Sub topic 7
Answer relevance: does the answer address the question?
This chapter assumes you know how a RAG pipeline works, can read Python, and understand precision and recall. You should also know how faithfulness is defined: an answer is faithful when the retrieved context supports its claims. Here we look at a different property, answer relevance.
What answer relevance measures
Answer relevance asks one question: does the answer address what the user asked? It ignores whether the answer is true. It also ignores whether the answer is supported by the context.
That makes it independent of faithfulness. An answer can fail on one and pass on the other.
| Answer | Faithful? | Relevant? |
|---|---|---|
| Question: "How long is the warranty?" Answer: "The warranty lasts 24 months." (context says 24 months) | Yes | Yes |
| Same question. Answer: "The warranty covers manufacturing defects." (context says so) | Yes | Partly. It is true but does not give the duration. |
| Same question. Answer: "The warranty lasts 5 years." (context says 24 months) | No | Yes. It addresses the question but is wrong. |
| Same question. Answer: "I could not find that information." | Yes (it makes no unsupported claim) | No, unless the context truly lacks the answer |
The second row is the common trap. A generator that stays strictly inside the context can score perfectly on faithfulness while answering a neighboring question. Faithfulness alone cannot detect this, so you need a separate measure.
Why it matters for diagnosis
Low answer relevance usually points at one of these causes:
- The retriever returned context about the wrong topic, and the generator summarized it anyway.
- The retriever returned the right topic but not the passage with the specific fact. The generator filled the space with related, supported detail.
- The prompt asks the generator to be thorough, so it pads the answer with material nobody asked for.
- The question has several parts and the answer covers only some of them.
- The generator refused or hedged when the context did contain the answer.
The first two causes are retrieval problems. The last three are generation problems. A later chapter covers diagnosis in full. For now, remember that answer relevance is the signal that separates "the answer is grounded but off target" from "the answer is on target but ungrounded".
The diagram shows that each score compares a different pair. Answer relevance is the only one that compares the answer directly with the question and never looks at the context.
Approach 1: judge the answer directly
The simplest method asks an LLM judge to rate how well the answer addresses the question. You give it the question and the answer, and nothing else. Leaving out the context is deliberate. If the judge sees the context, it starts checking support, and you end up measuring faithfulness again.
A direct rating prompt asks for a score on a small scale, such as 1 to 5, plus a short reason. Keep the scale small and define each point. For example:
- 5: answers every part of the question directly.
- 3: answers part of the question, or answers it with a lot of unrelated material.
- 1: does not address the question.
Direct rating is cheap and easy to read. Its weakness is that judges are lenient. Ratings cluster at the top of the scale, which leaves little room to see improvements.
Approach 2: generate questions from the answer
A second method, used by several open-source evaluation libraries, works backward. The idea is that a relevant answer should let you reconstruct the original question.
- Give the judge only the answer.
- Ask it to write N questions that this answer would respond to (N is often 3).
- Embed the original question and each generated question.
- Average the cosine similarity between the original and the generated questions.
If the answer is on target, the generated questions resemble the original, and the score is high. If the answer wandered, the generated questions describe something else, and the score drops. A vague answer such as "It depends on several factors" produces generic questions that match poorly.
The cosine similarity step is short:
import math
def cosine(a, b):
dot = sum(x * y for x, y in zip(a, b))
norm_a = math.sqrt(sum(x * x for x in a))
norm_b = math.sqrt(sum(y * y for y in b))
if norm_a == 0 or norm_b == 0:
return 0.0
return dot / (norm_a * norm_b)
def answer_relevance(original_vec, generated_vecs):
"""Mean cosine similarity between the original question and
questions regenerated from the answer."""
if not generated_vecs:
return None # nothing to compare; do not report 0 or 1
sims = [cosine(original_vec, v) for v in generated_vecs]
return sum(sims) / len(sims)
# Toy vectors for illustration. In practice these come from an embedding model.
original = [0.9, 0.1, 0.0]
on_target = [[0.85, 0.15, 0.0], [0.95, 0.05, 0.1], [0.8, 0.2, 0.0]]
off_target = [[0.1, 0.9, 0.2], [0.0, 0.8, 0.5], [0.2, 0.7, 0.3]]
print(round(answer_relevance(original, on_target), 3))
print(round(answer_relevance(original, off_target), 3))The on-target answer scores close to 1.0 and the off-target one scores far lower. The toy vectors only show the arithmetic. Real embeddings need a real model.
Limits of the question-generation method
- It is blind to correctness. A wrong answer that addresses the question scores well, which is consistent with the definition but surprises people.
- Embedding similarity is coarse. "How long is the warranty?" and "What does the warranty cover?" are close in embedding space even though they ask different things. Partial answers can score higher than they deserve.
- Noncommittal answers are a special case. "I don't know" generates unrelated questions and scores low. Yet it may be the right behavior when the context lacks the answer. Handle these answers separately, as described below.
- It costs several calls per answer. One generation call plus N embeddings per sample.
- Scores are not on a natural scale. A mean similarity of 0.8 has no fixed meaning. It depends on the embedding model, so compare scores only within one setup.
Approach 3: checklist of question parts
For questions with several parts, a more precise method breaks the question into the pieces an answer must cover, then checks each one. For "What is the warranty period, and does it cover water damage?" the checklist is:
- States the warranty period.
- States whether water damage is covered.
The judge marks each item as addressed or not, and the score is the fraction addressed. This mirrors claim-level faithfulness, with requirements in place of claims. It gives you a score you can explain, and it shows which part was missed. The cost is that you must produce the checklist, either by hand for the evaluation set or with an LLM for each question.
Handling refusals and "not found" answers
A good RAG system should sometimes say it cannot answer. If the evaluation set includes questions the corpus cannot answer, a correct refusal is the right outcome. A relevance score that punishes it will push you toward systems that invent answers.
The fix is to label this in the dataset. For each question, record whether the corpus contains the answer, then score the two groups differently:
- Answerable questions: score relevance as usual. A refusal counts as a failure.
- Unanswerable questions: measure whether the system refused. A refusal counts as a success, and a confident answer counts as a failure, which is usually a faithfulness failure too.
def is_refusal(answer):
markers = (
"i could not find",
"i don't know",
"not enough information",
"the context does not",
)
text = answer.lower()
return any(m in text for m in markers)
def score_case(answer, answerable, relevance_fn):
"""Return a score in [0, 1] using the right rule for each group."""
refused = is_refusal(answer)
if answerable:
return 0.0 if refused else relevance_fn(answer)
return 1.0 if refused else 0.0
print(score_case("I could not find that in the documents.", False, lambda a: 1.0)) # 1.0
print(score_case("I could not find that in the documents.", True, lambda a: 1.0)) # 0.0
print(score_case("The warranty lasts 24 months.", True, lambda a: 0.9)) # 0.9String matching on refusal phrases is brittle, and it is only a starting point. For production use, ask the judge to classify each answer as "answers", "partially answers", or "refuses", and validate that classifier against human labels.
Common errors
- Showing the judge the context. The judge then mixes support and relevance in one score. Give it only the question and the answer.
- Reading a high score as quality. A relevant answer can be wrong. Always report answer relevance next to faithfulness, never in place of it.
- Punishing correct refusals. Separate answerable from unanswerable questions, as shown above.
- Ignoring length. Judges often prefer long answers. If your system gets wordier after a change, a rising relevance score may reflect that bias. Track answer length alongside the score.
- Comparing scores across setups. A change of judge prompt, judge model, or embedding model shifts the whole scale. Rerun the baseline when you change any of them.
- Using one score for multi-part questions. A single holistic rating hides partial answers. Use the checklist method for those questions.
Reading the three scores together
Taken together, the main RAG scores form a pattern you can read.
| Context relevance | Faithfulness | Answer relevance | Likely situation |
|---|---|---|---|
| High | High | High | Healthy |
| High | High | Low | Generator answered a different question, or over-hedged |
| Low | High | Low | Retriever found the wrong material and the generator stayed close to it |
| High | Low | High | Generator added claims beyond the context |
| Low | Low | High | Generator answered from its own memory, ignoring the context |
The last row is easy to miss. Answer relevance can look excellent while retrieval is failing, because the model answers the question from training data. That is why this score cannot stand alone.
Exercise
A RAG system answers "What is the return window and who pays for shipping?" with "Items can be returned within 30 days of delivery." The context supports that sentence. What are its faithfulness and answer relevance, and which method would show the problem most clearly?
Show answer
Faithfulness is high because the one claim is supported by the context. Answer relevance is only partial because the answer covers the return window but ignores who pays for shipping. A direct 1 to 5 rating might give a lenient 4. The checklist method shows the problem most clearly: it lists two required parts, marks only the first as addressed, and scores 0.5, and it names the missing part.
Exercise
Your evaluation set contains 100 questions, and 20 of them have no answer in the corpus. A new system version refuses all 20 of them and answers 70 of the other 80 with a relevance score above 0.8, and refuses the remaining 10. Using the scoring rule from this chapter, how many questions count as clear failures, and why would a single relevance score without the answerable label be misleading here?
Show answer
The 10 answerable questions that were refused count as failures, since a refusal on an answerable question scores 0. The 20 correct refusals score 1.0 under the rule. Without the label, the 20 refusals would look like irrelevant answers and drag the average down, hiding the fact that the system behaved correctly on them and wrongly on only 10.