ホーム / Docs / 技術マニュアル

Docling 完全技術ドキュメント

クイックサマリー (TL;DR)
  • DoclingはPDF、DOCX、PPTX、XLSX、スキャン画像、音声を構造化Markdown/HTML/JSONへ変換する100%無料のMITオープンソースエンジンです。
  • 視覚的レイアウト解析、読書順序復元、高度な表構造認識モデル TableFormer v2 を標準搭載。
  • RapidOCR、Tesseract(tesserocr)、EasyOCRによる多言語OCRに対応。
  • テレメトリなしの100%完全ローカル実行に対応し、閉域網環境(Air-Gapped)、REST API(docling-serve)、MCPサーバー(docling-mcp)をサポート。

1. 概要とアーキテクチャ

DoclingはIBM Researchが開発したオープンソースの文書解析エンジンです。単なるテキスト抽出ツールとは異なり、ページ幾何構造の解析、バウンディングボックスの特定、複雑な結合セル表の復元、正確な読書順序の構築を自動で行います。

2. インストールと環境構築

DoclingはPython 3.9〜3.14(64ビット)に対応し、Windows、macOS、Linux環境で利用可能です:

bash — 標準インストール
$pip install docling

2.1 Windows 10/11 C++ ビルドツールの設定

Windows環境では64ビット版Pythonが必須です。pipでtesserocr等のC++拡張をコンパイルする場合はMicrosoft Visual C++ 14.0+が必要です:

Visual C++ Build Tools のインストール
管理者権限のPowerShellで実行します:
PS>winget install Microsoft.VisualStudio.2022.BuildTools --override "--passive --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"

推奨代替手法(C++コンパイラ不要): Astral uv を使用して事前ビルド済みバイナリを取得します:

powershell — astral uv
PS>uv add docling

3. クイックスタート

python — 基本的な変換
from docling.document_converter import DocumentConverter

converter = DocumentConverter()
result = converter.convert("https://arxiv.org/pdf/2408.09869")
print(result.document.export_to_markdown()[:500])
              

4. DoclingDocument データ構造

DoclingDocumentはページ上の見出し、段落、表、コードブロック、図をオブジェクトツリー形式で保持し、result.document.export_to_json()で完全な座標情報とともに出力可能です。

5. パイプラインと Granite Docling VLM

5.1 Granite Docling VLM の設定

python — granite docling vlm
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import VlmPipelineOptions
from docling.document_converter import DocumentConverter, PdfFormatOption

vlm_options = VlmPipelineOptions()
vlm_options.vlm_model = "granite_docling"

converter = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=vlm_options)}
)
result = converter.convert("document.pdf")
              

6. OCRエンジンと高速化チューニング

6.1 デジタルPDFでのOCR無効化(10倍高速)

python — ocr無効化
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions
from docling.document_converter import DocumentConverter, PdfFormatOption

pipeline_options = PdfPipelineOptions()
pipeline_options.do_ocr = False  # デジタルPDFを10倍高速処理

converter = DocumentConverter(
    format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
)
result = converter.convert("report.pdf")
              

7. 多形式対応(Excel XLSX、PowerPoint PPTX、CAD、音声)

python — excel・powerpoint変換
from docling.document_converter import DocumentConverter

converter = DocumentConverter()
excel_res = converter.convert("finance.xlsx")
print(excel_res.document.export_to_markdown())
              

8. RAGチャンキング (`HybridChunker`)

python — hybridchunker
from docling.document_converter import DocumentConverter
from docling.chunking import HybridChunker

converter = DocumentConverter()
result = converter.convert("article.pdf")

chunker = HybridChunker(max_tokens=512, merge_peers=True)
for chunk in chunker.chunk(result.document):
    print(chunk.meta.headings, chunk.text[:80])
              

9. GPUバッチ高速化と調整

python — gpuバッチ処理
from docling.datamodel.accelerator_options import AcceleratorDevice, AcceleratorOptions
from docling.datamodel.pipeline_options import ThreadedPdfPipelineOptions

accel = AcceleratorOptions(device=AcceleratorDevice.CUDA)
pipe_opts = ThreadedPdfPipelineOptions(accelerator_options=accel, page_batch_size=8)
              

10. フレームワーク連携(LangChain & LlamaIndex)

python — langchain docling
from langchain_docling import DoclingLoader

loader = DoclingLoader(file_path="report.pdf")
docs = loader.load()
              

11. VLMビジョンモデルカタログ

モデル名 提供元 主な用途 CLI引数
granite_docling IBM Research 高精度なPDFビジュアルレイアウト解析 --vlm-model granite_docling
smoldocling Hugging Face / IBM CPU向けの軽量・高速VLM --vlm-model smoldocling

12. FastAPIサーバー (`docling-serve`) と MCPサーバー

bash — docker docling-serve
$docker run -p 5001:5001 ghcr.io/docling-project/docling-serve:latest

12.1 Claude Desktop向けMCPサーバー設定

json — claude_desktop_config.json
{
  "mcpServers": {
    "docling": {
      "command": "uvx",
      "args": ["--from=docling-mcp", "docling-mcp-server"]
    }
  }
}
              

13. エンタープライズセキュリティ&閉域網環境(Air-Gap)

bash — オフライン環境での運用
export DOCLING_CACHE_DIR="/opt/docling_models"
docling-tools models download --all

export HF_HUB_OFFLINE=1
export DOCLING_CACHE_DIR="/opt/docling_models"
docling document.pdf --to md
              

14. トラブルシューティング

エラー / 現象 原因 解決方法
cannot import name 'BoundingBox' Docling v2でのスキーマ移動。 from docling_core.types.doc import BoundingBox からインポート。
RapidOCR: text detection result empty 解像度不足。 pipeline_options.images_scale = 2.0 でDPIを引き上げ。
バージョン確認 動作確認。 ターミナルで docling --version を実行。

15. CLIパラメータ一覧

オプション デフォルト 説明
--to md, json, html, doctags md 出力形式を指定。
--no-ocr Boolean - デジタルPDFの変換を高速化するためOCRを無効化。
--version Flag - 現在のDoclingバージョンを表示。