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 have seen faithfulness defined as support from the retrieved context. Here you will measure a different property: whether the answer responds to what the user asked.
Faithfulness is not enough
An answer can be fully supported by the context and still fail the user. Suppose the question is "How long is the warranty?" and the answer is "The warranty covers manufacturing defects." Every claim may be grounded, yet the question about duration is not answered.
Answer relevance measures how well the answer addresses the question. It does not check whether the answer is true or grounded. It looks only at the pair of question and answer.
| Property | Compares | Catches |
|---|---|---|
| Faithfulness | Answer and retrieved context | Invented or unsupported claims |
| Answer relevance | Answer and question | Off-topic, partial, or padded answers |
| Context relevance | Context and question | Retrieval that brought back the wrong passages |
What low relevance looks like
- Off-topic: the answer discusses a related subject, such as returns when the user asked about warranty.
- Incomplete: the question has two parts and the answer covers one.
- Evasive: the answer says "I can't find that" although the context contains it. This is relevant in form but unhelpful. Score it separately from refusals that are correct.
- Padded: the answer contains the right fact buried in unrelated text.
Two ways to score it
Judge with a rubric
Give an LLM judge the question and the answer, and ask for a score against a fixed scale. Do not show it the context, so grounding cannot influence the score.
- 0: does not address the question.
- 1: addresses part of the question.
- 2: addresses the whole question, with extra or missing focus.
- 3: addresses the whole question directly.
Ask for a short reason before the score. Validate the judge against human labels, as covered in later chapters.
Generate questions from the answer
A second method asks the model to write several questions that the answer would respond to. You then embed those questions and the original question, and average their cosine similarity. If the answer is on topic, the generated questions resemble the original. If it drifts, they do not.
import math
def cosine(a, b):
dot = sum(x * y for x, y in zip(a, b))
na = math.sqrt(sum(x * x for x in a))
nb = math.sqrt(sum(y * y for y in b))
return dot / (na * nb) if na and nb else 0.0
def answer_relevance(question_vec, generated_question_vecs):
"""Mean similarity between the original question and questions
that the answer could have been written to address."""
if not generated_question_vecs:
return None # nothing generated; do not report this as 0 or 1
sims = [cosine(question_vec, v) for v in generated_question_vecs]
return sum(sims) / len(sims)
# Toy 3-dimensional vectors, for illustration only.
q = [0.9, 0.1, 0.0]
on_topic = [[0.8, 0.2, 0.1], [0.9, 0.0, 0.1]]
off_topic = [[0.0, 0.1, 0.9], [0.1, 0.0, 0.8]]
print(round(answer_relevance(q, on_topic), 2))
print(round(answer_relevance(q, off_topic), 2))The embedding method is cheap and needs no rubric. Its weakness is that similar wording does not mean the question is answered. An answer that restates the question without giving a fact can score high.
Common errors
- Showing the judge the context, which mixes relevance with grounding.
- Rewarding length. Longer answers often score higher with judges, so include padded examples in your test set.
- Counting correct refusals as failures. Keep questions with no answer in the corpus in a separate group.
- Averaging into one score. Report relevance next to faithfulness so you can see which one dropped.
Exercise
A user asks "What is the refund window and who pays return shipping?" The system answers "Refunds are available within 30 days of purchase." The answer is fully supported by the context. How would you score faithfulness and answer relevance, and why?
Show answer
Faithfulness is high, because the claim is supported by the context. Answer relevance is partial, such as 1 on the 0 to 3 rubric above, because the answer addresses the refund window but ignores who pays return shipping. The two scores differ because faithfulness checks the answer against the context, and answer relevance checks it against the full question.