AI ENGINEERING · RETRIEVAL AND RAG IN DEPTH · QUALITY · 25 OF 35

How to Evaluate a RAG System: Retrieval and Answers

How to measure a RAG system in two halves: retrieval with recall at k, precision at k and MRR worked on three queries, and answers with faithfulness, relevance, completeness and citation accuracy. Building a test set, the risks of synthetic questions, model-as-judge checked against human labels, diagnosing failures, regression gates and online signals.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
1 / 19

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Split retrieval from generation
  • recall first
  • narrow judges checked by people
  • bucket failures
  • gate every change

Notes

The idea

The core idea is to split the system in two. Retrieval has one job: get the passage that holds the answer into the prompt. Generation has another: turn those chunks into an answer that is true to them, on topic and complete. If you only grade the final answer, a bad score tells you something broke, but not which half. Measure both halves separately and every failure points to its own fix.

Two questions, not one
  • retrieval: did the right passage reach the prompt at all?
  • generation: given those chunks, is the answer true to them, on topic and complete?
  • one end score hides which half broke

A real test set

Everything starts with a test set. Take real questions from logs, support tickets or the people who will use the tool. For each one, record the gold passages that answer it, and a short reference answer. Start with fifty to a hundred. Include questions your documents cannot answer, so you can check the system says so. Label passages by document and position, not chunk id, so the labels survive a rechunk.

One test case
question: "Can I get a refund
           after 30 days?"
gold passages: refund-policy.md
  section 2, lines 14-19
reference answer: "No cash
  refund; store credit only."
tags: billing, policy

start with 50-100, grow to
a few hundred; add unanswerable
questions too

Synthetic questions

Many teams also generate questions. Pick a chunk and ask a model to write a question it answers. You get the gold passage for free. But watch the risks. Generated questions tend to reuse the passage's exact words, which makes retrieval look far better than it is. They are rarely vague or multi step. Paraphrase them, review a sample, and mix in real questions.

Generate from documents
  • pick a chunk, ask a model: "write a question this passage answers"
  • gold passage is known for free
  • risks:
  • copies the passage wording, so retrieval looks too good
  • never multi-hop or vague
  • questions nobody would ask
  • fix: rewrite, review, mix real

Retrieval metrics

Three retrieval metrics cover most needs. Recall at k asks what share of the gold passages appear in the top k results. Precision at k asks what share of those top k are gold, so it measures noise. Reciprocal rank is one divided by the position of the first gold hit, or zero if there is none. Average it over all queries and you get mean reciprocal rank. Use the k you actually put in the prompt.

Three metrics
  • recall@k: share of the gold passages found in the top k
  • precision@k: share of the top k that are gold
  • reciprocal rank: 1 / rank of the first gold hit; 0 if none
  • MRR: its mean over queries
  • k = what you put in the prompt

A worked example

Three queries, top five each. Query one has gold A and B and finds both, so recall is one and precision is two fifths. A sits at rank one, so reciprocal rank is one. Query two finds its single gold passage at rank three: recall one, precision one fifth, reciprocal rank one third. Query three finds one of two, at rank two: recall one half, rank one half. Averages: recall zero point eight three, precision zero point two seven, M R R zero point six one.

k = 5, gold in caps
Q1 gold A,B  top5: A x B y z
   recall 2/2=1.0  prec 2/5=0.4  RR 1
Q2 gold C    top5: x y C z w
   recall 1/1=1.0  prec 1/5=0.2  RR 1/3
Q3 gold D,E  top5: x D y z w
   recall 1/2=0.5  prec 1/5=0.2  RR 1/2

recall@5    (1+1+0.5)/3   = 0.83
precision@5 (0.4+0.2+0.2)/3 = 0.27
MRR         (1+0.33+0.5)/3 = 0.61

Reading the numbers

For RAG, recall matters most, because a passage that never reaches the prompt can never be used. Measure recall at fifty before a reranker and recall at five after it, so you know which stage lost it. Precision tells you how much noise and token cost you add. Reciprocal rank, or its graded cousin n D C G, tells you if the best chunk is near the top.

Which metric when
  • recall@k: the headline. If the passage is absent, no prompt can save the answer
  • recall@50: before a reranker
  • precision@k: noise and token cost in the prompt
  • MRR / nDCG: is the best chunk near the top?
  • low precision is normal when most queries have 1 gold chunk

Grading answers

Now the answer half. Ask four separate questions. Faithfulness: is every claim supported by the retrieved text? Answer relevance: does it address what was asked, rather than a nearby topic? Completeness: does it cover the key points of the reference answer? And citation accuracy: when the answer cites a chunk, does that chunk really say it? Keep them separate. An answer can be perfectly faithful and still miss the question.

Generation metrics
  • faithfulness: is every claim supported by the retrieved text?
  • answer relevance: does it address the question asked?
  • completeness: does it cover the reference answer points?
  • citation accuracy: does each cited chunk really say it?

Faithfulness, worked

Here is faithfulness in practice. The chunks say refunds within thirty days, store credit after that, and no refunds on digital items. The answer makes four claims. No cash refund after thirty days, supported. Store credit is available, supported. Digital items are not refundable, supported. Store credit lasts a year, not in the text at all. Three of four claims are supported, so faithfulness is zero point seven five. It may be true, but nothing retrieved backs it.

Claims vs retrieved text
chunks: "Refunds within 30 days.
  After that, store credit only.
  Digital items: no refunds."

answer claims:
 1 no cash refund after 30 days  ok
 2 you can get store credit      ok
 3 digital items not refundable  ok
 4 store credit lasts a year     ??

faithfulness = 3/4 = 0.75

Model as judge

Grading hundreds of answers by hand is slow, so we ask a model to judge. The trick is a narrow rubric. Do not ask it to rate quality from one to ten. Ask one question at a time, with a yes or no answer: given this context, is this claim supported? Say what counts and what does not, ask it to quote the evidence, and run it at temperature zero. Narrow, binary questions give stable, explainable scores.

A narrow rubric
You are given CONTEXT and one
CLAIM. Answer only "supported"
or "unsupported". Supported means
the context states or directly
implies it. Background knowledge
does not count.

avoid: "rate quality 1-10"
do: one criterion per call,
quote the evidence, temp 0

Check the judge

A judge is a model, so it needs its own test. Have people label a couple of hundred answers, then compare. Suppose humans mark twenty as unfaithful and the judge agrees on ninety percent overall. But a judge that always says faithful also scores ninety percent. Look at the failures instead: it caught fourteen of twenty, seventy percent. Tighten the rubric until it catches most of them, and re-check whenever you change the judge.

Judge vs 200 human labels
humans: 180 faithful, 20 not
judge agrees overall:  90%

but a judge that always says
"faithful" also scores 90%

look at the failures:
  caught 14 of 20 unfaithful = 70%

fix the rubric, re-check, then
trust it; re-check every quarter

Component vs end to end

There are two levels of evaluation. Component evals test one part at a time. Retrieval alone is scored on ids, needs no model, and runs in seconds. Generation can be tested on fixed, known good chunks, so retrieval noise is removed. End to end evals run the real pipeline and catch interactions. Longer chunks might raise recall but bury the answer in the middle of the prompt. Run component evals on every change, end to end before release.

Two kinds of eval
  • component: retrieval alone, scored on ids: fast, cheap, no LLM generation on FIXED chunks
  • end to end: real retrieval + real answer catches interactions, e.g. longer chunks raise recall but bury the answer
  • run both; they disagree usefully

Diagnosing failures

When an answer is wrong, sort it into one of three buckets. One, not retrieved: the gold passage never reached the prompt. Fix chunking, add hybrid search or rewrite the query. Two, retrieved but ignored: the passage was there, yet the answer is wrong. Send fewer chunks, put the best one first, or tighten the prompt. Three, answered beyond the sources: the model added claims the chunks do not hold. Require citations and make saying not found acceptable.

Three failure buckets
  • 1 not retrieved: gold passage not in top k → chunking, hybrid search, query rewrite
  • 2 retrieved but ignored: gold in the prompt, answer wrong → fewer chunks, order, prompt
  • 3 beyond the sources: claims not in the chunks → require citations, allow "not found"

Regression gates

Any change to the chunker, the embedding model or the prompt reruns the test set in CI. Set clear thresholds: block the merge if recall at five drops more than three points, or faithfulness falls below zero point nine. Print the queries that flipped from pass to fail; that list teaches more than the average. Gate a new embedding model before you re-embed the whole corpus.

A gate in CI
triggers: new chunker, new
  embedding model, prompt edit

block if:
  recall@5 drops > 3 pts
  faithfulness < 0.90
  "not found" on answerable
    questions rises > 2 pts

also: list the queries that
flipped from pass to fail

Online signals

Offline sets go stale, so watch live traffic too. Thumbs up and down are useful but sparse, and angry users click more. A follow up that rephrases the same question within a minute usually means the first answer missed. Track the no answer rate. Too high means gaps in your documents or retrieval. Near zero may mean the model is guessing. Watch escalations to humans too. Then review the bad cases and add them to the test set.

Signals from users
  • thumbs up / down: sparse, biased toward angry users
  • quick rephrase of the same question: likely a miss
  • no-answer rate: too high = coverage gap; near zero = maybe guessing
  • citation clicks, escalations
  • feed bad cases into the set

Numbers worth knowing

Numbers worth knowing. Start with fifty to a hundred questions and grow toward several hundred or a thousand. Hand label a hundred to three hundred answers to check your judge. Aim for roughly eighty five to ninety percent agreement, with most failures caught. On two hundred questions, a swing of three to five points can be pure noise, so do not celebrate a one point gain. And only a few percent of users ever click a thumb.

Ballparks
test set to start      ~50 - 100 Qs
test set mature        ~200 - 1,000
human labels for judge ~100 - 300
judge agreement aim    ~85 - 90 %+
noise on 200 Qs        ± ~3-5 pts
retrieval-only eval    seconds
end-to-end + judge     minutes
users who click thumbs ~1 - 5 %

Common mistakes

The common mistakes. One end to end score only. Labelling gold by chunk id, so the first rechunk breaks the whole set. Using only synthetic questions. Trusting a one to ten judge that nobody checked against people, or letting the same model write and grade answers without spot checks. Leaving out unanswerable questions, so guessing never gets punished. And tuning on the same set over and over until it is memorised. Keep a held out set.

Common mistakes
  • only an end-to-end score
  • labels tied to chunk ids, so a rechunk breaks the set
  • synthetic questions only
  • a 1-10 judge nobody checked
  • same model writes and judges without human spot checks
  • no unanswerable questions
  • tuning on the test set until it stops meaning anything

Say it like this

How to say it. We have three hundred real questions, each with gold passages. Retrieval is scored with recall at five and M R R, no model needed. Answers are scored for faithfulness and relevance by a judge with narrow yes or no rubrics, checked against a hundred and fifty human labels. CI blocks any change that drops a metric by more than three points. In production, rephrase and no answer rates feed new cases back into the set.

In the interview
  • "300 real questions with gold passages. Retrieval: recall@5 and MRR, no LLM needed. Answers: faithfulness and relevance by a judge, checked on 150 human labels. CI blocks a drop over 3 points. Live: rephrase and no-answer rates feed new cases back."

Interview questions

Q1Why evaluate retrieval and generation separately in a RAG system?

They fail for different reasons and have different fixes. Retrieval metrics on labelled passage ids tell you whether the answer ever reached the prompt; generation metrics on fixed chunks tell you whether the model used it well. One end-to-end score cannot say which half broke.

Q2Define recall at k, precision at k and MRR.

Recall at k is the share of gold passages found in the top k. Precision at k is the share of the top k that are gold. MRR is the mean over queries of one divided by the rank of the first gold result, counting zero when none is found.

Q3Which retrieval metric matters most for RAG, and why?

Recall at the k you send to the model, because a passage that is not retrieved can never be used. Also track recall before a reranker, and use precision or MRR to manage noise, cost and ordering.

Q4What is faithfulness and how do you measure it?

Faithfulness is whether every claim in the answer is supported by the retrieved text. Split the answer into claims, ask a judge whether each is supported by the context, and report the supported share, for example 3 of 4 claims is 0.75.

Q5How do you make a model-as-judge trustworthy?

Use narrow, binary rubrics with one criterion per call, ask for quoted evidence and run at temperature zero. Then compare it with a few hundred human labels, looking at how many real failures it catches, not only overall agreement.

Q6What are the risks of synthetic test questions?

They tend to copy the passage wording, which inflates retrieval scores, and they rarely include vague, multi-hop or unanswerable questions that real users ask. Paraphrase them, review a sample by hand and mix in real questions.

Q7How do you diagnose a wrong RAG answer?

Check whether the gold passage was retrieved. If not, it is a retrieval problem. If it was in the prompt but the answer is wrong, the model ignored it, so reduce or reorder chunks or fix the prompt. If the answer has claims not in the chunks, it went beyond the sources.

Q8How do you stop a chunking or embedding change from making things worse?

Rerun a fixed test set in CI on every such change and block it when recall, faithfulness or the false no-answer rate moves past a threshold. Label gold passages by document and position so the set survives rechunking, and list the queries that flipped.

Q9What online signals tell you a RAG system is failing?

Thumbs-down votes, quick rephrasings of the same question, the no-answer rate (too high means coverage gaps, near zero may mean guessing), escalations to humans and citation clicks. Sample bad cases into the offline test set.