Document-based chunking splits a document along its own structure — headings, sections, tables and lists — instead of cutting at fixed character or token counts. Is it worth the extra effort? Yes, when your documents have real structure and your questions need whole sections rather than fragments: chunks that match the document’s own divisions retrieve more accurately and give the model cleaner context, but the approach depends entirely on reliable parsing.
Most chunking strategies treat a document as a stream of characters and decide where to cut by counting. Document-based chunking treats it as a structured object and lets the author’s own organisation decide. A chapter becomes a chunk, a section becomes a chunk, a table stays whole. The result is a set of pieces that mean something on their own, because each one corresponds to a unit the author intended.
Key takeaways
- Document-based chunking splits on structural elements — headings, sections, tables, lists — rather than on character or token counts.
- Chunks match the document’s own divisions, so each one is a coherent unit that can answer questions on its own.
- It depends on reliable parsing: if headings or tables are not detected correctly, the chunks will be wrong.
- Long sections usually need a second splitting pass, so document-based chunking often pairs with recursive splitting.
- It works best on manuals, reports, contracts and papers — documents where structure carries meaning.
What is document-based chunking?
Document-based chunking, sometimes called structure-aware chunking, uses the layout of a document to decide where chunks begin and end. A Markdown file is split at its headings, a Word document at its heading styles, a PDF at its detected sections, and a spreadsheet at its tables. Each chunk carries the heading or section title it came from, often stored as metadata, so the retriever and the model both know where the text sits in the document.
The key difference from other strategies is what the chunk represents. A fixed-size chunk represents 500 tokens of text. A document-based chunk represents a section called “Refund Policy” or a table called “Pricing Tiers”.
Structure also survives into the prompt. A chunk that arrives with its section heading gives the model context about what it is reading, which helps it weigh the evidence correctly. A fragment without a heading forces the model to guess, and guessing is where retrieval systems start to produce confident-sounding wrong answers.
How document-based chunking works
The pipeline has three stages. First, the document is parsed into a structured form: headings and their levels, paragraphs grouped under headings, tables with their rows and headers, and lists with their items. The quality of this stage decides everything downstream, which is why parsing deserves as much attention as splitting.
Second, the structured document is divided into chunks along its boundaries. A section becomes a chunk; a table becomes a chunk, often serialised as text with its headers repeated so the rows stay interpretable; a list becomes a chunk, or is split into items if it is long. Each chunk is tagged with metadata such as the document title, the section path and the page number, which supports filtering and citation later.
Third, sections that are too long for a single chunk are split further, usually with a recursive splitter that respects paragraph and sentence boundaries inside the section. This two-stage approach — structure first, size second — keeps chunks coherent at both levels: the outer boundary follows the document, and the inner boundary follows the prose.
Document-based chunking in practice
For Markdown documents, LangChain provides a Markdown-aware splitter that divides text at headings and code blocks before falling back to recursive splitting within each section. The pattern is simple to set up:
from langchain_text_splitters import MarkdownHeaderTextSplitter
headers = [("#", "chapter"), ("##", "section"), ("###", "subsection")]
splitter = MarkdownHeaderTextSplitter(headers_to_split_on=headers)
chunks = splitter.split_text(markdown_text)
Each chunk produced this way carries its heading path in metadata, so a chunk from “Chapter 3, Section 2” is labelled as such. That metadata is useful twice: at retrieval time, when it can be used to filter or boost results, and at generation time, when it tells the model exactly where the evidence came from.
PDFs and Word documents need more work, because their structure is presentational rather than explicit. A PDF stores positioned text rather than headings, so detecting a heading means inferring it from font size, weight and spacing. Tools that extract document structure from PDFs have improved considerably, but the results still need checking on your own files. Our guide to document parsing explains what to look for when choosing a parser, and why extraction quality sets a ceiling on everything downstream.
Tables deserve special handling. A table split across chunks loses its headers in one half and its rows in the other, and neither half is useful alone. The usual fix is to keep each table whole in a single chunk, repeating the header row alongside the data so the chunk reads correctly on its own. If a table is too large for one chunk, split it by rows and repeat the headers in every piece. The same principle applies to lists: keep items with their introductory sentence, so the model knows what the list is about.

Strengths of document-based chunking
The main strength is coherence. Every chunk corresponds to a unit the author created, so embeddings represent complete ideas and retrieval matches complete ideas. Answers built from such chunks are more accurate, because the model receives whole sections rather than fragments that start mid-thought.
It also preserves information that counting-based methods destroy. Tables keep their headers, lists keep their introductions, and sections keep their headings. That preserved context is often the difference between a correct answer and a plausible-sounding wrong one.
Finally, the metadata is genuinely useful. Section paths support filtering — a user asking about pricing can be restricted to pricing sections — and they make citations readable, because an answer can point to “Section 4.2, Refunds” rather than “chunk 37”. For systems where users need to verify answers, that traceability is a real feature, not a nice extra.
Weaknesses of document-based chunking
The biggest weakness is dependence on parsing. If the parser misses a heading, merges two sections or misreads a table, the chunks inherit the error, and no splitter setting can fix it. Documents that look clean to a human can be surprisingly messy underneath, especially PDFs exported from varied sources. Every new document type is a new parsing risk.
Chunk sizes also vary widely. A short section may produce a chunk of fifty tokens, while a long chapter produces one of several thousand. Uneven sizes complicate prompt budgeting and can dilute embeddings in the largest chunks, which is why the second-stage recursive split matters.
It is also more engineering work than counting-based splitting. You need a parser for each format, a mapping from structure to chunks, and handling for edge cases such as tables, figures, footnotes and appendices. For a small corpus of uniform documents, that work may not pay for itself.
Document-based chunking compared with other strategies
| Strategy | How it splits | Main strength | Main weakness | Best for |
|---|---|---|---|---|
| Document-based chunking | Headings, sections, tables, lists | Chunks are coherent units | Needs reliable parsing | Manuals, reports, contracts |
| Fixed-size chunking | Equal character or token counts | Simple and predictable | Cuts mid-sentence | Uniform plain text |
| Recursive chunking | Separator hierarchy | Respects natural boundaries | Ignores document structure | General-purpose documents |
| Semantic chunking | Topic shifts detected by embeddings | Chunks match real topics | Slow and costly | Long, varied prose |
Best for: structured documents — manuals, reports, contracts, research papers and policy documents — where headings, tables and lists carry meaning that counting-based splitting would destroy.
When document-based chunking is the right choice
Choose it when your documents have strong, reliable structure and your questions target whole sections. A user asking “what is the refund policy?” wants the refund section, not a 500-token window that contains half of it and half of the next section. A user asking about a pricing table wants the table whole, headers included.
It also fits when answers must be verifiable. Systems that show citations benefit from chunks with clear section paths, because users can check the source section directly.
Skip it when documents are flat prose with no headings, when parsing quality is poor and cannot be improved, or when the corpus is small enough that a recursive splitter already retrieves well. In those cases, the engineering cost buys little. As with every chunking decision, the test is your own evaluation: compare chunking strategies on your questions and keep whichever retrieves best.
Common mistakes with document-based chunking
The most common mistake is trusting the parser without checking it. Run the parser on a sample of your real documents and inspect the output: are headings detected, are tables whole, are sections grouped correctly? A parser that works on a demo file can fail on your files, and the failure will be silent until users report bad answers.
The second mistake is skipping the second-stage split. Long sections need recursive splitting inside them, or a single chapter becomes a single giant chunk that dilutes its embedding and wastes context. Structure-first does not mean size never matters — it means size is applied within structure, not instead of it.
The third mistake is throwing away the metadata. Section paths, page numbers and table titles are valuable at retrieval and generation time, and discarding them wastes half the benefit of the approach. Store the metadata with every chunk, and use it for filtering, boosting and citation.
Decision checklist
Use this checklist before adopting document-based chunking in production.
- Your documents have real structure — headings, sections, tables — that carries meaning.
- You tested the parser on your own files and confirmed headings, tables and lists are detected correctly.
- Long sections are split further with a recursive splitter inside each section.
- Tables are kept whole, with headers repeated alongside the rows.
- Every chunk carries metadata: document title, section path and page or position.
- You measured retrieval against a recursive-splitting baseline on your own test set.
- You have a fallback for documents whose structure cannot be parsed reliably.
Frequently asked questions
What is document-based chunking?
Document-based chunking splits a document along its own structure — headings, sections, tables and lists — instead of cutting at fixed character or token counts. Each chunk corresponds to a unit the author created, such as a section or a table.
How is document-based chunking different from recursive chunking?
Recursive chunking splits on punctuation and line breaks, which are surface features of the text. Document-based chunking splits on structural elements such as headings and tables, which requires parsing the document’s layout. The two are often combined: structure first, then recursive splitting inside long sections.
Does document-based chunking work for PDFs?
Yes, but it depends on the parser. PDFs store positioned text rather than explicit headings, so detecting structure means inferring it from fonts and layout. Test your parser on your own PDFs before committing, because quality varies widely by document source.
What should I do with tables when chunking by document structure?
Keep each table whole in a single chunk, with its header row included so the data stays interpretable. If a table is too large for one chunk, split it by rows and repeat the headers in every piece.
Is document-based chunking better than semantic chunking?
They solve different problems. Document-based chunking follows the author’s structure, which is fast and free once parsing works. Semantic chunking follows topic shifts detected by embeddings, which finds boundaries the author did not mark but costs an embedding pass over every sentence.
When should I not use document-based chunking?
Skip it for flat prose with no headings, for documents whose structure cannot be parsed reliably, or for small corpora where a recursive splitter already retrieves well. The engineering cost is only worth paying when structure genuinely improves retrieval.







