Evaluate a RAG Pipeline: Retrieval Metrics, Faithfulness and a Regression Gate
Turn 'the RAG bot seems better' into numbers you can gate on: chunk a knowledge base with paragraph provenance, label a golden set, score retrieval with recall, precision, MRR and nDCG, sweep chunk sizes, judge answer faithfulness claim by claim with a model, grade correctness, triage every failure by where it happened, and block a candidate configuration that regresses a protected question.
Hands-on labs require Pro · $29.99/mo · cancel anytime
What you'll learn
- 1Chunk with provenance: every chunk knows which paragraphs it holdsNorthwind's support bot answers from a dozen help articles in kb/. The
- 2Recall@k and precision@k against paragraph labelsruns/retrieval-s500.jsonl is a recorded retrieval run: for every
- 3Rank matters: MRR and nDCGRecall@3 says whether the right paragraph is somewhere in the top three.
- 4Sweep the chunk size and read the trade-offFour metrics per question is a spreadsheet; what the team needs is one
- 5Faithfulness: split the answer into claims and let a judge verify each oneRetrieval metrics stop at the prompt. runs/baseline.jsonl continues:
- 6Correctness by rule, and a triage that names where each failure happenedA faithful answer can still be wrong, and a wrong answer can be wrong for
- 7Run the suite: one report per configurationEverything so far scores one question. The team decides per
- 8The regression gate: block the change that breaks a protected questionThe team's proposal is in runs/candidate.jsonl: 1000-character chunks
Prerequisites
- Python: functions, dicts, sets, json, list comprehensions
- How a RAG pipeline works: chunk, embed, retrieve, generate (the module's earlier labs)
- Read the module's two evaluation lectures first: recall and precision, then LLM-as-judge and failure modes
Exam domains covered
Skills & technologies you'll practice
This intermediate-level ai/ml lab gives you real-world reps across:
Why evaluate RAG in two halves
A RAG system fails in two places. The retriever can miss the passage that holds the answer, and the generator can ignore or embellish the passages it was given. A single end-to-end score hides which one happened, and teams fix the wrong half. This lab measures each half with the metric that fits it and then combines them into a triage that names the failure. Retrieval is scored against paragraph-level labels with recall, precision, mean reciprocal rank and nDCG at k, and a chunk-size sweep shows the recall-versus-context trade-off with real numbers. Generation is scored by decomposing each answer into claims and asking a judge model whether the passages support each one, then by a deterministic check of the facts the answer must contain. A suite report rolls it up per question, and a regression gate compares a candidate configuration to the baseline and blocks it when a gated metric drops or a protected question stops passing.