databricks-unstructured-pdf-generation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUnstructured-Document for Demos and Eval Datasets on Databricks
在Databricks上用于演示和评估数据集的非结构化文档
Workflow for producing synthetic PDF documents + paired test questions as a Unity Catalog-resident dataset for Demos and RAG / unstructured-document retrieval evaluation on Databricks. The PDF-generation step uses standard local HTML → PDF tooling; the Databricks-specific value is the workflow shape — UC volume layout, paired question files, and integration with downstream Databricks retrieval / / evaluation.
ai_extractai_parse_document本工作流用于生成合成PDF文档+配对测试问题,作为存储在Unity Catalog中的数据集,供Databricks上的演示以及RAG/非结构化文档检索评估使用。PDF生成步骤使用标准的本地HTML转PDF工具;Databricks专属价值体现在工作流形态——UC卷布局、配对问题文件,以及与下游Databricks检索//评估的集成。
ai_extractai_parse_documentWorkflow
工作流
- Write HTML files to (write multiple files in parallel for speed) — domain-shaped to match the documents your retrieval pipeline will see in production.
./raw_data/html/ - Convert HTML → PDF using (parallel conversion, wraps
<SKILL_ROOT>/scripts/pdf_generator.py).plutoprint - Upload PDFs to a Unity Catalog volume via — same volume shape your production pipeline will read from.
databricks fs cp - Generate pairing each document with retrieval-eval questions; this becomes the gold dataset for
./raw_data/pdf/pdf_eval_questions.jsonor comparable retrieval-quality scorers.mlflow.genai.evaluate()
If you only need ad-hoc PDFs (no Databricks workflow), any HTML → PDF tool (,weasyprint,wkhtmltopdf,playwright pdf) works directly — this skill exists for the synthetic-dataset-on-UC end-to-end shape, not as a general PDF generator.plutoprint
Path convention:below = the directory containing this SKILL.md. Resolve to the absolute install path (e.g.<SKILL_ROOT>).~/.claude/skills/databricks-unstructured-pdf-generationpaths are relative to your own project cwd../raw_data/...
- 将HTML文件写入(并行写入多个文件以提高速度)——内容领域需与你的检索管道在生产环境中处理的文档匹配。
./raw_data/html/ - 使用将HTML转换为PDF(并行转换,封装
<SKILL_ROOT>/scripts/pdf_generator.py)。plutoprint - 通过将PDF上传至Unity Catalog卷——卷结构需与生产管道读取的结构一致。
databricks fs cp - 生成,将每个文档与检索评估问题配对;该文件将成为
./raw_data/pdf/pdf_eval_questions.json或类似检索质量评分工具的黄金数据集。mlflow.genai.evaluate()
如果你只需要临时PDF(无需Databricks工作流),任何HTML转PDF工具(、weasyprint、wkhtmltopdf、playwright pdf)都可直接使用——本技能的存在是为了实现UC上合成数据集的端到端形态,而非作为通用PDF生成器。plutoprint
路径约定: 下文的= 包含本SKILL.md的目录。需解析为绝对安装路径(例如<SKILL_ROOT>)。~/.claude/skills/databricks-unstructured-pdf-generation路径相对于你自己的项目工作目录。./raw_data/...
Dependencies
依赖项
bash
uv pip install plutoprintbash
uv pip install plutoprintStep 1: Write HTML Files
步骤1:编写HTML文件
bash
mkdir -p ./raw_data/htmlWrite HTML documents to . Use subdirectories to organize (structure is preserved).
./raw_data/html/filename.htmlbash
mkdir -p ./raw_data/html将HTML文档写入。可使用子目录进行组织(结构会被保留)。
./raw_data/html/filename.htmlStep 2: Convert to PDF
步骤2:转换为PDF
bash
undefinedbash
undefinedConvert entire folder (parallel, 4 workers)
转换整个文件夹(并行处理,4个工作进程)
python <SKILL_ROOT>/scripts/pdf_generator.py convert --input ./raw_data/html --output ./raw_data/pdf
Skips files where PDF exists and is newer than HTML. Use `--force` to reconvert all.python <SKILL_ROOT>/scripts/pdf_generator.py convert --input ./raw_data/html --output ./raw_data/pdf
会跳过已存在且比HTML更新的PDF文件。使用`--force`参数可重新转换所有文件。Step 3: Upload to Volume
步骤3:上传至卷
databricks fsdbfs:-rraw_data/pdfraw_data/pdf/dbfs:/Volumes/my_catalog/my_schema/raw_data/pdf/report.pdfbash
databricks fs cp -r --overwrite ./raw_data/pdf dbfs:/Volumes/my_catalog/my_schema/raw_data/pdfdatabricks fsdbfs:-rraw_data/pdfraw_data/pdf/dbfs:/Volumes/my_catalog/my_schema/raw_data/pdf/report.pdfbash
databricks fs cp -r --overwrite ./raw_data/pdf dbfs:/Volumes/my_catalog/my_schema/raw_data/pdfStep 4: Generate Test Questions
步骤4:生成测试问题
Create with questions for Knowledge Assistant (KA) or Multi-Agent Supervisor (MAS) evaluation. It's fine for this file to be uploaded to the volume alongside the PDFs — downstream agents can use it:
./raw_data/pdf/pdf_eval_questions.jsonjson
{
"api_errors_guide.pdf": {
"question": "What is the solution for error ERR-4521?",
"expected_fact": "Call /api/v2/auth/refresh with refresh_token before the 3600s TTL expires"
},
"installation_manual.pdf": {
"question": "What port does the service use by default?",
"expected_fact": "Port 8443 for HTTPS, configurable via CONFIG_PORT environment variable"
}
}This JSON can be used to build KA test cases and validate retrieval accuracy.
创建,包含用于知识助手(KA)或多代理管理器(MAS)评估的问题。该文件可与PDF一起上传至卷,供下游代理使用:
./raw_data/pdf/pdf_eval_questions.jsonjson
{
"api_errors_guide.pdf": {
"question": "ERR-4521错误的解决方案是什么?",
"expected_fact": "在3600s的TTL过期前,使用refresh_token调用/api/v2/auth/refresh"
},
"installation_manual.pdf": {
"question": "服务默认使用哪个端口?",
"expected_fact": "HTTPS默认使用8443端口,可通过CONFIG_PORT环境变量配置"
}
}该JSON可用于构建KA测试用例并验证检索准确性。
Document Content Guidelines
文档内容指南
When generating documents for Knowledge Assistant testing or demos:
- Multi-page documents: Each PDF should be several pages with substantial content
- Specific error codes and solutions: Include product-specific error codes, causes, and resolution steps
- Technical details: API endpoints, configuration parameters, version numbers, specific commands
- Simple CSS: Keep styling minimal for fast HTML creation and reliable PDF conversion
- Queryable facts: Include details a KA must read the document to answer (not general knowledge)
Good document types:
- Product user manuals with troubleshooting sections
- API error reference guides (error codes, causes, solutions)
- Installation/configuration guides with specific steps
- Technical specifications with version-specific details
Example content: Instead of generic "Connection failed" errors, write:
- "Error ERR-4521: OAuth token expired. Cause: Token TTL exceeded 3600s default. Solution: Call with your refresh_token before expiration. See Section 4.2 for token lifecycle management."
/api/v2/auth/refresh
为知识助手测试或演示生成文档时:
- 多页文档:每个PDF应包含多页且内容充实
- 特定错误代码及解决方案:包含产品专属错误代码、原因和解决步骤
- 技术细节:API端点、配置参数、版本号、特定命令
- 简洁CSS:保持样式简洁,以快速创建HTML并确保PDF转换可靠
- 可查询事实:包含知识助手必须阅读文档才能回答的细节(而非通用知识)
推荐文档类型:
- 包含故障排除章节的产品用户手册
- API错误参考指南(错误代码、原因、解决方案)
- 包含具体步骤的安装/配置指南
- 包含版本专属细节的技术规格说明
示例内容: 不要写通用的“连接失败”错误,应写:
- "错误ERR-4521:OAuth令牌过期。原因:令牌TTL超过默认的3600s。解决方案:在过期前使用refresh_token调用。详见4.2节的令牌生命周期管理。"
/api/v2/auth/refresh
CLI Reference
CLI参考
python <SKILL_ROOT>/scripts/pdf_generator.py convert [OPTIONS]
--input, -i Input HTML file or folder (required)
--output, -o Output folder for PDFs (required)
--force, -f Force reconvert (ignore timestamps)
--workers, -w Parallel workers (default: 4)python <SKILL_ROOT>/scripts/pdf_generator.py convert [OPTIONS]
--input, -i 输入HTML文件或文件夹(必填)
--output, -o PDF输出文件夹(必填)
--force, -f 强制重新转换(忽略时间戳)
--workers, -w 并行工作进程数(默认:4)Folder Structure
文件夹结构
Subfolder structure is preserved:
./raw_data/html/ ./raw_data/pdf/
├── report.html → ├── report.pdf
├── quarterly/ ├── quarterly/
│ └── q1.html → │ └── q1.pdf
└── legal/ └── legal/
└── terms.html → └── terms.pdf子文件夹结构会被保留:
./raw_data/html/ ./raw_data/pdf/
├── report.html → ├── report.pdf
├── quarterly/ ├── quarterly/
│ └── q1.html → │ └── q1.pdf
└── legal/ └── legal/
└── terms.html → └── terms.pdfBundled Script
捆绑脚本
This skill ships one helper script:
| File | Description |
|---|---|
| scripts/pdf_generator.py | HTML → PDF converter (wraps |
The script ships at . If it is absent, recreate it from the CLI Reference above (a subcommand taking ///, wrapping for HTML → PDF).
<SKILL_ROOT>/scripts/pdf_generator.pyconvert--input--output--force--workersplutoprint本技能附带一个辅助脚本:
| 文件 | 描述 |
|---|---|
| scripts/pdf_generator.py | HTML转PDF转换器(封装 |
该脚本位于。若缺失,可根据上文的CLI参考重新创建(一个包含///参数的子命令,封装实现HTML转PDF)。
<SKILL_ROOT>/scripts/pdf_generator.py--input--output--force--workersconvertplutoprintTroubleshooting
故障排除
| Issue | Solution |
|---|---|
| "plutoprint not installed" | |
| PDF looks wrong | Check HTML/CSS syntax |
| "Volume does not exist" | |
| 问题 | 解决方案 |
|---|---|
| "plutoprint not installed" | 执行 |
| PDF显示异常 | 检查HTML/CSS语法 |
| "Volume does not exist" | 执行 |