Databricks上でRAG(検索強化生成)や非構造化ドキュメント評価用データセット、デモドキュメント(例:Knowledge Assistant向け)を構築します。 具体的には以下の処理を実行します: - 合成PDFをローカルで生成する - Unity Catalogボリューム(データ保存領域)にアップロードする - 各ドキュメントに対して取得精度を評価するためのテスト質問を組み合わせる
Build RAG / unstructured-document evaluation datasets and demo documents (e.g. for Knowledge Assistant) on Databricks: generate synthetic PDFs locally, upload to Unity Catalog volumes, and pair each document with test questions for retrieval evaluation.
Databricks上でのデモやRAG(検索機能付き生成AI)、非構造化ドキュメント取得の評価に向けた、合成PDF文書と対応するテスト質問をUnity Catalogに保存するデータセットとして生成するワークフローです。PDF生成には標準的なローカルツール(HTMLからPDFへの変換)を使用しており、Databricks固有の価値はワークフローの構成にあります。すなわち、UCボリューム(ファイル保存領域)のレイアウト、対応する質問ファイル、そして下流のDatabricks検索・ai_extract・ai_parse_document評価ツールとの統合です。
HTMLファイルを ./raw_data/html/ に作成します(複数ファイルを並列処理で高速化)。本番環境の検索パイプラインが遭遇するドキュメントに合わせた内容にします。
<SKILL_ROOT>/scripts/pdf_generator.py を使用してHTMLからPDFに変換します(並列変換対応、plutoprintをラップしたツール)。
databricks fs cp コマンドでPDFをUnity Catalogボリュームにアップロードします。本番パイプラインが読み込むのと同じボリューム構成を使用します。
./raw_data/pdf/pdf_eval_questions.json を生成します。各ドキュメントに対応する検索評価用質問を含め、mlflow.genai.evaluate() などの検索品質スコアリングツール用の正解データセットとなります。
Databaksワークフローが不要で単発のPDFだけが必要な場合は、どのHTMLからPDF変換ツール(
weasyprint、wkhtmltopdf、playwright pdf、plutoprintなど)でも直接使用できます。このスキルは合成データセットをUC上で一連の流れで生成することを目的としており、汎用PDF生成ツールではありません。
パス規約: 以下の
<SKILL_ROOT>は、このSKILL.mdを含むディレクトリを示します。絶対パスに解決してください(例:~/.claude/skills/databricks-unstructured-pdf-generation)。./raw_data/...パスはプロジェクトの作業ディレクトリからの相対パスです。
uv pip install plutoprint
mkdir -p ./raw_data/html
HTMLドキュメントを ./raw_data/html/ファイル名.html に保存します。サブディレクトリを使って整理することもできます(フォルダ構成は保持されます)。
# フォルダ全体を変換(並列処理:4ワーカー)
python <SKILL_ROOT>/scripts/pdf_generator.py convert --input ./raw_data/html --output ./raw_data/pdf
PDFが既に存在し、かつHTMLより新しい場合はスキップします。すべてのファイルを再変換するには --force を指定します。
databricks fs コマンドはUCボリュームパスであっても dbfs: スキームプレフィックスが必要です。-r オプションはソースディレクトリの内容をコピーします(ソースディレクトリ名は保持されません)。そのため、ボリューム上でPDFを専用フォルダに保つために、明示的にターゲットを raw_data/pdf と指定します。PDFは raw_data/pdf/ 配下に配置されます。つまり dbfs:/Volumes/my_catalog/my_schema/raw_data/pdf/report.pdf のようになるので、ナレッジアシスタント(知識検索AI)または取り込みパイプラインがこの単一フォルダを指すことができます。
databricks fs cp -r --overwrite ./raw_data/pdf dbfs:/Volumes/my_catalog/my_schema/raw_data/pdf
./raw_data/pdf/pdf_eval_questions.json を作成します。ナレッジアシスタント(知識検索AI)またはマルチエージェント監督役(複数のAIを統括するシステム)の評価用質問を含めます。このファイルはPDFと一緒にボリュームにアップロードして問題ありません。下流のエージェントが利用できます:
{
"api_errors_guide.pdf": {
"question": "エラーERR-4521の解決方法は何ですか?",
"expected_fact": "リフレッシュトークンの有効期限切れ前に /api/v2/auth/refresh を refresh_token で呼び出します(デフォルトTTL:3600秒)"
},
"installation_manual.pdf": {
"question": "サービスはデフォルトでどのポートを使用していますか?",
"expected_fact": "HTTPS用ポート8443。CONFIG_PORT環境変数で変更可能"
}
}
このJSONはナレッジアシスタントのテストケース構築と検索精度の検証に使用できます。
ナレッジアシスタントのテストやデモ用のドキュメントを生成する場合:
良いドキュメント例:
コンテンツの例: 一般的な「接続失敗」エラーではなく、以下のように具体的に記述します:
/api/v2/auth/refresh をrefresh_tokenで呼び出してください。トークンライフサイクル管理の詳細はセクション4.2を参照してください。」python <SKILL_ROOT>/scripts/pdf_generator.py convert [オプション]
--input, -i 入力HTMLファイルまたはフォルダ(必須)
--output, -o PDF出力フォルダ(必須)
--force, -f 再変換を強制(タイムスタンプを無視)
--workers, -w 並列処理ワーカー数(デフォルト:4)
サブフォルダ構成は保持されます:
./raw_data/html/ ./raw_data/pdf/
├── report.html → ├── report.pdf
├── quarterly/ ├── quarterly/
│ └── q1.html → │ └── q1.pdf
└── legal/ └── legal/
└── terms.html → └── terms.pdf
このスキルには1つのヘルパースクリプトが含まれます:
| ファイル | 説明 |
|---|---|
| scripts/pdf_generator.py | HTMLからPDFへの変換ツール(plutoprintをラップ)。タイムスタンプによるスキップ機能付きの並列フォルダ変換に対応。ステップ2とCLIリファレンスで参照されます。 |
スクリプトは <SKILL_ROOT>/scripts/pdf_generator.py に配置されます。見つからない場合は、CLIリファレンスから再作成してください(--input/--output/--force/--workers を取る convert サブコマンドで、HTMLからPDFへの変換に plutoprint をラップしたツール)。
| 問題 | 対処方法 |
|---|---|
| 「plutoprint not installed」エラー | uv pip install plutoprint を実行 |
| PDFの表示がおかしい | HTMLやCSS構文を確認 |
| 「ボリュームが存在しない」エラー | databricks volumes create カタログ スキーマ ボリューム名 MANAGED(4つの独立した引数。catalog.schema.volume の形式ではなく) |
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 / ai_extract / ai_parse_document evaluation.
./raw_data/html/ (write multiple files in parallel for speed) — domain-shaped to match the documents your retrieval pipeline will see in production.<SKILL_ROOT>/scripts/pdf_generator.py (parallel conversion, wraps plutoprint).databricks fs cp — same volume shape your production pipeline will read from../raw_data/pdf/pdf_eval_questions.json pairing each document with retrieval-eval questions; this becomes the gold dataset for mlflow.genai.evaluate() or comparable retrieval-quality scorers.If you only need ad-hoc PDFs (no Databricks workflow), any HTML → PDF tool (
weasyprint,wkhtmltopdf,playwright pdf,plutoprint) works directly — this skill exists for the synthetic-dataset-on-UC end-to-end shape, not as a general PDF generator.
Path convention:
<SKILL_ROOT>below = the directory containing this SKILL.md. Resolve to the absolute install path (e.g.~/.claude/skills/databricks-unstructured-pdf-generation)../raw_data/...paths are relative to your own project cwd.
uv pip install plutoprint
mkdir -p ./raw_data/html
Write HTML documents to ./raw_data/html/filename.html. Use subdirectories to organize (structure is preserved).
# Convert entire folder (parallel, 4 workers)
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.
databricks fs requires the dbfs: scheme prefix even for UC Volume paths. -r copies the contents of the source directory into the target (the source directory name is not preserved), so name the target raw_data/pdf explicitly to keep the PDFs in their own folder on the volume. They land under raw_data/pdf/ — i.e. dbfs:/Volumes/my_catalog/my_schema/raw_data/pdf/report.pdf — so a Knowledge Assistant or ingest pipeline can point at that single folder.
databricks fs cp -r --overwrite ./raw_data/pdf dbfs:/Volumes/my_catalog/my_schema/raw_data/pdf
Create ./raw_data/pdf/pdf_eval_questions.json 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:
{
"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.
When generating documents for Knowledge Assistant testing or demos:
Good document types:
Example content: Instead of generic "Connection failed" errors, write:
/api/v2/auth/refresh with your refresh_token before expiration. See Section 4.2 for token lifecycle management."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)
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
This skill ships one helper script:
| File | Description |
|---|---|
| scripts/pdf_generator.py | HTML → PDF converter (wraps plutoprint); parallel folder conversion with timestamp-skip. Referenced by Step 2 and the CLI Reference. |
The script ships at <SKILL_ROOT>/scripts/pdf_generator.py. If it is absent, recreate it from the CLI Reference above (a convert subcommand taking --input/--output/--force/--workers, wrapping plutoprint for HTML → PDF).
| Issue | Solution |
|---|---|
| "plutoprint not installed" | uv pip install plutoprint |
| PDF looks wrong | Check HTML/CSS syntax |
| "Volume does not exist" | databricks volumes create CATALOG SCHEMA VOLUME_NAME MANAGED (four separate positional args, not catalog.schema.volume) |
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。