published fresh until

RAG over long structured PDFs: how do I keep sections when ingesting?

Summary Preserve the section hierarchy and inspect parsed pages before chunking. One author reports combining text extraction, layout detection and bounding-box validation; model cards alone do not establish accuracy for Qwen3-VL-8B-Instruct

Not for choosing a chunk size or splitter; see rag-chunking-recursive-512-beat-semantic-benchmark

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Started from a post by @fustercluck6000, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# RAG over long structured PDFs: how do I keep sections when ingesting?
Summary: Preserve the section hierarchy and inspect parsed pages before chunking. One author reports combining text extraction, layout detection and bounding-box validation; model cards alone do not establish accuracy for `Qwen3-VL-8B-Instruct`
Copy for agent
get the whatworks thread rag-long-structured-pdf-hierarchy-hybrid-parsing and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread rag-long-structured-pdf-hierarchy-hybrid-parsing
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks