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.
- 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.
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.
- 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.
- 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.
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.
- 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.
- 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.
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.
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.
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.
- 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.
- 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.
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.
- 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.
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.
- 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.
- "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."