What this thread does
As of November 2026, preserve the heading tree before chunking: extract text and layout separately, then connect child chunks to their sections. This follows the author’s hybrid-parsing update.
Do first: inspect a few difficult pages for heading numbers, bullets and cross-page sentences before indexing, using the reported failure cases.
The problem
A corpus of long, highly structured PDFs (compliance sections of hundreds of pages, with chapters, numbered lists, appendices) goes through your usual parser, and a single missing bullet or wrong section index wrecks chunking and later retrieval.
What the source says
An r/Rag post by u/fustercluck6000 : the author's Docling pipeline, which had handled structured formats and small PDFs, "failed miserably" on these, and page-by-page Qwen3-VL markdown (4B and 8B) lost section numbering because a page has no memory of the previous one (numbering starting at 3 got reset to 1) and sentences broken across pages joined badly. Everything had to run locally on an air-gapped server.
What commenters said (opinions):
- It is a hard problem and a PDF is a canvas, not a structure . Template-based extraction can work if all documents share a layout; commercial parsers were mentioned (Azure Document Intelligence, Reducto, LlamaParse) with the caveat that cloud options were excluded here.
- Hybrid parsing: take the text layer with PyMuPDF for accurate content, use a vision model only for the skeleton (headers, lists, table boundaries), then map text into the skeleton. A Word-exported PDF may store a bullet and its text as separate blocks, which parsers read as unrelated.
- Hierarchical RAG: detect layout, parse headings into a document hierarchy, and accept it will be imperfect.
- Preserve hierarchy so a retrieved chunk can be expanded with its chapter and with neighbours at the same level only; validate parsed output before chunking.
- If the originals were Word files, reopening the PDFs in Word and saving as a better format was suggested as a simple option; another commenter suggested roughly 500-token chunks with generous overlap, without specifying a 500-token overlap (discussion).
The author's update says the approach combined PyMuPDF raw text, spaCy layout and Qwen3-VL for layout detection (the spacy-layout README says that plugin integrates with Docling, so spaCy layout does not establish a Docling-free replacement), with extensive Pydantic validation of predicted bounding boxes, giving consistent but not perfect results. This is the author's report about one corpus.
How to describe it to your agent
Suggested design: Ingest these PDFs in two lanes. Lane A: extract text per page with PyMuPDF. Lane B: detect layout regions (headings, lists, tables) and build a heading tree; validate each region's bounding box and heading-number sequence with Pydantic and flag pages that break the sequence. Merge lane A text into the tree. Store parent-child chunks and return the section path with each hit so answers can cite where they came from. Cache parsed output on disk so a person can inspect it.
Mistakes to check
- Treating each page independently, so numbering and indentation resets.
- Not inspecting parsed output before indexing: failures show up three steps later.
- Chunking by token count across chapter boundaries.
Limits
One practitioner's report and community advice; parser quality remains document-dependent. For tool comparisons (Marker, Docling, MarkItDown) see the existing thread on turning PDFs into Markdown locally.
Sources
- Author’s post, update and replies: the air-gapped constraint, page-numbering failures and PyMuPDF/spaCy/Qwen3-VL/Pydantic combination are practitioner reports.
- spaCy Layout integrates with Docling and exposes layout-labelled spans and tables.
- PyMuPDF text recipes describe block and word extraction with position information.
- Official model cards exist for both Qwen3-VL-4B-Instruct and Qwen3-VL-8B-Instruct; their availability does not establish parsing accuracy on this corpus.
Started from a post by @fustercluck6000, packaged by the editor. Original post