Document retrieval
Chunk Size, Minimum Size and Overlap in RAG
Preserve conditions, tables and short exceptions without filling the prompt with duplicate passages.
A chunk is the unit you can get back
A technician searches for a safety check that applies immediately after replacing a connector. The first paragraph names the replacement procedure, and the next says, “Perform this check only on units fitted with harness H-17.” A splitter puts the first paragraph into one chunk and the condition into another. The first chunk retrieves well because it contains the product name and the repair task. The condition, on its own, embeds as a fragment about a harness. The assistant sees enough to sound helpful while missing the condition that determines when the check applies.
Chunking is an information design decision. The retriever scores and returns the records you indexed. Each record needs enough local context to be found and interpreted, while remaining focused enough to rank for a specific question. A useful chunk might be a procedure step with its prerequisites, a table row with its column labels, or a short policy clause with the heading that identifies its scope. The aim is a unit of evidence a reader could understand and cite.
Give target size, minimum size and overlap different jobs
Target size governs how much material you try to place into each chunk. For an experiment you might start with a target of 350 tokens, split at paragraph or sentence boundaries when possible, and cap the chunk at a documented input budget. Treat the cap as a distinct setting if your splitter provides one. A 350-token target can produce shorter chunks around natural section endings.
Minimum size describes what the splitter does with a fragment below a useful threshold. For example, with a 70-token minimum, a 40-token tail may join an adjacent compatible paragraph. Some libraries skip small chunks or use a minimum measured in characters. Check the implementation before setting that knob, and define an explicit preservation rule for a short warning, exception or table row. In many domains the shortest clause is the one that changes the answer.
Overlap repeats material near a boundary. A window with 350 tokens and 50 tokens of overlap advances by about 300 tokens per step if fixed length. That duplication increases the chance that adjacent wording survives in at least one chunk. It only bridges what lies inside the overlap. A part number in a heading far earlier in the document needs carried metadata, a parent reference or a different segmentation strategy.
| Control | Value | Failure to watch for |
|---|---|---|
| Target size | 350 tokens | A long window buries the revision-specific clause. |
| Minimum size | 70 tokens | A short exception disappears if the splitter discards it. |
| Overlap | 50 tokens | Adjacent copies crowd out another required source. |
Follow a boundary in a worked example
Consider a maintenance manual with three successive passages. The heading says “AX-450, revision B, connector replacement”. The first paragraph describes the work. A second paragraph gives an exception for a particular harness. A small box after it lists the approved connector codes and a special-order note. All codes in this example are fictional. An evaluation question asks, “Which connector is allowed for revision B when an H-17 harness is already fitted?”
With a small fixed window, the top result may be the second paragraph because it contains H-17. If the answer requires the approved codes, that paragraph alone is incomplete. With a very large window, the question may rank a whole maintenance section that also covers wiring, storage, routine cleaning and a revision C procedure. That result has the right words but makes it harder to isolate the evidence and consumes more of the final prompt.
Try a section-aware chunk that carries the heading and keeps the exception with the list it qualifies. For a Markdown source, a parser can read the header hierarchy and carry the relevant heading into each child. For a PDF, inspect the extraction order before trusting its line breaks. A two-column manual can produce interleaved sentences that no token budget will repair. Preserve the source reference used for display independently of any text added for retrieval.
Use a minimum size without losing short exceptions
Imagine the end of an otherwise well-sized policy section produces a 22-token fragment. It says “This exception expires on 30 June. After that, use the revised approval schedule.” A rule that discards everything below 60 tokens removes the only expiry notice. Merging the fragment with the next heading about another policy can be just as confusing. The correct merge target is usually a neighbouring block that shares the heading, version and access policy. If there is no safe neighbour, keep the fragment and attach enough approved parent context to identify it.
Useful exceptions include standalone warning callouts, compact table rows and titles whose following block has a different access scope. They can stay short if they have clear identifying context. Enforce a budget after merging so the result does not exceed the encoder's input allowance and silently lose the final paragraph. During ingestion, count what happens to small candidates. Log counts for merged, retained and rejected fragments. Examine a sample from each bucket alongside the original document. This is where a configuration value becomes observable behaviour.
Put overlap where the boundary actually causes harm
Stride = window size − overlap
Long-section duplication ≈ window size ÷ strideIf a 1,100-token section is cut into 350-token fixed windows, no overlap requires four windows. With 100 tokens of overlap, the stride is 250 and the same section also needs four windows through the end. The difference is that those windows contain about 1,400 tokens in total instead of 1,100. On much longer sequences the duplication factor approaches window size divided by stride, or 1.4 in this example, ignoring the edge windows. Real structural splitters will produce different counts. Measure on your corpus, including repeated headings and metadata.
The duplicated text helps when a key noun or qualification lies near a split. It can hurt when five adjacent chunks all retrieve on the same sentence and fill the candidate list. A rare exception from a different section then never reaches the reranker. Apply modest overlap inside a section where the seam matters. Deduplicate or merge overlapping spans before packing the answer prompt. Use document ID, version and offsets to recognise overlapping evidence while preserving separate clauses that are genuinely required.
Another inexpensive tactic is to index focused child chunks and retrieve a neighbouring span on demand. For example, search returns the exception paragraph and the application expands it to include the next table. Recheck access on any expanded content. The presumed parent or sibling may have different permissions, even if it is physically adjacent in a file.
| Overlap | Window starts | Tokens indexed |
|---|---|---|
| 0 tokens | 0, 350, 700, 1,050 | 1,100 |
| 100 tokens | 0, 250, 500, 750 | 1,400 |
Choose a method that fits the source
A consistent token window is a strong baseline because its behaviour is easy to reproduce. Use it to establish a comparison before adding more logic. A recursive splitter can try sections, paragraphs and sentences before falling back to tokens. That is a practical next step for manuals and policies. Structured content often benefits from explicit rules. Store table headings with each row, retain column units, and keep a definition with the conditions it governs. Avoid flattening unrelated rows into one paragraph solely to reach a minimum token count.
Late chunking tackles the context problem at a different point. The encoder first processes a larger span with a long-context model, then pools contextualised token representations into chunk vectors. The retrieved chunk can remain short even though its representation uses information from surrounding text. This needs compatible model access and pooling support. Passing each already-split chunk to an ordinary embedding endpoint does not implement the method. It also does not automatically insert missing evidence into the generator prompt. If the answer needs the full table, make sure the table reaches the prompt.
Compare chunking on labelled source spans
Keep the corpus, access rules, encoder and query set fixed. Label evidence by source version and span before running the splitters. If you label only existing chunk IDs, a different splitter will produce different IDs and the comparison will be misleading. Include boundary-spanning questions, short code lookups, topics with frequent repeated headings, and questions that need evidence from two sections.
Try a small matrix. For example, compare a 250-token baseline with a 450-token baseline. Then try a modest overlap on the better setting and compare a minimum-size merge rule with a version that retains short warnings. Keep the candidate count fixed for one comparison, then compare at equal token budgets. Ten 450-token chunks send substantially more material than ten 250-token chunks. A gain may reflect the budget change rather than a better split.
Record how often the minimum evidence enters the candidate set and how much irrelevant material comes with it. Measure answer support after reranking and packing, as well as index size, ingestion time and query latency. Chroma's evaluation report explores span-level retrieval metrics that make it possible to distinguish more evidence from more repeated text. Its results are an example of an evaluation design, and your manuals may behave differently.
Review examples before rolling out a splitter
Suppose both splitters find the required revision and harness exception for 45 of 50 questions. One version sends two nearly identical chunks for most successes and rarely includes the connector code table. The other regularly sends one focused chunk plus the relevant table row. The hit rate masks a meaningful difference in context efficiency and answerability. Count unique spans, and check that the model input contains every condition needed for the answer.
Find some cases where the new approach makes things worse. A boundary-aware method may keep a long complex section intact until it exceeds the hard budget. A minimum-length merge may pull a phrase from an adjacent revision. More overlap may crowd a narrow candidate pool. Annotate the failure and identify the smallest change that fixes it. Retest other documents with the same structure to make sure the fix generalises beyond a single manual.
Make the ingest version visible in your evaluation output. When you rebuild, preserve document and version identifiers for access and citations even if the chunk IDs change. If users can bookmark a passage, decide how the new version maps to old links and retain canonical source references.
Check the two ends of every lossy pipeline
Sample the search index after extraction, tokenisation and storage. Retrieve one oversized source and one page made mainly of tables. Compare stored text with the original visually and inspect what the embedding input contains near the cap. Then run the same comparison against the context sent to the generator. The index and the answer stage can truncate different parts of the same item. A sensible target size cannot compensate for OCR that misread B07 as BO7, and a careful extraction step cannot compensate for a packer that discards the qualifier after reranking. Save examples with source offsets so the team can inspect the problem again after the next rebuild.
Write down the policy you can defend
A pragmatic starting policy is to preserve source structure, keep identifying headers attached, merge small fragments only across compatible boundaries and add overlap where tests show lost evidence. Treat those as choices to verify, because a troubleshooting guide, a legal policy and an inventory catalogue will offer different natural units. A one-row catalogue record with a code and exact attributes may be complete at 30 tokens. A paragraph about a conditional maintenance exception may need a heading and two nearby steps.
Before calling the experiment successful, inspect the initial example end to end. Does the authorised chunk recognise the revision B procedure and H-17 harness? Does the evidence handed to generation contain the approved code and any relevant exclusion? Can the user locate the cited source and see the same meaning? If the answer to one of these is no, identify which boundary or assembly rule lost the information. The best size is the one that keeps those answers reliable within your retrieval and latency budget.