Lesson 5.2: Retrieval quality and reranking
Measure whether retrieval finds the right chunk using hit rate and MRR, then improve it with hybrid search, query rewriting and reranking, with cost figures.
In a retrieval-augmented system, the language model can only answer from what it is shown. If the passage that holds the answer never reaches the prompt, the best model in the world will guess, refuse or invent. This makes retrieval the ceiling on the quality of the whole system, and it is the part most worth measuring and improving first. Yet many teams tune the prompt for weeks while retrieval quietly misses one question in four. This lesson shows how to measure retrieval on its own, how to read the numbers, and the main ways to improve it: combining keyword and vector search, rewriting the question, filtering, and reranking a wide list of candidates with a more careful model. By the end you will be able to define hit rate at k, precision at k and mean reciprocal rank, and compute them from a small test, explain the common reasons retrieval misses, combine two ranked lists with reciprocal rank fusion, describe how a reranker differs from the first-stage search and why it improves results, work out what a reranking step costs in money and delay and what it can save, and plan a first set of improvements in a sensible order. You should have read Lessons 4.1 to 4.4 and Lesson 5.1. No programming is needed, and the arithmetic is addition, division and simple fractions.
Retrieval is the ceiling
Recall the pipeline from Lesson 5.1: the question is embedded, the nearest chunks are found, the best few go into the prompt and the model answers. At each step something can go wrong, but they are not equally recoverable. If the right chunk is in the prompt, a good model usually uses it. If it is not, nothing downstream can fix the answer. So the rate at which retrieval puts the right chunk in front of the model sets an upper limit on how many questions the system can answer correctly.
Because of that, you should measure retrieval separately from the answer. A test for retrieval needs only two things: a list of realistic questions, and for each one, the chunk or chunks that actually contain the answer. You do not need to run the language model at all. This makes the test fast, cheap and repeatable, and it points at one stage only. When you change the chunk size, the embedding model or the number of results, you can see within minutes whether retrieval got better or worse.
The metrics
Suppose you have ten test questions, and for each you know which chunk holds the answer. You run each question through retrieval and note the rank of the correct chunk: 1 if it came first, 2 if second, and so on.
Question · Rank of the correct chunk1 · 1
2 · 1
3 · 2
4 · 3
5 · 1
6 · 8
7 · 15
8 · 2
9 · 1
10 · 4
Hit rate at k, also called recall at k when each question has one correct chunk, is the share of questions where the correct chunk appears in the top k results.
At k = 1: questions 1, 2, 5 and 9 have rank 1, so 4 of 10, or 40%.
At k = 3: ranks of 3 or lower are questions 1, 2, 3, 4, 5, 8 and 9, so 7 of 10, or 70%.
At k = 5: add question 10 (rank 4), so 8 of 10, or 80%.
At k = 10: add question 6 (rank 8), so 9 of 10, or 90%.
At k = 20: add question 7 (rank 15), so 10 of 10, or 100%.
Mean reciprocal rank, or MRR, rewards putting the right chunk near the top. For each question, take 1 divided by the rank, then average. Here the values are 1, 1, 0.5, 0.33, 1, 0.125, 0.067, 0.5, 1 and 0.25. They sum to 5.775, so the MRR is 0.5775, about 0.58. A system that always put the right chunk first would score 1.0.
Precision at k asks a different question: of the k chunks returned, how many are relevant? If you retrieve five chunks and two of them hold part of the answer, precision at 5 is 40%. Precision matters because the prompt has limited space and the model can be distracted by irrelevant passages. Hit rate matters because a missing chunk cannot be recovered. In practice you want a high hit rate at the number of chunks you can afford to put in the prompt, and as high a precision as you can get.
Predict first: look at the hit rate figures. The correct chunk is in the top 20 for every question but in the top 5 for only eight of ten. If your prompt has room for five chunks, which question would you try to fix first, the one where the right chunk is at rank 15 or the one where it is at rank 8? Think about what you could do before you read on.
Both are candidates for the same remedy. A second step that looks at the top 20 more carefully and picks the best five would move rank 8 and rank 15 into the top five if it judges them well. That is the idea of reranking, which we come to below. First, let us see why retrieval misses.
You can try your own results with the first simulator.
Why retrieval misses
When a question fails, there is usually a clear cause. The common ones are these.
The words do not match the way the embedding sees them. Embeddings capture meaning, but they are weak on exact strings: product codes, error numbers, names, section numbers and rare terms. A question about "error E-4021" may not retrieve the one chunk that contains that code.
The chunk lost its context. A chunk that says "It must be returned within 30 days" does not say what "it" is. Lesson 4.3 showed why chunks should carry titles and section headings.
The answer is split across chunks, so that neither half is similar enough to the question.
The question is vague or depends on the conversation. "What about for gold members?" cannot be searched without knowing what came before.
Similar documents compete. Several versions of a policy, or near-duplicate pages, push each other down the list, and an old version may outrank the new one.
Wrong or missing filters. The chunk exists but is hidden by a filter on region, product or date, or the filter is missing and chunks from the wrong region fill the list.
The question needs several chunks. A question that compares two plans needs both, and getting both into the top k is harder than getting one.
The embedding model is not suited to the content. A model trained mostly on English web text may handle technical Hindi-English mixed text or specialised terms poorly.
Diagnose before you fix. Take the questions that failed, look at what was retrieved, and write down the cause for each. A pattern will appear, and the pattern tells you which remedy to try.
Remedy 1: combine keyword and vector search
Keyword search, such as the classic BM25 method, scores chunks by how many of the question's rare words they contain. It is excellent for exact strings and weak at meaning. Vector search is the opposite. Hybrid search runs both and combines the results, and in most systems that deal with specific terms it beats either alone.
The two searches produce lists with different kinds of scores, so adding scores directly makes little sense. A simple and robust method is reciprocal rank fusion. Each chunk gets a score of 1 divided by (60 plus its rank) from each list it appears in, and the scores are added. The number 60 is a common default that stops the very top ranks from dominating.
Suppose the vector search returns chunks A, B, C and D in that order, and the keyword search returns C, A and E.
A: rank 1 in the vector list and rank 2 in the keyword list: 1 ÷ 61 + 1 ÷ 62 = 0.01639 + 0.01613 = 0.03252.
C: rank 3 and rank 1: 1 ÷ 63 + 1 ÷ 61 = 0.01587 + 0.01639 = 0.03226.
B: rank 2 in the vector list only: 1 ÷ 62 = 0.01613.
E: rank 3 in the keyword list only: 1 ÷ 63 = 0.01587.
D: rank 4 in the vector list only: 1 ÷ 64 = 0.01563.
The fused order is A, C, B, E, D. Chunks that both searches like rise to the top, and E, which only the keyword search found, now sits above D. If the question contains an exact code, the keyword list pulls the right chunk up even when the vector search ranked it low.
Remedy 2: fix the question and the filters
Rewrite follow-up questions into standalone ones, using the conversation so far, before searching. "And for digital goods?" becomes "What is the refund period for digital goods?".
Expand or generate variants. A model can write two or three rephrasings of the question, and you search for all of them and merge the results. This helps when users and documents use different words.
Break a compound question into parts and retrieve for each part.
Use metadata filters for region, product, version and date, so that the search looks only at chunks that could be right, and make sure the filter values come from reliable data, not from the model's guess.
Prefer newer versions. Add the date as a filter or a small boost so that an old policy does not outrank the current one.
Each of these costs a little in delay and tokens, so apply the ones your failures call for.
Remedy 3: retrieve more, then rerank
The fast first-stage search compares one vector for the question against one vector for each chunk. This is cheap enough to run over millions of chunks, but it has to squeeze the meaning of the question and of the chunk into separate vectors before comparing them, and some detail is lost. A reranker works differently. It is a model that reads the question and a candidate chunk together, in a single input, and gives a relevance score. Because it sees both at once, it can notice whether the chunk really answers the question, how the words relate and whether a negation changes the meaning. A model of this kind is often called a cross-encoder.
The cost is that it is too slow to run on every chunk in the collection. So the two are combined in a funnel.
1. First stage. Retrieve a wide list, say the top 30 candidates, using hybrid or vector search. The aim is a high hit rate at 30.
2. Rerank. Score each of the 30 chunks against the question with the reranker and sort by score.
3. Keep the best few, say the top 4, and put those in the prompt.
The funnel has a useful property: the reranker can only reorder what the first stage found. If the right chunk is not among the 30, no reranker will find it. So the quality of a reranked system is capped by the hit rate at 30, and you should check that number first. If it is 95%, reranking has a lot of room to work. If it is 60%, fix the first stage.
What does reranking gain? In a typical test, the first stage might put the right chunk in the top five 70% of the time and in the top 30 about 95% of the time. After reranking, the right chunk is in the top five perhaps 85% to 90% of the time. These numbers are illustrations, not promises, and results vary a great deal with the data and the models, so you should measure on your own questions.
There is a second benefit. Because the reranked list is more precise, you can send fewer chunks to the language model. Instead of sending 10 chunks to be safe, you may send 4. That cuts the tokens in the prompt, which lowers the cost of generation and the delay. The cost of reranking itself must be set against this saving.
What reranking costs
A reranker adds a delay, usually tens to a few hundred milliseconds depending on how many chunks it scores and how large the model is, and a charge. Many providers charge per search, for example a fixed amount per thousand reranking calls, and self-hosted rerankers cost compute time instead.
Take an example with invented prices. Each prompt has 800 tokens of instructions, conversation and question, and each chunk is 500 tokens. Input costs ₹30 per million tokens.
Without reranking, the system sends 10 chunks to protect against misses: 800 + 10 × 500 = 5,800 input tokens, costing 5,800 × 30 ÷ 1,000,000 = ₹0.174.
With reranking, it sends the best 4: 800 + 4 × 500 = 2,800 tokens, costing ₹0.084. The reranker charges ₹50 per thousand calls, which is ₹0.05 per question. The total is ₹0.134.
Reranking saves ₹0.04 per question, or ₹4,000 a month at 100,000 questions, and improves the chance that the right chunk is in the prompt. If the reranker's price were ₹100 per thousand calls, the saving on input cost would disappear, and the case for it would rest only on better answers. That may well be enough, but you should know which it is.
An order of work
When retrieval is not good enough, resist the urge to try everything. A sensible order follows the cost and likely gain.
1. Build the test. Collect 50 to 100 real questions with their correct chunks. Without this you are guessing.
2. Look at the failures. For each missed question, write the cause from the list above.
3. Fix the data first. Clean extraction, add titles to chunks, remove duplicates, mark versions. These fixes are cheap and often large.
4. Tune chunking and k. Try different chunk sizes and overlaps, and check the hit rate at the k you can afford.
5. Add hybrid search if exact terms, codes or names matter.
6. Rewrite questions if follow-ups or vague questions are a big part of the failures.
7. Add a reranker when the right chunk is often in the top 20 or 30 but not in the top few.
8. Try a different embedding model if failures are spread across many kinds of question and a stronger model may help.
9. Re-run the test after each change, and keep what helps. Many ideas will not.
Three worked examples
Example 1: product codes. A support assistant for an electronics company fails on questions such as "How do I fix error E-4021 on the XR-200?". The hit rate at 5 for questions containing a code is 45%, against 85% for others. The cause is that the vector search treats codes as a weak signal. The team adds keyword search and fuses it with reciprocal rank fusion. The hit rate at 5 for code questions rises to 80%, with no change for other questions. The test, which split results by question type, showed where the problem was.
Example 2: a wide funnel. A bank's policy assistant has a hit rate of 68% at 5 and 94% at 30. The gap of 26 points means the right chunk is usually found but ranked too low. The team adds a reranker on the top 30. The hit rate at 5 rises to 87%. It then reduces the chunks in the prompt from 8 to 4, which cuts input tokens by about 40% and pays for the reranker. The reranker added about 150 milliseconds of delay, which the team offsets by streaming the answer.
Example 3: stale versions. A legal team's assistant sometimes answers from the previous year's template, which ranks higher than the new one because it has been cited more often in other documents. A reranker does not fix this, since both texts answer the question well. The team adds a version and date field to each chunk, filters to the current version by default, and shows older versions only when a user asks. The right fix was in the data and the filter, not in the ranking model.
A retrieval worksheet
1. The test set. How many questions, from where, with which correct chunks?
2. The baseline. Hit rate at 1, 5 and 20, and MRR.
3. The failures. For each miss, the cause.
4. The pattern. Which cause is the most common?
5. The ceiling. What is the hit rate at the widest k you could rerank?
6. The cost. Delay and money added by each change.
7. The change. One remedy to try first, and the number you expect to move.
8. The result. Hit rate after, and whether it was worth the cost.
9. The guard. How the test runs again whenever the data, chunking or model changes.
10. The next step. What remains and what it would take.
Common mistakes
Tuning the prompt while retrieval is missing the answer.
Measuring only the final answer, so that retrieval failures hide among other causes.
Testing on questions written by the team, which are cleaner than real ones.
Adding a reranker when the right chunk is not in the candidates.
Using only vector search for content full of codes, names and numbers.
Sending too many chunks to make up for poor ranking, which raises cost and distracts the model.
Ignoring versions and dates, so that old documents win.
Changing several things at once, so that nobody knows what helped.
Key takeaways
Retrieval sets the ceiling on a RAG system. If the right chunk is not in the prompt, the answer cannot be reliably right.
Measure retrieval alone with hit rate at k, precision at k and MRR, on real questions with known correct chunks. In the ten-question test the hit rate is 40% at 1, 80% at 5 and 100% at 20, and the MRR is 0.58.
Retrieval misses for reasons you can see: exact terms, chunks without context, split answers, vague questions, competing versions, wrong filters and weak embeddings.
Hybrid search with reciprocal rank fusion combines keyword and vector results, and helps with codes and names.
A reranker reads the question and each candidate together and re-orders a wide list. It can only reorder what the first stage found, so the hit rate at the wide k is its ceiling.
Reranking costs delay and money, but can pay for itself by letting you send fewer chunks. In the example it saves ₹0.04 per question, ₹4,000 a month.
Fix the data first, test after every change and keep only what helps.
Check yourself
1. Eight of twelve test questions have the right chunk in the top 5. What is the hit rate at 5?
8 ÷ 12 = 66.7%.
2. The right chunks rank 1, 2 and 4 for three questions. What is the MRR?
(1 + 0.5 + 0.25) ÷ 3 = 0.583.
3. Why can a reranker not fix a question whose right chunk is not in the top 30?
It only reorders the candidates the first stage returned. A chunk that is not among them is never scored.
4. Why does hybrid search help with an error code like E-4021?
Keyword search matches the exact string, which vector search treats as a weak signal, so the fused list ranks the right chunk higher.
5. A reranking step lets you send 4 chunks of 500 tokens instead of 10, at ₹30 per million input tokens. How much input cost do you save per question, before the reranker's own price?
6 fewer chunks is 3,000 tokens, and 3,000 × 30 ÷ 1,000,000 = ₹0.09.
6. What should you do before adding a reranker?
Check the hit rate at the wide k you will rerank, and fix data and chunking problems first.
Try this
Measure retrieval on your own documents. Set aside 60 minutes.
1. Choose a set of documents, such as a help centre, a policy folder or a set of notes.
2. Write 20 questions that real users would ask, and for each note the passage that holds the answer.
3. Run each question through your search, whether a vector tool, a keyword search or a simple document search, and record the rank of the correct passage.
4. Enter the counts in the first simulator, and write the hit rate at 1, 5 and 20.
5. For each miss, write the cause from the list in this lesson, and find the most common one.
6. Choose one remedy, apply it, run the test again and write the new numbers.
7. Use the second simulator with your own chunk size and prices to see whether a reranker would pay for itself.
A good result is a list of questions with correct passages, hit rates before and after, a named cause for each miss and a cost estimate for the next change.
Tags: AI Engineering RAG Reranking Retrieval Evaluation