learn-ai-evals-with-phoebe / Builder session 4 of 10
Learn Evals with Phoebe · Builder track · Session 4 of 10

Generation metrics: grading the answer, not the search

Sessions b1 to b3 measured retrieval - did the right chunks come back. This one measures what the model does with them: the answer itself. You will meet the four workhorse generation metrics - faithfulness, response relevancy, noise sensitivity, and semantic similarity - see exactly what each one catches (and what it does not), and run faithfulness and relevancy over a sample of Recall's answers with RAGAS. By the end you can tell a hallucination apart from an off-topic answer apart from a merely differently-worded one, with a number for each.

🟡 Builder track Practitioners · some Python Medium · concept + code ~45 min
0-3 · Welcome 3-24 · Faithfulness + relevancy 24-40 · Noise + similarity 40-45 · Q&A
Part 0

Two answers, both retrieved perfectly, one still wrong

A retriever can hand the model the exact right chunk and the model can still blow it: it invents a detail the chunk never mentioned, or it wanders off and answers a slightly different question. Retrieval metrics are blind to both - the chunks were right. Generation metrics grade the sentence the user actually reads. Today we add four of them to Recall, our RAG assistant over corpora A, B, and C, and we are careful about the one trap that catches everyone: these metrics measure faithfulness and focus, not truth.

Live - presented in session Self-study - full depth after class ★ Try it now Sources covered at the end
★ What you build today A working feel for four generation metrics, a RAGAS run that scores Recall's answers on faithfulness and response relevancy, and the judgment to read a low score correctly - is it a hallucination, an off-topic answer, noise leaking in, or just different wording?
Part 1 · covers faithfulness + response relevancy

Faithfulness + relevancy 9 min live

Two metrics, two different questions about one answer. Faithfulness asks: is every claim in the answer actually backed by the retrieved context? Response relevancy asks: does the answer stay on the topic the user asked about? Neither one asks whether the answer is true - that is a separate metric (b7). Getting this distinction into your bones is most of today.

FAITHFULNESS · is every claim backed by context? Answer the model wrote claim 1 · supported claim 2 · supported claim 3 · unsupported Retrieved context Faithfulness 2 / 3 = 0.67 RESPONSE RELEVANCY · does the answer stay on topic? Answer the model wrote gen question 1 gen question 2 gen question 3 Original question Relevancy mean cosine Faithfulness reads the context; relevancy reads only the question. Neither one checks whether the answer is true.
🔍 Click to zoom - faithfulness decomposes the answer into claims and checks each against context; relevancy generates questions from the answer and compares them to the original
LiveFaithfulness: claims supported divided by total claims3 min

RAGAS computes faithfulness in two LLM passes. First it breaks the answer into individual factual claims. Then, for each claim, it asks: can this be inferred from the retrieved context? The score is simply the fraction that can.

  • The formula. Faithfulness = (claims supported by context) / (total claims). All three claims backed gives 1.0; the answer that adds one invented detail to two good ones scores 0.67.
  • It is a hallucination detector. A low score means the model said something the context did not support - the textbook definition of a RAG hallucination. This is the single most useful generation metric for a support bot.
  • No reference needed. Faithfulness compares the answer only to the context that was retrieved. You do not need a gold answer, which makes it cheap to run on live traffic.
  • It is not accuracy. An answer can be perfectly faithful to a context that is itself wrong or outdated. Faithful means "grounded in what we gave it", not "correct".
LiveResponse relevancy: N questions back from the answer3 min

Response relevancy (renamed from Answer Relevancy in RAGAS v0.2+) measures whether the answer actually addresses what was asked. The clever trick: it works backwards. An LLM reads the answer and writes N questions (default 3) that this answer would be a good reply to. Each generated question is embedded and compared by cosine similarity to the real question. The score is the mean.

  • The intuition. If the answer is on topic, the questions you can reconstruct from it look like the question that was asked. If the answer rambled, the reconstructed questions drift away and cosine similarity drops.
  • It catches off-topic, incomplete, and evasive answers. A response that dodges the question, over-answers, or trails into a tangent scores low even when every sentence is faithful.
  • It measures on-topic, NOT accuracy. A confidently wrong answer that stays squarely on the question can still score high on relevancy. Relevancy is about focus, not correctness.
  • No reference needed either. Like faithfulness, it uses only the answer and the original question, so it runs on production traffic.
Faithfulness and relevancy are a pair, not a ranking Faithfulness catches the answer that invents things; relevancy catches the answer that wanders. An answer can be faithful but irrelevant (grounded, but not what you asked) or relevant but unfaithful (on topic, but made up). You want both high. Read them together.
Self-studyScoring Recall's answers with RAGAS4 min read

In RAGAS you assemble a dataset of samples - each with the question, the model's answer, and the retrieved contexts - then hand a list of metrics to evaluate(). Faithfulness and ResponseRelevancy need no reference, so this runs on any sample of Recall's live answers.

Python · faithfulness + response relevancy over a samplefrom ragas import evaluate, EvaluationDataset from ragas.metrics import Faithfulness, ResponseRelevancy # one dict per answer we want to grade samples = [ { "user_input": "How do I get a refund after cancelling?", "response": "Cancel in Settings, then refunds post in 5 to 7 days. " "Refunds over $500 need manager approval.", # last claim invented "retrieved_contexts": [ "To cancel, open Settings > Billing. Refunds are issued " "to the original card within 5-7 business days.", ], }, # ... more Recall answers across corpora A / B / C ] dataset = EvaluationDataset.from_list(samples) result = evaluate( dataset=dataset, metrics=[Faithfulness(), ResponseRelevancy()], # both reference-free ) print(result) # {'faithfulness': 0.71, 'answer_relevancy': 0.88} df = result.to_pandas() # per-row scores to find the worst answers

The manager-approval sentence has no support in the context, so this sample's faithfulness lands below 1.0 while its relevancy stays high - the answer is on topic, it just added a detail. That signature, high relevancy plus dented faithfulness, is exactly a hallucination.

Reference-free is the point Because neither metric needs a gold answer, you can run this nightly over a random sample of yesterday's real Recall traffic. That is your early-warning system for hallucination drift long before b7's correctness metrics, which do need references.
Part 2 · covers noise sensitivity + semantic similarity

Noise sensitivity + semantic similarity 8 min live

Two more metrics for two more failure shapes. Noise sensitivity asks how easily irrelevant retrieved context knocks the model into a wrong claim. Semantic similarity asks how close the answer is in meaning to a known-good reference - forgiving different wording where an exact-match check would not.

NOISE SENSITIVITY · lower is better · needs ground truth Relevant + noisy context Answer claims made Check vs ground truth Noise sens. wrong / total SEMANTIC SIMILARITY · needs a reference answer Answer embed → vector Reference cosine of the two vectors Semantic similarity 0.0 far → 1.0 same meaning Noise sensitivity stress-tests robustness; semantic similarity forgives wording. Both need a reference, so they are offline metrics.
🔍 Click to zoom - noise sensitivity counts wrong claims under noisy context; semantic similarity is the cosine of answer and reference embeddings
LiveNoise sensitivity: how easily noise knocks it wrong3 min

Real retrieval hands the model a mix - some relevant chunks and some near-miss noise. Noise sensitivity measures how often that noise leaks into a wrong claim. It is the fraction of claims in the answer that are incorrect, given the ground truth.

  • The formula. Noise sensitivity = (incorrect claims) / (total claims). Because it counts mistakes, lower is better - the opposite direction from faithfulness and relevancy. A robust model reads past the noise and scores near 0.
  • It needs ground truth. To label a claim incorrect you need to know the right answer, so this is an offline metric you run against a golden set, not on raw live traffic.
  • When it is useful. Reach for it when your retriever returns a lot of borderline chunks and you want to know whether the generator is disciplined enough to ignore them. It isolates a robustness problem that faithfulness alone can miss.
LiveSemantic similarity: meaning, not wording3 min

Sometimes you have a reference answer and want to know how close the model got - but exact string matching punishes every valid paraphrase. Semantic similarity embeds both the answer and the reference and reports the cosine similarity between the two vectors.

  • The formula. Semantic similarity = cosine(embed(answer), embed(reference)). 1.0 means the same meaning; values near 0 mean unrelated. It is smooth and forgiving of rewording.
  • It needs a reference. There must be a known-good answer to compare against, so it belongs to your offline golden-set evaluation.
  • When it is useful. A quick, cheap proxy for "did the answer land near the target meaning" when you have references but do not want a full LLM-judge correctness call. It is a component of answer correctness in b7, not the whole thing.
  • The caveat. High similarity is not the same as correct. Two answers can be semantically close yet disagree on the one fact that matters, and embeddings will not always separate them.
Real world

The paraphrase that failed a string check. A team (anonymized) graded a support assistant with exact-match against a reference answer and watched scores crater - not because the bot was wrong, but because it wrote "we will refund you within a week" where the reference said "refunds post in 5-7 business days". Swapping to semantic similarity recovered the signal: cosine 0.93, clearly the same meaning. Exact match had been measuring wording, not helpfulness.

Direction check before you alert on a metric Faithfulness, response relevancy, and semantic similarity all read "higher is better". Noise sensitivity reads "lower is better". Wire your dashboards and CI gates with that flip in mind, or you will page yourself for a model that got more robust.
Build-along · take it further

Score a faithful vs an unfaithful answer by hand ★ 10 min · pen and paper

Do the decomposition yourself once and faithfulness stops being a black box. Take one Recall question and two candidate answers to it.

Pin the context. Write out the one or two retrieved chunks Recall was given for the question - say the refund policy chunk: "Refunds are issued to the original card within 5-7 business days."

Decompose answer A into claims. Answer A: "Cancel in Settings, then your refund posts to your original card in about a week." Break it into atomic claims: (1) cancel in Settings, (2) refund goes to original card, (3) takes about a week. Check each against the context. All three are supported. Faithfulness = 3/3 = 1.0.

Decompose answer B into claims. Answer B: "Cancel in Settings, refunds post in 5-7 days, and amounts over $500 need manager sign-off." Claims: (1) cancel in Settings - supported, (2) 5-7 days - supported, (3) over $500 needs sign-off - NOT in the context. Faithfulness = 2/3 = 0.67.

Reflect. Both answers are on topic, so response relevancy would score both high. Only faithfulness separates them - and the invented sign-off rule is exactly the kind of confident hallucination that gets a support bot in trouble. In one line: which metric would have caught it, and would it have caught it without a reference answer?

★ Recall's answers after b4 Recall's answers now carry four numbers, not just its retrieval score. You can tell a hallucination (low faithfulness) from an off-topic reply (low relevancy) from a noise-fragile generator (high noise sensitivity) from a valid paraphrase (high semantic similarity). In b5 we look under the hood of the LLM judge that produces several of these - and at how it can be fooled.
Homework

Before session b5 ◐ 40 min total

Source material

Official sources covered

Taught from official docs. This page covers ~80% of their working content on generation metrics - the correctness metric that combines several of these lands in b7.

RAGAS · faithfulness + response relevancyPart 1 · claims supported / total; N generated questions vs input; both reference-free
RAGAS · noise sensitivity + semantic similarityPart 2 · incorrect claims / total (lower better, needs truth); cosine of answer vs reference
TruLens · RAG Triad groundednessNamed as the sibling of faithfulness; full context in a2 and b6
Check yourself

Three questions before you go 🎯 ◐ 90 seconds

1 · RAGAS faithfulness is computed as...

Faithfulness decomposes the answer into claims and scores the share that can be inferred from the context: supported / total. It is the hallucination detector, and it needs no reference.

2 · Response relevancy measures...

Relevancy has an LLM generate N questions from the answer and compares them by cosine to the original question. A confidently wrong but on-topic answer can still score high, so it measures focus, not truth.

3 · For noise sensitivity, a lower score is better because...

Noise sensitivity is (incorrect claims) / (total claims) under noisy context, and it needs ground truth to label claims. Because it counts errors, lower is better - the reverse of faithfulness and relevancy.

Builder session 4 cheat sheet · pin this

Generation vs retrievalGeneration metrics grade the answer the user reads, not which chunks came back. Retrieval can be perfect and the answer still wrong.
FaithfulnessClaims supported by context / total claims. Hallucination detector. LLM judge, no reference. Not the same as accuracy.
Response relevancyMean cosine of N (default 3) LLM-generated questions vs the original question. On-topic, NOT accuracy. Reference-free. Formerly Answer Relevancy.
Noise sensitivityIncorrect claims / total claims under noisy context. Lower is better. Needs ground truth, so it is offline.
Semantic similarityCosine of answer embedding vs reference embedding. Forgives wording. Needs a reference. High is not the same as correct.
The pairFaithfulness catches invention; relevancy catches wandering. Read them together - you want both high.
Direction flipFaithfulness, relevancy, similarity: higher is better. Noise sensitivity: lower is better. Wire alerts accordingly.
Reference or notFaithfulness + relevancy run on live traffic. Noise sensitivity + semantic similarity need a golden set.