Docling Graph Examples¶
Example scripts and Pydantic templates for docling-graph. Run scripts from the project root with uv run python docs/examples/scripts/....
Project Structure¶
| Path | Description |
|---|---|
docs/examples/scripts/ |
Python example scripts (01–16) |
docs/examples/templates/ |
Pydantic templates (e.g. billing_document.py, insurance_terms.py, rheology_research.py) |
Example Scripts (01–16)¶
Getting Started¶
01_quickstart_vlm_image.py— VLM extraction from an invoice image02_quickstart_llm_pdf.py— LLM extraction from a multi-page PDF (e.g. rheology)03_url_processing.py— Process documents from URLs (e.g. arXiv)
Core Features¶
04_input_formats.py— Text, Markdown, and DoclingDocument inputs05_processing_modes.py— One-to-one vs many-to-one modes06_export_formats.py— CSV, Cypher, and JSON exports07_local_inference.py— Local inference with Ollama
Optimization & Providers¶
08_chunking_consolidation.py— Chunking and merge behavior09_batch_processing.py— Batch processing with error handling10_provider_configs.py— OpenAI, Mistral, Gemini, watsonx, Amazon Bedrock12_custom_llm_client.py— Custom LLM client (bring your own URL) with full pipeline14_streaming_responses.py— Streaming LLM responses for real-time processing and progress feedback
Data Grounding¶
15_provenance_grounding.py— Trace extracted nodes back to source chunks and pages via__provenance__andprovenance.json
Evaluation¶
16_extraction_evaluation.py— Score an extractedgraph.jsonagainst a template-shaped ground-truth JSON (node/edge P/R/F1, attribute completeness, integrity). Domain-agnostic — works with any(template, ground_truth.json, graph.json)triple.17_benchmark_aggregate.py— Aggregate a benchmark matrix tree (documents × contracts × LLM formats × repeats) of Example 16 outputs into_aggregate.json+ a synthesis report with micro node/edge F1, dense retention, and chunk coverage. Driven byrun_benchmark.sh.
For CLI usage, see CLI Reference and convert command.
Quick Start¶
# From project root: VLM from image
uv run python docs/examples/scripts/01_quickstart_vlm_image.py
# Or use the CLI
uv run docling-graph convert "https://upload.wikimedia.org/wikipedia/commons/9/9f/Swiss_QR-Bill_example.jpg" \
--template "docs.examples.templates.billing_document.BillingDocument" \
--backend "vlm"
# Score a completed run against a ground-truth JSON
uv run python docs/examples/scripts/16_extraction_evaluation.py \
--graph outputs/RUN_DIR/docling_graph/graph.json \
--truth ground_truth.json \
--template "docs.examples.templates.insurance_terms.AssuranceMRH"
Learning Path¶
- Run 01 for a minimal VLM run, then 02 for LLM extraction.
- Use 03–07 for input formats, processing modes, exports, and local inference.
- Use 08–10 for chunking, batch runs, and multiple providers.