Chunking

Chunking decides the unit that retrieval pipelines can find and context construction can pass to a model. In RAG, chunk boundaries often determine whether citations support the generated claim. A good chunk is small enough to retrieve precisely and large enough to preserve the local meaning of the source.

How a chunker maps a document

A chunker maps a document into ordered spans , where stores source, heading, permissions, and version. Fixed token windows are simple, but heading-aware spans preserve local meaning. Overlap helps boundary cases but increases duplicate retrieval.

Strategies

StrategyHow it splitsStrengthWeakness
Fixed windowevery N tokens, optional overlaptrivial, uniform sizessplits mid-idea; boundary loss
Sentence / recursiveon sentence or paragraph breaksrespects natural unitsuneven sizes
Heading-awarekeeps a heading with the text it governspreserves local context, cleaner citationsneeds document structure
Semanticon shifts in embedding similaritycoherent topical spanscostly, non-deterministic

Overlap of a few sentences between adjacent chunks helps answers that straddle a boundary, at the cost of some duplicate retrieval.

Metadata belongs with the chunk

Every chunk should carry enough metadata to make retrieval and citation safe:

MetadataWhy it matters
source_id and chunk_idstable citations and evaluation.
heading pathpreserves local meaning after extraction from the document.
version or valid dateprevents stale policy from looking authoritative.
permissionsallows ACL filtering before retrieval.
text hashdetects source changes and supports re-indexing.
neighboring chunk IDssupports expansion when the answer crosses a boundary.

Worked chunking example

For a two-section policy document, heading-aware chunking keeps each heading with the paragraph it governs:

ChunkTextWhy this boundary helps
1# Refunds Refunds require receipt. Manager approval is required above 500 EUR.A later answer can cite the approval rule with the refund heading attached.
2# Shipping Standard shipping is five days.Shipping facts do not contaminate refund retrieval.

This boundary is more useful than a fixed window that might split the refund heading from the approval rule or merge refund and shipping facts into one retrieved passage.

Realistic boundary failure

Bad fixed-window chunk:

... Refunds require receipt. Manager approval is required

Next chunk:

above 500 EUR. Finance approval is required above 5000 EUR. # Shipping ...

Neither chunk alone cleanly supports the claim “manager approval is required above 500 EUR.” A heading-aware or sentence-aware chunk keeps the condition with the rule, making retrieval and citation validation easier.

Evaluation

Evaluate chunking with retrieval tests, not visual inspection alone. For a set of questions, check whether an answer-bearing chunk is retrievable, whether its citation span is self-contained, and whether context packing can include it without excessive boilerplate. Rechunking should trigger re-embedding and regression tests because chunk IDs, retrieval scores, and citations may all change.

Caveats

Tiny chunks lose context; huge chunks bury the answer and waste tokens. Overlap improves boundary recall but can produce duplicate chunks that crowd out diverse evidence. Rechunking changes vector IDs and can invalidate cached evaluations.

References