Tuning RAG Retrieval
- Explain how chunking affects retrieval quality
- Describe hybrid search and why it helps with exact terms
- Describe the role and cost of reranking
- Measure hit rate at k against a fixed test set
- Evaluate one retrieval change at a time
Retrieval Is the Ceiling
A language model cannot use a document it never sees. In a RAG system, if the right chunk is not retrieved, no prompt can fix the answer. This lesson assumes you have already built a basic RAG pipeline (see RAG for Agents if you have not) and focuses on the levers that most often improve retrieval, and on how to know whether a change actually helped.
Lever 1: Chunking
You split documents into pieces before indexing. Pieces that are too large dilute the meaning of each embedding, and pieces that are too small lose context. Anthropic's contextual retrieval write-up gives a clear example: a chunk saying "the company's revenue grew by 3% over the previous quarter" does not say which company or which quarter, so it is hard to retrieve for the right question. Common fixes:
- Split along natural boundaries such as headings and paragraphs, not at a fixed character count
- Add overlap between neighboring chunks so ideas are not cut in half
- Attach the document title or a short generated description of where the chunk fits
Anthropic's contextual approach has a model write a short context (50 to 100 tokens in the post) for each chunk and prepend it before indexing. The post reports that generic summaries added little, so the context needs to be specific to the chunk.
Lever 2: Hybrid Search
Embedding search finds meaning but can miss exact terms such as error codes, product names, and IDs. Keyword search (BM25) catches exact terms but misses paraphrases. Hybrid search runs both and merges the results with a rank-fusion step. Anthropic's pipeline combined embeddings and BM25 this way and deduplicated the merged list.
Lever 3: Reranking
A reranker takes a wide candidate list and rescores it more carefully against the question. In Anthropic's experiment the pipeline retrieved the top 150 candidates, reranked them, and passed the top 20 to the model. Reranking costs extra latency and money, so measure whether it earns its place on your data.
What Anthropic Reported
Anthropic measured the failure rate as one minus recall at 20, meaning how often the right chunk was missing from the top 20, averaged over several kinds of data such as code, fiction, and scientific papers. Their numbers, from their own experiments:
- Contextual embeddings cut failures by 35% (5.7% down to 3.7%)
- Adding contextual BM25 cut them by 49% (to 2.9%)
- Adding reranking cut them by 67% (to 1.9%)
These came from a vendor blog on specific data sets, so treat them as evidence that the levers can matter, not as a promise for your data. Generating context for every chunk also costs money; Anthropic estimated about $1.02 per million document tokens under its assumptions with prompt caching.
A Simple Retrieval Test
You do not need a framework to start. For each task in your test set, record which document or chunk should contain the answer. Then measure hit rate at k: the share of tasks where that source appears in the top k results. Track hit rate at 5 and at 20, and note the average rank of the right chunk. Anthropic's metric, one minus recall at 20, is the same idea turned upside down.
Illustrative result table, with made-up numbers: baseline hit rate at 5 of 62%; after adding document titles to chunks, 70%; after adding BM25, 78%; after adding a reranker, 85%. What matters is that each row changes only one thing.
Change One Lever at a Time
The discipline that makes tuning work is measurement. Keep your test set fixed, change one thing (chunk size, overlap, add BM25, add a reranker), and compare. If two changes land together you cannot tell which one helped or which one hurt. Also watch for regressions: a change that helps typical questions may hurt exact-ID lookups.
What Retrieval Tuning Cannot Fix
If the answer is simply not in your documents, retrieval cannot find it. That is a content problem, and your test set should include unanswerable questions to check the system says so. The next lesson shows how to score retrieval and generation separately so you know which half to work on.
Try This
For 20 questions from your test set, note the document that should contain the answer. Record whether it appears in your top 5 and top 20 retrieved chunks. Change one lever, repeat, and compare the hit counts. Keep a table of what you changed and the result, and keep any change that helps without hurting your edge cases.
- Retrieval quality caps the quality of every RAG answer
- Chunk context, hybrid search, and reranking are the main levers
- Vendor benchmarks show potential, not guaranteed gains on your data
- Fix the test set and change one lever per experiment
- Missing content is a data problem, not a tuning problem
Progress is saved in this browser only — clear your cache or switch device and it's gone. Create a free account and it follows you everywhere.