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.
Without component-level evaluation, teams change the prompt when the retriever is the problem, or the other way round.
- 1. RAG evaluation separates…
- 2. Exact match can fail…
- 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.
- 1. Faithfulness asks whether…
- 2. Context recall asks whether…
- 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())- 1. A RAG evaluation framework:
- 2. A good starting test set size:
- 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.
- 1. Share of errors due to retrieval is…
- 2. A metric is valid when it…
- 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.
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
- P. Rajpurkar, J. Zhang, K. Lopyrev and P. Liang (2016). “SQuAD: 100,000+ questions for machine comprehension of text.” EMNLP.
- S. Es, J. James, L. Espinosa-Anke and S. Schockaert (2024). “RAGAS: automated evaluation of retrieval augmented generation.” EACL demos.
- J. Saad-Falcon, O. Khattab, C. Potts and M. Zaharia (2024). “ARES: an automated evaluation framework for retrieval-augmented generation systems.” NAACL.
- L. Zheng et al. (2023). “Judging LLM-as-a-judge with MT-Bench and Chatbot Arena.” NeurIPS.