Why Docling Is Becoming the Standard for RAG-Ready PDF Parsing
This article explains why Docling, an open-source document parser from IBM Research, is gaining traction for RAG systems by preserving document structure—layout, tables, reading order—through AI models like DocLayNet and TableFormer, and provides code examples for PDF-to-Markdown conversion, OCR, and structure-aware chunking with HybridChunker.
Introduction: The Structure Problem in PDF Parsing
Feeding a PDF into a RAG system often yields fragmented chunks—broken tables, misplaced headings—because traditional tools like PyMuPDF or pdfplumber only extract text, discarding the logical structure. The root cause is that PDFs are essentially drawing instructions with coordinates, not semantic markup. Docling, originally from IBM Research and now a Linux Foundation AI & Data Graduated project (GitHub stars >70k, 68% external contributors), addresses this by using AI models to reconstruct a hierarchical, position-aware DoclingDocument that retains headings, paragraphs, tables, formulas, and code blocks in human reading order.
Architecture Overview
Docling's modular pipeline consists of three layers:
Parsing Backend : Format-specific parsers; for PDF it uses the custom docling-parse built on qpdf, avoiding PyMuPDF's license issues and pypdfium's quality limits.
AI Processing Pipeline : StandardPdfPipeline runs OCR, layout analysis, and table recognition in parallel. Layout analysis uses the DocLayNet model; table structure recognition uses TableFormer .
Unified Document Model : All formats (PDF, DOCX, PPTX, XLSX, HTML, Markdown, images, audio) converge into a single DoclingDocument with hierarchy, coordinates, and table structure, exportable to JSON, Markdown, or HTML.
Core Principles
3.1 Layout Analysis: Identifying Elements and Their Positions
Instead of immediately extracting text, Docling renders each page to an image and runs the DocLayNet model to classify every element—title, paragraph, table, figure, formula, code block—and record its bounding box.
This element-centric approach ensures downstream steps (table recognition, heading hierarchy) operate on semantic units, not a raw text stream.
3.2 Reading Order Restoration: Correct Multi-Column Flow
Layout analysis tells what is where; reading-order inference tells when to read it. In two-column papers, a naive left-to-right, top-to-bottom sort merges the bottom of the left column with the top of the right column, breaking context. Docling's model infers human reading order (left column top-to-bottom, then right column top-to-bottom).
The left side shows coordinate-based sorting (paragraph 1 followed by paragraph 3); the right side shows Docling's restored order, preserving logical flow.
3.3 Table Structure Recognition: TableFormer Rebuilds Rows, Columns, and Merged Cells
Traditional tools either flatten tables into disjoint text blocks or use simple row/column splits that fail on merged cells. TableFormer predicts the full row/column grid, including multi-level headers and nested lists, outputting a structured table object—not plain text.
This enables RAG retrieval to understand which metric a number belongs to. Reported TEDS scores range from 0.877 to 0.911.
Hands-On: From PDF to RAG-Ready Chunks
4.1 Installation
pip install doclingRequires Python 3.10+; runs on macOS, Linux, Windows.
4.2 Basic Conversion: PDF to Markdown
from docling.document_converter import DocumentConverter
source = "your_document.pdf"
converter = DocumentConverter()
result = converter.convert(source)
print(result.document.export_to_markdown())4.3 Handling Scanned Documents: Enable OCR
from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.pipeline_options import PdfPipelineOptions
from docling.datamodel.base_models import InputFormat
pipeline_options = PdfPipelineOptions()
pipeline_options.do_ocr = True
pipeline_options.do_table_structure = True
converter = DocumentConverter(
format_options={
InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)
}
)
doc = converter.convert("scanned_invoice.pdf").document
print(doc.export_to_markdown())4.4 RAG Chunking: HybridChunker Preserves Structure
Character-based chunking breaks sentences and splits tables. HybridChunker chunks by document structure—headings stay with their paragraphs, tables remain intact—and uses tokenizer-aware sizing to fit embedding model limits.
from docling.document_converter import DocumentConverter
from docling.chunking import HybridChunker
converter = DocumentConverter()
doc = converter.convert("employee_handbook.pdf").document
chunker = HybridChunker()
chunks = list(chunker.chunk(dl_doc=doc))
for chunk in chunks[:3]:
# contextualize() prepends section hierarchy metadata
print(chunker.contextualize(chunk))
print("---"contextualize()injects the heading path (e.g., "Employee Handbook > HR Policies > Resignation") into each chunk, giving the embedding model contextualized text that improves retrieval accuracy.
Pros and Cons
Pros
Structured, RAG-friendly output : DoclingDocument with hierarchy, table structure, and positions; combined with HybridChunker yields higher-quality chunks than character splitting.
Strong table recognition : TableFormer restores rows, columns, merged cells, multi-level headers (TEDS 0.877–0.911).
Fully local execution : Models download and run locally; suitable for air-gapped or data-sensitive environments.
Multi-format unification : PDF, DOCX, PPTX, XLSX, HTML, Markdown, images, audio all map to the same DoclingDocument model.
Mature ecosystem integration : Native LangChain, LlamaIndex support; MCP Server; docling-java wrapper for JVM.
Reliable open governance : LF AI & Data Graduated project; contributors from 109 organizations; high community activity.
Cons
Not the fastest : Complex PDFs take ~9–10 seconds on CPU; Marker or PyMuPDF4LLM are quicker on simple PDFs.
Complex tables still have limits : Deeply nested tables; commercial solutions like Reducto claim ~20% higher accuracy.
Python-centric; Java requires indirection : JVM projects must call via docling-serve REST API or docling-java, adding network overhead.
Advanced features disabled by default : LaTeX formula conversion, code-block detection, image description need explicit enabling.
Recommended Use Cases
RAG knowledge-base preprocessing – Highly recommended: structured output + HybridChunker yields superior chunk quality.
Table-structure preservation required – Highly recommended: TableFormer restores rows, columns, merged cells.
Data-sensitive / offline environments – Highly recommended: fully local, no cloud dependency.
Technical documents / academic papers – Highly recommended: strong layout analysis and reading-order restoration.
Extreme parsing speed priority – Evaluate: slower than Marker on CPU.
Highly complex nested tables – Evaluate: commercial tools still hold an edge.
Pure Java stack – Evaluate: requires REST API layer.
Conclusion
Docling shifts PDF parsing from "text extraction" to "structure restoration." A document's value lies in the relationships between its elements—heading hierarchy, table semantics, reading order—which traditional tools discard. That structure directly determines the ceiling of a RAG system: a shattered table yields unrecoverable noise; a preserved table lets the LLM answer precisely. While not the fastest and not perfect on the most pathological tables, Docling is currently among the best open-source choices for turning PDFs into structured, RAG-ready data with a mature integration ecosystem.
Reference: GitHub: https://github.com/docling-project/docling
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
