100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Agent Evaluation & Observability
30 minadvanced

Evaluating RAG: Retrieval Quality vs Answer Quality

A RAG system can post a respectable end-to-end score on your eval set and still be broken in a way that score cannot see. The pipeline has two independent stages -- a retriever that selects context and a generator that writes an answer from that context -- and a single pass/fail number averages over both. When the score drops, that average tells you nothing about which stage to open first: whether the retriever handed the generator the wrong documents, or handed it the right documents and the generator wrote the wrong answer anyway. Debugging the wrong stage wastes a cycle and, worse, can leave the actual defect live in production.

This is an exercise lesson, and everything below is buildable: a small labelled corpus of cricket facts, a retriever you can inspect, the four standard retrieval metrics -- recall@k, precision@k, MRR, nDCG -- run over it, a groundedness checker that verifies generated claims against the context that was actually retrieved, and a harness that combines both into a single diagnosis per query. Every number quoted in the prose below is copied from a script's printed output, not estimated -- rerun any of the four code blocks and you will get the same figures.

The organizing idea is a four-way split: good retrieval with a good answer, good retrieval with a bad answer, bad retrieval with a bad answer, and one quadrant that looks harmless and is not -- bad retrieval with a right answer. That last case means the model answered from what it memorized during pretraining rather than from the documents it was given, and it will keep looking correct on your eval set right up until the underlying fact changes and nothing in the pipeline notices.

Analogy🏏Cricket
🏏 Think of it like cricket: Before India's 2023 World Cup semifinal, Rahul Dravid's support staff hand the batting group a scouting report on New Zealand's bowling attack -- where each bowler pitches it, which batter struggles against left-arm spin into the rough. If Kohli gets out cheaply, the post-match review has exactly two places to look: was the scouting report wrong (it said Santner bowls a certain line and he didn't), or was the report accurate and Kohli played the wrong shot anyway? Just as a coaching staff that only tracks 'did we win the match' cannot tell a scouting failure from a batting failure, a RAG eval that only tracks 'was the final answer correct' cannot tell a retrieval failure from a generation failure. Just as Dravid's analysts keep the scouting report and the batting review as two separate documents precisely so a bad review doesn't get blamed on good scouting, retrieval metrics and generation metrics have to be scored separately before you can trust either one. The insight is that diagnosing a loss requires decomposing it into the input you were given and what you did with it -- exactly what a single end-to-end score refuses to do.
Lesson 18 of 35
0% complete