TECHNOLOGY

PDF to Markdown for RAG: fix reading order before indexing

In this article
THE QUICK TAKE

Chunking cannot reliably repair a PDF conversion that has already mixed adjacent columns or detached captions from their objects.

PDF-to-Markdown conversion should preserve reading order before a RAG index is built, because perfectly recognized words can still form the wrong document. Multicolumn pages, floating captions and repeated headers need structural inspection rather than assuming that a text-filled output is ready for retrieval.

Identify layout before flattening

The Docling technical report describes layout-aware conversion. A PDF page encodes positioned objects; their storage order need not match human reading order. Flattening those objects too early can interleave adjacent columns or separate a caption from its figure. Inspect a representative layout sample before choosing conversion rules, especially when the collection combines brochures, manuals and scanned forms.

Retain structural objects during conversion

The DoclingDocument model represents document hierarchy and provenance. Keep that structured artifact alongside Markdown. Paragraphs, headings, tables and page furniture play different roles. Repeated headers should not become the opening sentence of every retrieved fragment, while a table caption may be essential context. Removing all repeated text indiscriminately can also erase meaningful repeated section labels or warnings.

Test a two-column page explicitly

Choose a page whose left column describes installation and whose right column describes disposal. Add a caption between a diagram and a warning. Compare the converted sequence against the page image. A malformed sequence can create an apparently coherent but false instruction by placing the disposal sentence inside the installation procedure. Retrieval then faithfully returns an artifact the source never contained.

Layout elementConversion check
Adjacent columnsRead each intended flow separately
Floating captionPreserve its related figure context
Repeated page headerClassify furniture before indexing
Warning boxKeep scope and nearby procedure explicit

Check Markdown boundaries before chunking

The primary Docling implementation provides conversion and export interfaces. Verify that headings introduce the correct sections and list items remain within their procedure. Chunking cannot reliably repair reading order that was already lost. A heading from the neighboring column can attach a technically correct paragraph to the wrong operation, changing both retrieval relevance and the apparent authority of its citation.

Keep a conversion acceptance artifact

Save source page images, structured output, Markdown and an annotated list of ordering defects for the sample. Accept the converter based on recovered document relationships, not merely the amount of extracted text. Then inspect retrieval examples whose evidence spans headings, captions or columns. This focuses subsequent fixes on layout analysis, serialization or chunk construction as appropriate, without assuming that another embedding model will correct a corrupted sequence of source statements.

Related reading: A GPU OCR pipeline for a 1,000-page PDF workload; A local RAG server: placing components around the GPU.

← All articles