Foundations to Frontier
Tests
F. NLP and Large Language Models › F10 Retrieval-Augmented Generation

RAG evaluation

A RAG system can fail at retrieval, at reading, or at grounding its answer in what it retrieved, and a single accuracy number hides which. RAG evaluation measures the components separately: context recall and precision for retrieval; faithfulness and answer correctness for generation. Each metric can mislead: exact match penalises correct but differently worded answers, LLM judges have biases, and small test sets cannot separate close systems. This page covers the metrics, judges, test-set construction and statistics. In the exercises you write answer normalisation, token F1 and context recall, then evaluate three simulated systems with known true accuracy. Exact match ranked the truly best system (92%) far below a terser one (76%). A judge lenient to long answers ranked a 75% system above a 76% one. Splitting failures showed one system losing 83% of its errors at retrieval and another only 17%. With 60 questions the two close systems came out in the right order only 65% of the time.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Grading an open-book exam fairly

To grade an open-book exam you want to know two things: did the student find the right page, and did they read it correctly? A student who found nothing and guessed needs a better library; a student who found the page and still got it wrong needs to read more carefully. Grading also has to be fair: marking only answers that match the key word for word fails students who say the same thing differently. The demo shows how few test questions leave a wide margin of uncertainty.

Prompting lab
95% interval: 63.6% to 76.4%. Two prompts whose intervals overlap this much may not really differ.
Why engineers care

Without component-level evaluation, teams change the prompt when the retriever is the problem, or the other way round.

📝 Quick check (Level 0)
0/3 answered
  1. 1. RAG evaluation separates…
  2. 2. Exact match can fail…
  3. 3. A small test set gives…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Retrieval metrics: context recall (are the facts needed for the answer in the retrieved passages?), context precision (how much retrieved text is relevant), recall@k and MRR when relevance labels exist.
  • Generation metrics: faithfulness or groundedness (is every claim supported by the context?), answer relevance, answer correctness against a reference.
  • String metrics: exact match and token F1 after normalisation; cheap but brittle for free-form answers.
  • LLM-as-judge: a model grades correctness or faithfulness, often by splitting the answer into claims (RAGAS, ARES); validate against human labels and watch for biases (length, position, self-preference; F14-3).
  • Test sets: real user questions with reference answers and gold passages; synthetic questions generated from the documents; include unanswerable questions to test abstention.
  • Statistics: confidence intervals, paired comparisons on the same questions, enough questions to detect the gap you care about (F9-4).
  • Online: user feedback, citation click-through, escalation rate.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Faithfulness asks whether…
  2. 2. Context recall asks whether…
  3. 3. Unanswerable questions test…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Running a RAG evaluation

Exercise 1.

  • Normalise answers SQuAD-style.
  • Token F1.
  • Context recall of reference facts.

Practice.

  • Frameworks: RAGAS, TruLens, DeepEval, ARES; or a small custom harness (F14-5).
  • Start with 100–300 real questions; label gold passages and reference answers; add synthetic questions for coverage.
  • Report retrieval and generation metrics side by side, with confidence intervals.
  • Hand-check a sample of judge decisions per release; track judge agreement with humans.
  • Keep the test set fixed and versioned; never tune on it.
from ragas import evaluate
from ragas.metrics import faithfulness, answer_correctness, context_recall, context_precision
result = evaluate(dataset,        # question, answer, contexts, ground_truth
                  metrics=[context_recall, context_precision, faithfulness, answer_correctness])
print(result.to_pandas().describe())
🐍 Exercise 1: answer and context metrics
Write answer normalisation, token F1 and context recall.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A RAG evaluation framework:
  2. 2. A good starting test set size:
  3. 3. Judges should be…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Decomposition. Accuracy = R · a_hit + (1 − R) · a_miss, with R the recall of gold evidence. Of the wrong answers, the share caused by retrieval is (1 − R)(1 − a_miss) / (1 − accuracy). This tells where to invest: a system whose errors mostly occur with the evidence retrieved needs a better reader or prompt, not a better index.

Metric validity. An automatic metric is useful when it ranks systems as humans would. Exact match has low recall for free-form answers, with recall depending on answer style, so it can reorder systems. An LLM judge with a bias that correlates with a system property, such as length, shifts that system’s score and can reorder close systems.

Statistical power. The standard error of an accuracy p from n questions is √(p(1 − p)/n); at p = 0.75 and n = 60 the 95% interval is ±11 points. Separating systems a few points apart needs hundreds to thousands of questions, or a paired design.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Share of errors due to retrieval is…
  2. 2. A metric is valid when it…
  3. 3. 95% interval half-width at p = 0.75, n = 60:

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Do exact match and LLM judges rank RAG systems correctly, can component metrics locate failures, and how many questions are enough?

History.

  • P. Rajpurkar et al., SQuAD (2016): exact match and token F1.
  • S. Es et al., “RAGAS: automated evaluation of retrieval augmented generation” (2023); J. Saad-Falcon et al., “ARES” (2023).
  • L. Zheng et al., “Judging LLM-as-a-judge” (2023): position, verbosity and self-enhancement biases.

Exercise 2. Three simulated RAG systems, 1000 questions each, with per-question ground truth.

  • A (strong retriever): recall 0.95, reads correctly 78% given evidence, 20% of answers contain unsupported claims, verbose.
  • B (strong reader): recall 0.78, reads 96%, 5% unsupported, terse.
  • C (both improved): recall 0.95, reads 95%, 5% unsupported, verbose.
  • Exact match: counts a correct answer only if worded like the reference (45% of verbose, 85% of terse answers).
  • LLM judge: agrees with humans 90% of the time and also accepts 30% of wrong verbose answers.
system human-graded accuracy exact match LLM judge errors due to retrieval unsupported (true / flagged)
A 0.752 0.333 0.779 0.173 0.206 / 0.224
B 0.762 0.655 0.704 0.832 0.053 / 0.093
C 0.917 0.440 0.863 0.494 0.051 / 0.093
  • Exact match ranked B first and C, the best system, a distant second.
  • The judge ranked A above B, the reverse of the truth, because it is lenient to A’s long answers. It ranked C correctly first.
  • Component metrics located the problems: most of B’s errors happen at retrieval, most of A’s at reading, and the faithfulness check flagged A’s unsupported claims.
  • Sample size: with 60 questions per system, B beat A only 65% of the time over 2000 simulated test sets; with 1000, 97%.
  • Seeds 1 and 2: C human 0.910 and 0.906, C exact match 0.412 and 0.377. On seed 1 the judge tied A and B (0.752 vs 0.753) rather than reversing them.
  • Caveat: the metric biases are set by assumption, so this shows what such biases do, not how large they are for any real judge; measure that on your own data.
🐍 Exercise 2 (research): do exact match and LLM judges rank RAG systems correctly, can component metrics locate failures, and how many questions are enough?
Evaluate three simulated RAG systems with human grades, exact match, a biased LLM judge, component metrics and small test sets.

RAG evaluation in AI, robotics and aerospace

  • Safety-related documentation assistants: faithfulness and citation correctness matter more than fluency; unsupported claims are treated as failures.
  • Regression testing: a fixed, versioned question set re-run on every index or prompt change.
  • Expert review: engineers label a sample of answers each release to keep automatic judges honest.

References

  1. P. Rajpurkar, J. Zhang, K. Lopyrev and P. Liang (2016). “SQuAD: 100,000+ questions for machine comprehension of text.” EMNLP.
  2. S. Es, J. James, L. Espinosa-Anke and S. Schockaert (2024). “RAGAS: automated evaluation of retrieval augmented generation.” EACL demos.
  3. J. Saad-Falcon, O. Khattab, C. Potts and M. Zaharia (2024). “ARES: an automated evaluation framework for retrieval-augmented generation systems.” NAACL.
  4. L. Zheng et al. (2023). “Judging LLM-as-a-judge with MT-Bench and Chatbot Arena.” NeurIPS.