A few dozen tokens of context cut failed retrievals by 49%
Default chunk sizes have never seen your client's documents, so test on real questions first; adding reranking takes the reduction to 67%.
In brief
- A corpus under roughly 200,000 tokens (about 500 pages) can go straight into the prompt, with no chunking.
- Choose chunk size and overlap from results measured on real questions; do not trust the default configuration.
- Adding 50-100 tokens of context to the start of each chunk cuts failed retrievals by 49%, and by 67% when combined with reranking.
“Revenue grew 3% on the previous quarter”: a RAG system can return that line, copied faithfully from a client’s own documents, and still give the wrong answer. Say a team is in its second week on site. The demo has sailed through ten questions the engineers wrote themselves. Then the head of finance types a real one: how much did second-quarter revenue grow at the northern subsidiary?
The 3% line that comes back is from a different subsidiary’s report, for a different quarter. The model has invented nothing. It was handed a passage that had lost its name and date when the document was split.
Anthropic describes this problem: standing alone, a chunk no longer says which company or period it refers to.
An FDE will run into it on almost every RAG project, because corporate documents are full of phrases such as “as noted above” and “during the period”.
The remedy has three parts, in this order: measure first, split second, and add context to each chunk.
Why not split by default?
Microsoft’s RAG architecture guidance calls the chunking approach a nearly fixed choice in system design. The reason is practical: changing how you split means re-embedding, re-indexing and re-measuring everything downstream. A bad decision in week two will follow you to handover.
Meanwhile, Chroma’s technical report shows that the default settings of some popular chunking strategies perform rather poorly. The library hands you a ready-made chunk size. That number has never seen the client’s documents.
The first question: do you need to split at all?
Before deciding how to split, ask whether you need to. Anthropic notes that if the knowledge base is smaller than 200,000 tokens, or about 500 pages, you can put all of it in the prompt and skip RAG.
At many clients, the document set for a first use case is only a few dozen internal procedures. Counting tokens on day one can save a week of pipeline building. Move to the next step only if the corpus is above that threshold or will soon outgrow it.
Measure with real questions, not by feel
Microsoft advises analyzing the documents first, then trying several chunking approaches on a test set of documents and questions gathered in advance. Document analysis means looking at what the client has: plain text, contracts with numbered clauses, or reports with tables and images.
Document structure determines how to split. According to Microsoft, loosely structured text suits sentence-based splitting or fixed-size splitting with overlap. Semi-structured documents suit layout analysis or custom code written for the format.
Pinecone adds a few questions to answer before choosing: what kind of content it is, which embedding model you use, and how long and complex user questions are. The last can be answered only by sitting with real users, so the test set should come from them rather than from you.
The simplest metric is hit rate: for each question, does the passage containing the answer appear in the top-k results? Chroma goes further with token-level Intersection over Union (IoU), a way of scoring chunking separately from the rest of the RAG pipeline. IoU penalizes the redundant tokens created by overlapping chunks.
A worked measurement, start to finish
Take a hypothetical insurance client with a few thousand contracts. You sit with the customer service team and collect 40 questions they regularly look up, each paired with the clause that contains the answer.
You then run three configurations and measure hit rate at top-5. The numbers below only illustrate how to read the results.
| Configuration | Correct passage in top-5 | Hit rate |
|---|---|---|
| 200 tokens, no overlap | 24/40 | 60% |
| 200 tokens, 50-token overlap | 31/40 | 77.5% |
| 800 tokens, no overlap | 28/40 | 70% |
Small chunks without overlap do clearly worse than the other two, because answers often fall right where the text is cut. This is consistent with Chroma’s observation that with small contexts, overlap is necessary for high recall, and with Microsoft’s warning that relevant context can span several chunks.
The 800-token chunk is no solution either. Pinecone points out that chunks that are too small or too large both make search results less precise. For large chunks the reason is easy to see: a long passage gathers several different ideas, so its embedding rarely matches one specific question sharply.
Overlap has its own price: more duplicate tokens, which means lower IoU and a bloated index. You choose the second configuration, but write down why and what it costs.
Add context to each chunk
The right size still does not fix the error at the start of this article. Whether the “revenue grew 3%” passage is 200 tokens or 800, it does not say which company it belongs to. Contextual Retrieval, a technique introduced by Anthropic, targets this error.
The idea is compact: each chunk gets a short piece of context written specifically for it, usually 50-100 tokens, placed at the start of the chunk before embedding and before BM25 indexing. According to Anthropic, this cuts failed retrievals by 49%, and by 67% when combined with reranking.
The sketch below shows one way to do it: have an LLM read the document containing the chunk and write that context.
# Sketch: llm() and search() are placeholders; swap in the client you use
def contextualize(doc_text, chunk_text, llm):
prompt = (
"DOCUMENT:\n" + doc_text + "\n\n"
"PASSAGE TO PUT IN CONTEXT:\n" + chunk_text + "\n\n"
"Write 1-2 short sentences stating which document this passage belongs to, "
"which entity it concerns and which period. Return only the context."
)
context = llm(prompt) # usually about 50-100 tokens
return context + "\n\n" + chunk_text # embed and BM25-index this string
def hit_rate(test_set, search, k=5):
hits = 0
for q in test_set: # each q has "question" and "gold_span"
results = search(q["question"], k=k)
hits += any(q["gold_span"] in r.text for r in results)
return hits / len(test_set)
Note that hit_rate checks whether the correct passage appears in the results instead of comparing chunk IDs. That lets one test set serve every chunking configuration. Cost is not a worry either: with prompt caching, Anthropic estimates about $1.02 per million document tokens, assuming 800-token chunks and 8,000-token documents.
Context goes beyond prose. When describing a table or image that is split across several chunks, Microsoft advises attaching the image URL to each chunk so the metadata accompanies every answer that uses it. File name, page number and table of contents should travel with each chunk in the same way.
Measure again: the last round of the example
Back at the insurer, you keep the configuration of 200 tokens with a 50-token overlap, add context to each chunk and rerun the same 40 questions. The numbers are again illustrative: suppose the result rises to 35/40, a hit rate of 87.5%, from 31/40 before.
What matters is that you compare on the same questions and the same metric. If you change the test set midway, you can no longer tell whether the improvement came from the context or from easier questions. This two-row “before” and “after” table is also what you show the client when proposing to turn the feature on.
Common mistakes
The most common mistake is writing the test questions yourself. Engineers’ questions tend to use the document’s exact words, which inflates hit rate. Real users’ questions are shorter, vaguer and often use in-house terms.
The second is measuring once and stopping. Whenever the client adds a new document type, for example moving from contracts to meeting minutes, the test set needs questions for it. The third is splitting tables like plain text: a row of figures separated from its column headers is nearly meaningless.
The last is skipping the corpus size check. Plenty of complex pipelines have been built for a document set that fits neatly in one prompt.
Where do employers look for this skill?
In job descriptions for FDE or AI engineer roles, look for phrases such as “retrieval quality”, “evaluation”, “RAG pipeline” or “document ingestion”. They signal that the job will call for the skills described here.
On a CV, a line with a measurement is far more convincing than “built a RAG system”. For example: “Built a set of 40 questions from users, compared 3 chunking configurations, and raised hit rate@5 from X to Y with overlap and per-chunk context”.
In interviews, be ready to explain the trade-offs behind the configuration you chose: overlap raises recall but lowers IoU and bloats the index, while an 800-token chunk is less likely to cut through an answer but is less precise in search. Interviewers want to hear that you know what you paid for that number.
Clients will never ask what your chunk size is. They will remember the time the system gave them another subsidiary’s revenue, and the person who understands why is the one they will want to keep.
Was this article useful?
Thanks for the feedback!