跪拜 Guibai
← All articles
Backend

Docling Puts the Structure Back into PDFs Before RAG Ever Retrieves

By 苏三说技术 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

When RAG output degrades, the fix usually sits upstream in parsing, not in the embedding model or vector store. Docling keeps structure through extraction locally and open-source, so table-heavy and multi-column documents retrieve far better without swapping models.

Summary

Docling attacks the failure before retrieval: when a PDF becomes text, the document structure dies, and RAG retrieves fragments of tables, detached headings, and scrambled multi-column pages. Docling renders each page to an image and runs DocLayNet layout analysis to identify headings, paragraphs, tables, formulas, and code blocks with coordinates. A reading order model re-sorts multi-column pages the way a human reads them, and TableFormer rebuilds table rows, columns, and merged cells with TEDS scores between 0.877 and 0.911.

Output lands in a single DoclingDocument object that exports losslessly to JSON, Markdown, or HTML. HybridChunker splits that document along structural boundaries and contextualize() prepends the section hierarchy to each chunk, so an embedding model sees "Employee Handbook > HR Policy > Resignation Management" attached to the sentence about giving 30 days' notice.

Docling runs fully on local machines with models downloaded once, covers PDF, DOCX, PPTX, XLSX, HTML, Markdown, images, and audio, and integrates with LangChain, LlamaIndex, and an MCP server. The trade-offs: a complex PDF takes 9 to 10 seconds on CPU, deeply nested tables still lose accuracy to commercial tools, Java teams must call through a REST API, and formula, code block, and image-description features ship off by default.

Takeaways
— Docling started at IBM Research, entered the Linux Foundation in March 2025, and became an LF AI & Data Graduated project in August 2026.
— The project has over 70,000 GitHub stars, with more than 68% of community PRs coming from outside the core team.
— Traditional extractors like PyMuPDF and pdfplumber pull text out but drop structure; PDFs carry coordinates, not semantics.
— Pipeline order: each page renders as an image, DocLayNet classifies elements and positions, then a reading order model reconstructs human reading sequence.
— TableFormer predicts rows, columns, merged cells, and multi-level headers, scoring 0.877 to 0.911 on TEDS.
— HybridChunker cuts along document structure, not characters, so headings stay with their paragraphs and tables stay intact.
— contextualize() prepends the section hierarchy to each chunk, giving embedding models context like "Employee Handbook > HR Policy > Resignation Management."
— Everything runs locally; PDF, DOCX, PPTX, XLSX, HTML, Markdown, images, and audio all converge on one DoclingDocument model.
— Native integrations cover LangChain, LlamaIndex, and an MCP server; Java teams route through the docling-serve REST API or docling-java.
— A complex PDF takes 9 to 10 seconds on CPU, slower than Marker or PyMuPDF4LLM on simple documents.
— Merged-cell and deeply nested tables remain a weak point; Reducto claims about 20% higher accuracy there.
— Formula-to-LaTeX conversion, code block recognition, and image description are disabled by default and must be turned on.
— Install via pip install docling; requires Python 3.10+, works on macOS, Linux, and Windows.
Conclusions

Debugging usually targets retrieval first: swapping embedding models, chunk sizes, and vector search strategies left RAG broken, because structure was lost at extraction. Parsing costs less to fix and sits further upstream.

Graduated status at LF AI & Data and 68% of PRs from outside the core team carry as much weight as the star count; governance at that level survives whatever happens to the original sponsor.

Structure preservation is conditional in practice. Formula-to-LaTeX conversion, code block recognition, and image description ship disabled, so reaching the advertised capability takes explicit configuration.

Nine to ten seconds per complex PDF on CPU and a REST-API detour for Java stacks set real operational limits on teams that choose Docling for structure preservation.

Concepts & terms
DocLayNet
Layout analysis model that classifies PDF page elements into headings, paragraphs, tables, images, formulas, and code blocks, each with its coordinate position.
TableFormer
A table structure recognition model that predicts row-column relationships, merged cells, and multi-level headers, rebuilding a table as structured data rather than scattered numbers.
HybridChunker
Docling's chunking strategy that splits documents along structural boundaries and uses tokenizer-aware sizing; its contextualize() method attaches the section hierarchy to each chunk.
TEDS
Table Edit-Distance Similarity, a metric that scores how closely a reconstructed table matches ground truth; Docling's TableFormer lands between 0.877 and 0.911.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗