Skip to content

Courses / RAG Systems / Module 8

Module 8: Retrieval and answer evaluation: golden sets, judge calibration, evals in CI

12 h · theory 4 · hands-on 5 · project 2 · revision 1

You will be able to

  • Separate retrieval metrics from answer metrics
  • Measure faithfulness and answer relevance
  • Calibrate an LLM judge against human labels
  • Block regressions in CI

Capstone increment: Eval suite (Ragas + ranx + pytest) on every pull request, with scores posted to the PR.

Job-description skills: RAG evaluation · Lab tools: ragas, ranx, pytest

1. Two systems, two sets of metrics

A RAG answer can fail in four places: the fact isn’t in the index, it is there but wasn’t retrieved, it was retrieved but the model ignored it, or the model added claims the context doesn’t support. Retrieval metrics tell you about the first two; answer metrics tell you about the last two. One blended “quality score” tells you nothing about which to fix.

Build the layers in order: retrieval metrics on a golden set first (cheap and deterministic), then answer metrics scored by a calibrated judge, then end-to-end checks on questions the documents can’t answer.

Golden setQ, relevant chunks, ARetrievalrecall@k, MRR, nDCGFaithfulnessclaims in context?Relevanceanswers the question?Not-found setrefuses correctly?Judgecalibrated vs humansCI jobpytest + ranx + RagasPR commentscores vs mainBlock mergebelow thresholdMeasure each stage separately…and gate every changescored by
A bad answer is either a retrieval failure or a generation failure. Separate metrics tell you which one to fix.

2. A golden set that grows

Each golden-set row holds a question, the chunks or documents that answer it, a reference answer and tags: question type, language, source document family, difficulty. Fifty well-chosen questions beat five hundred generated ones nobody checked. Generate candidates with an LLM if you like, but have a person verify each.

Grow it from production: every failure a user reports and every “thumbs down” you confirm becomes a new row. Version the set with the corpus version it was built against; when documents change, some answers do too.

In production: Report every metric per segment. An average can rise while one language, document family or question type collapses.

3. Answer metrics: faithfulness, relevance, correctness

Faithfulness asks whether every claim in the answer is supported by the retrieved context; Ragas splits the answer into claims and asks a judge model about each. Answer relevance asks whether the answer addresses the question. Answer correctness compares against the reference answer. Citation precision (Module 9) asks whether each cited chunk supports the sentence that cites it.

These need an LLM judge, and judges have biases: they prefer longer answers, the first option shown, and text in their own style. Treat their scores as measurements that need calibration, not as ground truth.

Common misconception: “Ragas says 0.87 faithfulness, so we’re 87% accurate.” That number is only as good as the judge behind it, and only on the questions you tested. Calibrate it against people first.

Deep dive

Deep dive: scoring faithfulness claim by claim

Faithfulness asks whether every claim in the answer is supported by the retrieved context, not whether the answer is true in the world. RAGAS-style faithfulness splits the answer into atomic claims with an LLM, asks a judge whether each claim can be inferred from the context, and reports supported claims ÷ total claims.

Context recall goes the other way: split the reference answer into claims and check how many of them the retrieved context supports. Low faithfulness with high context recall means the generator added things; low context recall means retrieval never found the facts, and no prompt change will fix that.

Worked example: “How long do I have to return a laptop?”

context: “Laptops can be returned within 14 days of delivery. Opened software is not refundable.”
answer:  “You have 14 days from delivery. Refunds reach your card in 5–7 days.”
claim 1  the return window is 14 days            supported
claim 2  the 14 days count from delivery         supported
claim 3  refunds reach the card in 5–7 days      not in the context
faithfulness = 2 / 3 = 0.67  (claim 3 may be true, but the system can’t show it)
Common misconception: A faithfulness score of 1.0 doesn’t mean the answer is right. A faithful answer built from an outdated document is still wrong; that is what answer correctness against a reference is for.

4. Calibrate the judge against people

Label 50 to 100 answers yourself as pass or fail with written criteria. Run the judge on the same answers and measure agreement with Cohen’s kappa, which corrects for agreement by chance. Specific binary criteria (“every number in the answer appears in the context”) agree with people far better than a vague 1-to-10 scale.

Use the tool below to see how a vague rubric and a specific rubric compare against human labels, and why “it passes everything” can look accurate while being useless.

Calibrate an LLM judge against human labels20 answers, each labelled pass or fail by a person. The judge scores 1–10; you choose its rubric and pass mark.
Human: passHuman: fail
Judge: pass86 bad answers passed
Judge: fail3 good answers failed3

Agreement 55% · Cohen’s κ 0.06 · catches 33% of the failures (κ corrects for agreement by chance: below 0.4 is weak, above 0.7 is good)

  1. #1 Correct refund steps, cites policy · human pass · judge 9/10 → pass
  2. #2 Confident, but invents a 60-day window · human fail · judge 8/10 → pass ✗
  3. #3 Correct, a little long · human pass · judge 7/10 → pass
  4. #4 Answers a different question · human fail · judge 7/10 → pass ✗
  5. #5 Correct, terse · human pass · judge 6/10 → fail ✗
  6. #6 Correct with the right form · human pass · judge 9/10 → pass
  7. #7 Polite, fluent, wrong amount · human fail · judge 9/10 → pass ✗
  8. #8 Correct, asks a useful follow-up · human pass · judge 8/10 → pass
  9. #9 Refuses a valid request · human fail · judge 5/10 → fail
  10. #10 Correct, says when it can’t know · human pass · judge 7/10 → pass
  11. #11 Leaks another customer’s order id · human fail · judge 8/10 → pass ✗
  12. #12 Correct · human pass · judge 9/10 → pass
  13. #13 Correct but clumsy wording · human pass · judge 5/10 → fail ✗
  14. #14 Missing the deadline the user asked for · human fail · judge 6/10 → fail
  15. #15 Correct, cites two sources · human pass · judge 8/10 → pass
  16. #16 Right answer, wrong currency · human fail · judge 9/10 → pass ✗
  17. #17 Correct, informal tone · human pass · judge 6/10 → fail ✗
  18. #18 Empty answer after a tool error · human fail · judge 4/10 → fail
  19. #19 Correct · human pass · judge 8/10 → pass
  20. #20 Hallucinated tracking link · human fail · judge 7/10 → pass ✗
Guided experiments
  1. With rubric v1, try every pass mark from 5 to 9. What is the best κ you can get? Which kinds of bad answer does v1 keep passing?
  2. Switch to rubric v2. Find the pass mark with the best κ. What changed in the rubric that made the judge useful?
  3. Agreement can look fine while κ is low. Set v1 with pass mark 1 (everything passes). What is the agreement, and why is κ zero?
  4. You have budget to label 50 more answers by hand. Which answers would you pick to label, and why?

5. Evals in CI

Run retrieval metrics on every pull request: they are deterministic, take seconds with ranx and cost nothing. Run the LLM-judged answer metrics on a fixed sample on every pull request with cached judgements for unchanged answers, and on the full set nightly. Post the scores and the difference from main as a PR comment, and block the merge if a metric drops below its threshold.

Small golden sets are noisy: a 60-question set can swing several points from random changes. Use a confidence interval on the difference (bootstrap is simple) so the gate fails on real regressions, not noise.

Tip: Pin the judge model version and prompt. A judge upgrade changes every score; run old and new judges side by side before switching.

Hands-on: coding window

The coding window and the full VS Code lab are available after you sign in.

Sign in to code

Labs

Lab 8.1: Grow the golden set

Extend the capstone golden set to 60 questions with tags for type, language and document family, including 10 unanswerable questions. Have a second person check 20 of them.

Expected: golden/v2.jsonl with tags and a short note on disagreements found.

Lab 8.2: Calibrate a judge

Score 40 capstone answers for faithfulness with Ragas, label the same 40 yourself, and compute Cohen’s kappa. Rewrite the judge criteria once and re-measure.

Expected: Kappa before and after the rewrite, with the criteria you settled on.

Lab 8.3: Evals in CI (capstone increment)

Add a CI job that runs retrieval metrics with ranx on every PR, runs Ragas on a 20-question sample with cached judgements, posts scores versus main as a comment and fails below thresholds.

Expected: A PR that lowers recall shows a failing check with the numbers in a comment.

Go deeper

Videos

Further reading

GitHub repositories

  • vibrantlabsai/ragas: The faithfulness and context precision metric implementations; read how claims are extracted and judged.
  • AmenRa/ranx: Run and Qrels objects, compare() with statistical tests: the retrieval half of your CI gate.
  • confident-ai/deepeval: pytest-style LLM test cases and its RAG metrics, an alternative to Ragas in CI.
  • promptfoo/promptfoo: Declarative eval configs and assertions, with a GitHub Action that comments on PRs.

Checkpoint quiz

1. The right chunk was retrieved but the answer is wrong. Which metric family points at this?
2. Best source of new golden-set rows after launch?
3. Why calibrate an LLM judge?
4. A judge passes every answer and agrees with humans 75% of the time. Kappa is about…
5. Your 60-question gate shows a 2-point drop. What should CI do?

Interview questions

  1. How do you evaluate a RAG system before you have users? After launch?
  2. Explain faithfulness. How is it computed, and how can it mislead you?
  3. How do you know your LLM judge is trustworthy?
  4. Design an eval gate for pull requests that is fast, cheap and not flaky.
  5. Your offline metrics improved but user satisfaction dropped. What could explain it?

Ask the professor

Sign in to ask questions about this module.

Discussion

Community discussion appears here once giscus is configured (see README).