GOAT EngineerPreparing your learning space…

AI Engineering · Concept Library · Free article

RAG Evaluation

You evaluate a RAG system in two halves, because it fails in two places. Score retrieval on whether the passage that answers the question came back at all, using recall@k and MRR against labelled tickets. Score generation on whether the reply is supported by that passage, using faithfulness, and on whether it addresses the question, using answer relevance. Keeping them apart is what makes a failure localisable, and it is what a single blended score destroys.

A RAG system has two places to fail, retrieval (the wrong passages came back) and generation (the model ignored the right ones), so you measure them separately, which makes any bad answer localizable. Retrieval is scored with classic ranking metrics (recall@k, precision@k, MRR, nDCG) against a labeled set. Generation is scored by an LLM judge for faithfulness (does every claim follow from the retrieved text?) and answer relevance (does it address the question?), two numbers that can each be perfect while the other fails. You run all of this on a golden set of question and answer pairs, treated as a regression suite you re-run on every change, and you close the loop with production signals, because a frozen test set goes stale the moment your users move.

The rag page left you with a working support bot. Wrenlet's help center is chunked, embedded, indexed; a customer asks “you charged me twice, how do I get it back?” and the bot retrieves the refund passages and answers from them. It worked in the three questions you tried before shipping. That is exactly the trap.

A month in, you notice the chunker is tearing some answers in half, so you change the chunk size. On the two questions you re-test, the answers look better. You ship it. Two weeks later, support escalations are up and nobody can say why. Did your change help or hurt? You genuinely don't know, because “looked better on two questions” was never a measurement. It was a vibe.

First rule: measure the two halves separately

A RAG answer travels through two stages, and it can break in either. Retrieval goes first: embed the question, pull the top passages from the index. If the passage that answers the question never comes back, nothing downstream can save you. Generation goes second: hand those passages to the model and have it write the answer. Even with the right passage in hand, the model can ignore it, misread it, or pad the answer with things it made up.

The single most useful habit in RAG evaluation is to score these two stages with separate metrics, never one blended “is the answer good?” score. Why? Because a blended score tells you that something is wrong but not where. Split it, and a bad answer localizes itself: if retrieval recall is low, the fix is upstream (chunking, the embedding model, k, reranking); if retrieval recall is high but the answer is still wrong, the fix is downstream (the grounding prompt, the model). One number that names the guilty stage saves you days of guessing.

Scoring retrieval: did the answer even come back?

Start with a labeled query: a real question plus the passages a human marked as actually answering it, the gold set for that query. Now run your retriever and compare its ranked list against those gold labels. Four numbers fall out, each answering a slightly different question, and they routinely disagree about whether the retrieval was any good.

The four numbers, and what each one asks

  • recall@k. Of all the truly relevant passages, what fraction landed in your top k? relevant-in-top-k / total-relevant. This is the one that matters most in RAG: a passage the retriever never surfaces is a passage the model can never use.
  • precision@k. Of the k passages you kept, what fraction were actually relevant? relevant-in-top-k / k. High precision means little noise for the model to read past.
  • hit@k. Did at least one relevant passage make the top k? A coarse yes or no, useful when the model only needs one good source to answer. Note how it differs from recall: hit@k is a fact about the query, recall@k is a fraction of the passages inside it.
  • MRR (mean reciprocal rank). For a single query the reciprocal rank is 1 / (rank of the first relevant passage); MRR is that averaged over your query set. It cares only where the earliest good passage lands: first place scores 1.0, tenth place scores 0.1.

Drag k below and feel the tension. Widen the cut and recall climbs toward 1.0, while the precision trend falls, from 0.50 at k=2 down to 0.30 at k=10. Precision does not fall smoothly, though: it jumps up on every step that lands a gold passage and decays on every step between them, so at k=9 it is higher than at k=8 even as noise piles up. Reciprocal rank moves exactly once, when the first gold passage crosses the cut, and then holds flat however far you widen.

The interactive version of this example is available when JavaScript loads.

Those four treat every relevant passage as equally relevant. Often it isn't: one passage nails the answer, another is merely on-topic. nDCG (normalized discounted cumulative gain) is the metric that handles graded relevance and rewards putting the best passage highest. In the form everyone uses today it sums each passage's relevance discounted by how far down it sits, DCG@k = Σ relevanceⱼ / log₂(j+1), then divides by the score of the perfect ordering (the IDCG) so it lands between 0 and 1. A 1.0 means your ranking matched the ideal one. The measure is Järvelin and Kekäläinen's, 2002, although they write the discount as log_b(i) applied from rank b downward and note explicitly that a logarithmic discount cannot apply at rank 1; the log₂(j+1) shift that sidesteps that is the later machine-learning convention. It is the retrieval metric that most closely tracks what a reranker is for.

Scoring generation: did the model answer from them?

Now assume retrieval did its job: the right passages are in front of the model. The answer can still go wrong in two independent ways, and each has its own metric. Both are computed by a judge model reading the answer, so neither needs a hand-written gold answer to compare against.

Faithfulness (also called groundedness) asks: does every statement in the answer actually follow from the retrieved passages? The judge does it in two passes. First it breaks the answer into individual claims, then it checks each claim against the context and counts how many are supported. The score is simply supported-claims / total-claims. An answer with three claims where one was invented scores 0.67. This claim-decompose-then-verify recipe is the one popularized by RAGAS (Es et al., 2023).

Answer relevance asks a different question: does the answer actually address what was asked, or is it grounded but off-topic? A neat trick measures it without a gold answer: prompt the judge to generate a handful of questions from the answer, embed them, and see how close they sit to the original question. An answer that squarely addresses the question regenerates near-identical questions (high similarity); an evasive one regenerates questions about something else (low). Toggle the three candidate answers below and watch the two meters come apart. The evasive one is the clean demonstration: faithfulness a flat 1.0, relevance collapsing to a third of that, from the same context on the same question.

The interactive version of this example is available when JavaScript loads.

Correctness needs that gold answer, which is why it's the expensive one to build. When you have it, a modern correctness score blends two things: how much the answer's facts overlap the gold answer's facts, and how semantically close the two are overall. Which brings up the metrics people used to reach for and shouldn't, here.

Which RAG evaluation tool should you use?

You rarely hand-roll these metrics. Several libraries ship them, and the split that matters is dev-time (score a change before you ship it, in CI) versus production monitoring (score live traffic after). Mature teams usually run one of each, because no single tool is great at both. The table below is a snapshot as of September 2026: this part of the ecosystem moves faster than the metrics do, so check the current docs before you pick one.

A representative slice of the RAG-eval landscape
ToolWhere it fitsWhat it’s known for
RAGASDev-time, RAG-specialistFaithfulness and answer relevance, which need no reference, plus context precision and context recall, where recall always does need one. An LLM judge under the hood. The 2023 paper defines three metrics; the context ones arrived later, from the library.
TruLensDev-time / tracingThe “RAG triad” of context relevance, groundedness and answer relevance, where each failing leg names the guilty stage.
DeepEvalDev-time, CI-nativeEvals written as pytest tests, so a regression blocks the deploy like any failing unit test.
Arize PhoenixProduction monitoringOpenTelemetry-native tracing plus built-in evals; score live traces in the same tool you debug them in.
LangSmith / BraintrustBoth, platformDataset management, scoring, and prod monitoring in one place, the path of least resistance if you want the whole lifecycle hosted.

How do you build a golden set for RAG?

Every metric so far needs something to score against. That something is the golden set: a fixed batch of held-out rows, each a real question paired with its ground-truth answer and the passages that should be retrieved for it. It is the single most important artifact in your eval, the ruler you measure every change against.

Building one that earns its trust

  • Curate the core by hand. A few hundred rows written or vetted by someone who knows the domain is a strong foundation, and quality beats volume. For a support bot, mine your real ticket history for the questions that actually get asked.
  • Grow it synthetically, carefully. You can prompt an LLM to generate questions from each chunk to bulk it out fast, but synthetic questions lack the messiness of real ones and inherit the generator's blind spots, so promote them to “gold” only after a human vets them.
  • Label the passages by pooling. You are not going to read the corpus. Judge the union of the top N from two or three different retrievers, treat the rest as irrelevant, and write down that this is what your recall denominator means.
  • Watch for contamination. If the same model family that generated your test questions also serves the answers, or your test passages leaked into a fine-tune, your scores are inflated. Keep the set genuinely held out.
  • Re-run it on every change. Chunk size, embedding model, k, reranker, prompt: every one of those is a change you gate through the golden set, comparing the new score against the last. This is the whole point. The set is a regression suite.

And here is why one example is never enough. You tweak the prompt, eyeball the one question you always demo, and it looks worse, so your gut says don't ship. Run the whole set and the truth appears: that question regressed and so did one other, but six improved and the average went up. Six wins against two losses is a shape an anecdote cannot see, and the row you happened to demo was one of the two.

The interactive version of this example is available when JavaScript loads.

Count the red markers in that table rather than taking the sentence under it on trust. Two rows got worse and six got better, and the mean moved from 0.74 to 0.83. The row you would have demoed is one of the two that regressed, so the anecdote and the set do not merely differ in confidence here, they point in opposite directions. That is the entire argument for a fixed set, and it is why the set has to be fixed: a golden set you quietly edit when it disagrees with you is a mirror.

Offline gates, online tells the truth

The golden set is offline evaluation: fast, deterministic, runs in CI, gates a change before it ships. Its blind spot is total, because it can only score questions it contains. The moment your product ships a feature or your users start asking something new, the frozen set goes stale and its clean green score is quietly lying to you.

That gap is filled by online evaluation, measuring on live traffic after you ship: thumbs-up and thumbs-down, escalation rates, an LLM judge sampling real answers (the reference-free faithfulness and relevance metrics shine here, since production has no gold answers), and drift monitors watching the question mix change. Online sees the real distribution but can't gate a change before it's live. So you wire the two into a loop: gate offline, watch online, and harvest what breaks in production back into the golden set. Production failures become tomorrow's test cases, which is the flywheel that keeps offline honest. Watch what happens to the gate itself once the failing rows are in it.

The interactive version of this example is available when JavaScript loads.

Notice which direction the gate moves when the loop closes. Before the harvest it reads a comfortable pass, because the questions it was asked were the questions it could answer. Harvest the cluster that was failing in production, and the same gate on the same system turns red. Nothing about the product changed in that moment. What changed is that the instrument stopped being blind to a failure its users had been living with, and a red gate that was green yesterday is the loop working rather than a regression.

The judge grading your work has its own biases

Faithfulness, answer relevance, and the online spot-checks all lean on an LLM acting as a judge, and a judge is a model, with a model's quirks. The documented ones: it tends to prefer the answer shown first (position bias), the longer answer (verbosity bias), and answers from its own model family (self-preference). Take its scores as gospel and you'll optimize for the judge's taste instead of your users'.

What does RAG evaluation cost to run?

LLM-graded metrics aren't free. Each one is one or more model calls per test row: faithfulness is a claim-extraction call plus a verification call per claim, answer relevance generates several questions then embeds them, correctness classifies claims against the gold answer. Multiply that by a few hundred golden rows and several metrics and re-run it on every change, and eval becomes a real recurring bill, sometimes larger than serving. The practical moves: cache judge results so an unchanged row isn't re-scored, use a cheaper judge model for the cheap metrics, sample the set on every commit and run the full set only at release gates, and reserve the most expensive metrics (correctness against gold) for the changes that warrant them.

The eval loop in code

Stripped to essentials, an eval harness is five moves: hold the set as data, score retrieval with arithmetic, score generation with a judge, gate on the aggregate, feed production back. Here it is with RAGAS, which packages the judge-scored half; the retrieval half you write yourself, because it is two lines and no library should own your definition of a hit.

The whole flow, step by step

  • Hold the golden set as data. Each row is a plain dict in the shape RAGAS reads: {"user_input": question, "retrieved_contexts": [c.text for c in chunks], "response": answer, "reference": gold_answer}. Keep the file in the repo and treat it like a fixture, because a ruler that lives on somebody's laptop is not a ruler.
  • Score retrieval per row, with no LLM at all. recall = len(set(retrieved_ids) & set(relevant_ids)) / len(relevant_ids), and nDCG is sum(rel[j] / math.log2(j + 2) for j in range(k)) divided by the same sum over the ideal ordering. Exact, cheap, run on every row on every commit.
  • Score generation per row with a judge. from ragas import evaluate, EvaluationDataset and from ragas.metrics import Faithfulness, ResponseRelevancy, LLMContextRecall, then result = evaluate(dataset=EvaluationDataset.from_list(rows), metrics=[Faithfulness(), ResponseRelevancy(), LLMContextRecall()], llm=evaluator_llm). Note which is which: the first two read only response and retrieved_contexts, while LLMContextRecall reads reference, so drop it from any run where you have no gold answers.
  • Aggregate and gate. Average each metric, then fail the build on a real drop rather than a wobble: assert mean_recall >= last_run - noise_band, with noise_band measured rather than guessed (the next section does that). If you would rather the gate live in your test suite, DeepEval writes the same thing as a pytest file: assert_test(test_case, [AnswerRelevancyMetric(threshold=0.7)]) fails CI like any other assertion.
  • Feed production back. Harvest thumbs-down and judge-flagged live answers into new rows, so the ruler grows with the product instead of going stale.

How wide is the number?

The gate in step four compares two averages, and two averages over a few hundred noisy rows differ even when nothing changed. The noise band is how far they drift by chance alone. Until you have measured it, you cannot tell a two-point improvement from a quiet afternoon, and every gate you build is theatre.

Measuring the band, and sizing the set

  • Work with per-row deltas, not two averages. For each golden row record candidate_score - baseline_score. Scoring the same row twice is a paired comparison, which cancels out the fact that some questions are simply harder than others and shrinks the noise you have to beat.
  • Bootstrap the deltas. Resample your N deltas with replacement a few thousand times, take the mean of each resample, and read the 2.5th and 97.5th percentiles. That interval is the band. It is about ten lines of numpy and it makes no assumption about the score distribution, which matters because judge scores are lumpy.
  • Gate on the interval, not the mean. Ship when the whole interval sits above zero. A mean delta of +0.02 with an interval of [-0.03, +0.07] is a coin flip wearing a decimal point, and shipping on it teaches the team that the gate means nothing.
  • Size the set from the resolution you need. The half-width is roughly 1.96 × s / √n, where s is the standard deviation of the per-row deltas. Prompt changes graded on a 0-to-1 scale typically give an s around 0.15, so fifty rows buys you 1.96 × 0.15 / √50, about ±0.04. That is twice the size of the 0.81 to 0.83 move you were about to celebrate, which is exactly why it is noise. Resolving two points needs n ≈ (1.96 × 0.15 / 0.02)², about 216 rows, which is where “a few hundred” keeps coming from.
  • Re-measure the band whenever the judge changes. It is a property of this set scored by this judge with this prompt, not a constant you write down once.

Where RAG evaluation bites

The ones that actually bite

  • Eyeballing a handful of answers. Two questions looking better is not a measurement. A real gain can be vetoed by one unlucky example and a real regression can hide behind a lucky one. Score the set, gate on the aggregate.
  • One blended score. “Answer quality: 0.7” tells you something's wrong, not where. Split retrieval from generation so every failure names its stage, and keep the two axes on separate dashboards.
  • Tuning generation while retrieval leaks. If recall@k is low, most of the evidence isn't in front of the model at all. Fix and measure retrieval first, because generation is capped by it.
  • Reading recall@k as a share of questions. It is a share of relevant passages, averaged over queries. The fraction of questions left with nothing relevant is 1 - hit@k, and quoting one when you mean the other is how a team convinces itself retrieval is twice as broken, or twice as healthy, as it is.
  • Trusting the judge blind. Position, verbosity, and self-preference bias are real, and a judge you never validated optimizes for its own taste. Measure agreement with kappa, then pin the judge version and prompt so your history stays comparable.
  • A frozen golden set. It can only score questions it holds, so as the product and the users move, its green score quietly lies. Feed production failures back in.
  • Reading too much into a small delta. A move from 0.81 to 0.83 on fifty rows sits inside the noise band, as the arithmetic above shows. Measure the band before you celebrate a change, and re-measure it when the judge changes.

Interview cheat-sheet: intern to principal

How do you evaluate a RAG system?
Score the two stages separately. Retrieval: run a labeled query set and measure recall@k, precision@k, and nDCG against the passages a human marked relevant. Generation: use an LLM judge to score faithfulness (are the answer's claims supported by the retrieved context?) and answer relevance (does it address the question?). Run all of it on a golden set of question and answer pairs you re-run on every change, and back it with production signals. The key move is separating the halves so a bad answer localizes to retrieval or generation.
Why measure retrieval and generation separately instead of one end-to-end score?
Because one blended number tells you the answer is bad but not why. Split them and the fault localizes: low retrieval recall means the fix is upstream (chunking, embedding model, k, reranking); high recall but a wrong answer means the fix is downstream (the grounding prompt, the model). It turns a day of guessing into a glance.
What is faithfulness, and how is it computed?
Faithfulness (or groundedness) is the fraction of the answer's claims that are actually supported by the retrieved context, supported-claims over total-claims. An LLM judge computes it in two passes: decompose the answer into individual claims, then verify each against the context. It needs no gold answer, which is why it is the workhorse for scoring live production traffic too. Watch the edge case: a refusal has no claims, so the ratio is 0 over 0 and your harness has to be told what that means.
Can an answer be faithful but still bad?
Yes, in two ways. It can be faithful but off-topic, with every claim grounded in the retrieved text while answering a different question than the one asked; relevance catches that. And it can be faithful and relevant and still wrong, if the passage it faithfully repeated was itself outdated, because grounded is not the same as true. Faithfulness and relevance never look at ground truth, so only correctness, scored against a gold answer, catches a confidently-repeated falsehood.
Why not just use BLEU or ROUGE like older NLP?
They score n-gram overlap with a reference, which was fine for translation and summarization but fails grounded QA: a correct answer phrased differently scores near zero, and a wrong answer that reuses the reference's words scores high. They miss semantic equivalence and, more importantly, they don't measure grounding in the retrieved passages at all. Claim-level faithfulness plus an LLM judge are what fit RAG.
What's the recall ceiling, and why does it change your priorities?
Generation quality is capped by retrieval recall, because a model can't answer from a passage that was never retrieved. If recall@k is 0.6, then on average 40% of the relevant passages are missing from the context no matter how good the prompt or the model is. Say it carefully, because this is where people slip: recall@k counts passages within a query, so it is not the share of questions that got nothing at all. That number is 1 - hit@k, and the two only coincide when every question has exactly one relevant passage. Either way the priority is the same, measure and fix retrieval before tuning generation.
You made an LLM judge score your answers. How do you know the judge is any good?
You validate it against human labels: have people grade a sample, and measure agreement with Cohen's kappa rather than raw accuracy, which flatters a rubber stamp when one label dominates. Judges have known biases, favouring the first-shown answer, longer answers, and their own model family, so you also swap positions and average, grade against a reference, and compare pairwise. Then you pin the judge model and the grading prompt, because an upgrade re-baselines every historical score and your regression gate starts comparing two rulers. The famous result is that a strong model can reach human-level agreement as a judge, but the lesson is that it was measured, not assumed.
Offline eval passed but users are unhappy. What happened?
Offline eval can only score the questions in your golden set; the moment your product or your users move past it, it goes stale and its green score is blind to the new failures. The fix is to close the loop: keep the offline gate, add online monitoring (thumbs, escalations, a judge sampling live traffic, drift detection), and harvest the failing production queries back into the golden set so it tracks reality.
Your metric moved from 0.81 to 0.83. Do you ship?
Not on that number alone. Compute the per-row deltas, bootstrap them, and look at the interval: with a typical per-row spread around 0.15, fifty rows gives roughly ±0.04, so a two-point move sits inside the noise and the honest answer is that you cannot tell yet. Either gate on an interval that clears zero, or grow the set. Resolving two points reliably takes a couple of hundred rows, which is the real argument for the size everyone recommends.

By GOAT Engineer. Back to Concept Library. Privacy Policy · Contact.