The chunk-size tradeoff
Naive RAG uses one chunk for two jobs: the text you embed, so retrieval can match, and the text you hand the model, so the answer can be explained. No single size is good at both. The two patterns in this course split the jobs, and each split has a bill.
Where naive chunking loses One size, two jobs
Fixed-size chunks fail in opposite directions. The eval set tells you which direction you are in.
Chunk too large — the match fails
- The embedding is an average of a whole window.
- A specific sentence loses to a section that merely shares vocabulary. In the handbook, “30 days” in the PTO chapter outranks the health-enrollment sentence.
- Context relevance drops. The model may still sound grounded, because the wrong passage really does contain a similar fact.
Chunk too small — the explanation fails
- The embedding hits the sentence, and the sentence is not self-contained.
- The exception, the heading, or the next step never reaches the model. “After 30 days” arrives without “first of the following month” or the part-time rule.
- Context relevance can pass while the answer is incomplete. That shows up as answer relevance, or as a grounded fragment that is not the policy.
Shrinking every chunk to fix the first failure creates the second. Growing every chunk to fix the second recreates the first. The patterns below keep a small unit for matching and a larger unit for reading, and they build that larger unit in different ways.
Sentence-window Match small, read a window
Embed sentences so the hit is precise. Replace the hit with the surrounding sentences before the model sees it.
Use it for fact-style questions inside long documents
The matching sentence is specific, and the neighbors carry the meaning: a definition followed by its exception, a number followed by the unit and the condition, a step whose subject was named in the previous sentence. The handbook enrollment rule is this shape. A sentence embedding beats the PTO chapter; a one-sentence window on either side keeps the part-time exception without importing dental.
A wider window raises the chance you retrieved “something related.” The model can lean on a neighbor that was only adjacent, and groundedness drops the same way it drops after an aggressive merge. Latency and token cost move with the width.
Auto-merging Children hit, send the parent
Index a parent–child hierarchy. When enough children of one parent are retrieved, replace those children with the parent section.
Use it when the source has real structure and the answer lives at section level
Headings, sections, and procedures. The question is “walk through new-hire health enrollment,” and no single sentence is the answer. Small children still do the matching, so a query about the first-of-month rule can find that leaf. Once enough leaves of the enrollment section hit, the model sees the section: eligibility, the date rule, and the part-time exception, in order.
The threshold is the knob. A high bar keeps the children and behaves like small-chunk retrieval. A low bar promotes early, and an aggressive merge pulls a parent that also contains the next procedure. That is the groundedness drop: context relevance stays fine because the right section is in the parent, and the model blends in a neighboring rule. Token cost and latency follow the size of the parent you promoted.
Precision, context, cost The architect conversation
Both patterns buy context with tokens. The metric that pays for a bad purchase is groundedness.
| What you embed | What the model sees | When the bill comes due | |
|---|---|---|---|
| Fixed-size | The same chunk | The same chunk | Either the match is diluted, or the explanation is missing a neighbor. You only discover which after you score both legs. |
| Sentence-window | One sentence | The sentence plus a window | A wider window imports adjacent facts. Groundedness falls. Prompt tokens and latency rise with the width. |
| Auto-merging | Child chunks, under a parent | The children, or the parent once the threshold is met | A low threshold promotes a section the question did not need. Same groundedness hit, at the parent’s token cost. |
Architect's lens
Precision, context, and cost are one decision. Say the window size or the merge threshold in the same sentence as the groundedness delta and the token delta. A design that only reports “retrieval improved” has not finished the comparison.
Which pattern first From the failing leg
Look at the questions and the document structure. Then confirm on the frozen set.
| What you see | Try first | Leave it when |
|---|---|---|
| Context relevance is low on fact questions. The answer is one specific sentence, and the document is long prose. | Sentence-window. The match is the problem; small embed units address it, and a short window restores the neighbors. | The window that restores the exception also pulls in the next section, and groundedness falls. |
| The corpus has headings and procedures. The answer is the section. Small chunks match fragments and the answer is incomplete. | Auto-merging. Children match; the parent is the unit the question asked for. | You had to drop the threshold so far that parents promote on a single weak child. |
| The baseline already clears context relevance, and the misses are groundedness or out-of-scope refusals. | Neither. Both patterns add context. The fix is packing, citation, routing, or a refusal. | You would be spending latency to move a metric these patterns do not own. |
If you have to pick before seeing scores, pick from the shape of the work. Fact questions in long documents: sentence-window. Section and procedure questions in documents that already have headings: auto-merging. Then run both against the same evaluation set and keep the row whose failing leg moved inside the token budget.
A mixed corpus
One choice for the whole corpus fails as soon as a file mixes prose, tables, and headings. Route each element to its own chunker, with a fixed-size fallback, onRouting a mixed corpus.
What you must be able to do
- Explain the two ways a single chunk size loses an answer, and why shrinking the chunk does not fix both.
- Choose sentence-window or auto-merging from the question shape and the document structure, then defend it with the triad and the token count.
- State the groundedness and latency cost of a wider window and of a lower merge threshold.
Key takeaways
- Naive RAG fails because the embed unit and the context unit are forced to be the same size.
- Sentence-window is for a specific sentence whose neighbors carry the meaning. Auto-merging is for a real section.
- More context is not free. It raises the chance of a merely related passage, lowers groundedness, and spends tokens and latency.