The RAG evaluation loop
Evaluate retrieval and generation separately: a golden set with relevant chunk ids, recall@k and MRR, groundedness and correctness checks, reading misses, changing one thing at a time, and a runnable loop that shows a stemming fix, a semantic miss and a generation gap.
By Sandip Maity, Applied AI Engineer
"The answers seem better" is not an evaluation. A RAG system has two parts that fail differently, retrieval and generation, and you should measure them separately so you know which one to fix. The general method is in evaluation fundamentals and testing RAG and agents; this lesson is the hands-on loop.
#The loop
- 1Golden setquestions + relevant chunk ids + key facts
- 2Runretrieve, then generate, with one setting changed
- 3Scoreretrieval metrics, then answer metrics
- 4Read missesthe failures tell you what to change
- 5Change one thingchunking, retriever, k, reranker, prompt
#Build the golden set
For each question store:
- the question, written the way users ask (including vague and misspelled ones),
- the ids of the chunks that contain the answer,
- a key fact that a correct answer must contain, or a reference answer for a judge.
Start with 50 to 100 questions taken from real logs or support tickets. Include questions whose answer is not in the documents; the correct behaviour is to say so.
When chunking changes, chunk ids change too. Store the relevant passage text or a source and offset, and map it to the new chunk ids automatically.
#Retrieval metrics
- Recall@k: the share of questions where at least one relevant chunk is in the top k. If it is low, nothing downstream can help.
- MRR (mean reciprocal rank): the average of 1 / rank of the first relevant chunk. Rewards putting it first.
- Precision@k matters when you pass many chunks and irrelevant ones distract the model.
These need no model and run in milliseconds, so you can sweep k, chunk sizes, hybrid weights and rerankers quickly.
#Answer metrics
- Correctness: does the answer contain the key fact? Exact checks first, an LLM judge for free-form answers.
- Groundedness: is every citation one of the retrieved chunks, and is every claim supported by them?
- Refusal behaviour: on unanswerable questions, does it say it does not know?
Pro content
Keep reading with Inference Academy Pro
Unlock the rest of this lesson, plus every advanced lesson, hands-on lab, the larger playground models and completion certificates.
Still to come in this lesson
- A loop you can run
- Change one thing at a time
- Online signals
- Common mistakes
- Exercises
You will be able to answer
- Recall@3 is 0.83 but answer correctness is 0.67. Where is the gap?
- What does MRR reward that recall@k does not?
- 'I bought the same course twice' fails to retrieve the chunk about 'duplicate purchases'. What kind of miss is it?
- Why label relevant chunk ids in the golden set instead of only expected answers?
- You changed the chunk size, the embedding model and the prompt at once and quality rose. What do you know?
Articles that build on this lesson
- RAG vs fine-tuning: which does your problem need? (7 min read)