Retrieval is mostly a search problem
When a retrieval-augmented system gives a wrong answer, the passage it needed usually never reached the model. How to test retrieval separately from generation with recall at k, and what to fix first.
When a retrieval-augmented system gives a wrong answer, look at what it retrieved before you touch the prompt or change the model. My working assumption is that the passage holding the answer never reached the model, and that assumption is right often enough to check it first.
Retrieval-augmented generation has two stages. A search step takes the user's question and pulls a handful of passages out of your documents. A language model then reads those passages and writes an answer. The stages fail in different ways. If search returns the wrong passages, the model writes a fluent answer from the wrong material, which is about what an analyst would do if you handed over the wrong folder and asked for a summary by noon. Changing the model does not help, because the model never saw the right page.
Teams tend to work on the second stage because it is the visible one. The prompt is right there to edit, and a new model is one configuration change away. The search stage is an index somebody built during the pilot and has not looked at since.
Test the two stages separately
You need a set of questions where you know which passage contains the answer. Fifty is enough to start, and they should be real questions from real users where you can get them. For each question, record the document and the passage a knowledgeable person would point to.
Then run only the search step. For each question, look at the top k passages it returns and check whether the right one is among them. The share of questions where it is there is recall at k. If you pass twenty passages to the model, you care about recall at 20. Anthropic's September 2024 write-up on retrieval used the inverse of the same measure: "We use 1 minus recall@20 as our evaluation metric, which measures the percentage of relevant documents that fail to be retrieved within the top 20 chunks."
Record the position as well. A right passage at rank 2 and a right passage at rank 19 both count toward recall at 20, and they are not equally useful. A 2023 paper, "Lost in the Middle," found that models are often at their weakest when the relevant information sits in the middle of a long context. A passage that technically made the cut can still go unused.
Now test generation without search. Take the same questions, paste the correct passage into the prompt by hand and see whether the model answers correctly. If it does, your model and prompt are fine for those questions and every remaining failure belongs to search. If it does not, you have a generation problem, and now you know which questions show it.
Those two numbers, retrieval recall and answer quality given the right passage, tell you where to spend the next month. Without them, every wrong answer starts the same argument about which model to try next.
- Build a question setReal questions, each with the passage that holds the answer
- Run only the search stepRecall at k is the share of questions with the right passage returned
- Test generation without searchPaste the correct passage into the prompt by hand
- Compare the two numbersThey show whether search or generation needs the work
My working assumption is that the passage holding the answer never reached the model, so I check search first.
Where search goes wrong
Chunking. Documents are cut into pieces before indexing, and the cut often separates an answer from the thing that gives it meaning. A paragraph that says "the limit is 30 days" is useless if the product name was in a heading three paragraphs up. Anthropic's write-up describes one fix, which is to attach a short description of the surrounding document to each chunk before indexing it. On their test sets that reduced the top-20 retrieval failure rate by 35%, from 5.7% to 3.7%.
Exact terms. Embedding search matches on meaning. It is weak on part numbers, error codes, account identifiers and people's names, which are often exactly what the user typed. Old-fashioned keyword search handles those well. The BEIR benchmark paper from 2021 tested ten retrieval systems across 18 datasets and reported that BM25, a keyword-ranking method that dates from the 1990s, remained a strong baseline. Running both kinds of search and merging the results is now common practice. In Anthropic's tests, adding keyword search on top of the chunk descriptions took the failure-rate reduction from 35% to 49%.
Ranking. The first-pass search is built for speed. A second model, a reranker, can then read each candidate passage against the question and reorder the list. BEIR found reranking and late-interaction models gave the best average results, at a high computational cost. The usual design is to retrieve widely and rerank down. Anthropic's example retrieves 150 candidates and keeps the top 20, and with that step the reduction in failures reached 67%.
The question itself. Users write short, vague questions and documents are written in the organization's formal vocabulary. A question about "time off" has to find a policy titled "Leave of Absence." Your test set will show whether this is happening, because the failures cluster around certain phrasings.
Stale and duplicate content. If the index holds four versions of a policy, search will return whichever version matches best, and that may be the 2022 one. Search engines have dealt with this for decades using metadata: dates, versions, owners and status. Carry those fields into the index and filter on them.
Permissions. Retrieval has to respect who is allowed to read what. If it does not, the system will summarize a document for someone who could never have opened it. Enterprise search teams solved this years ago, and it is worth asking them how.
What I would fix first
Build the test set before anything else. It costs a few days and it turns every later decision into a measurement.
Add keyword search alongside embeddings if you have only one of them. It is cheap and it fixes the exact-term failures quickly.
Then look at chunking, using the failures in the test set to see where the cuts hurt. After that, add a reranker if recall at a large k is good and recall at a small k is poor. That pattern means the right passage is being found and then ranked too low.
Leave the prompt and the model for last. You may find they were fine.
Those percentages are one vendor's results on its own datasets, and yours will differ. Take from them the order of the steps and the method of measuring, then run the same comparison on your own questions before you believe any figure.
There is also a case where you can skip all of this. The same Anthropic article points out that a knowledge base under about 200,000 tokens can simply be included in the prompt, with no retrieval step at all. Check the size of your corpus before you build a search system for it.
Ownership follows the two stages. The team that owns the documents owns their freshness, their metadata and their permissions. The team that runs the index owns recall. The application team owns the prompt and the answer. The test set is shared by all three teams, and of everything described here it is the piece I would keep longest. If your organization has people who ran enterprise search before any of this was called AI, bring them into the project now.
Sources
Views are my own.