Sub topic 3
Judging Context Relevance When You Have No Labels
Assume you understand chunking, embeddings, vector search, prompting an LLM, Python, and basic averages. This chapter focuses on evaluating the retrieved context when no relevance labels exist.
Use a judge for context relevance
Context relevance asks whether the retrieved passages contain information useful for answering the question. An LLM judge can score each question-context pair using a fixed scale, such as:
- 0: the context is unrelated
- 1: the context is partly useful
- 2: the context contains the needed information
Give the judge only the question, retrieved context, scoring rules, and required output format. Do not include the generated answer when measuring context relevance. Otherwise, the answer can influence the score.
Check the judge against human labels
Sample questions across easy, ambiguous, and failure cases. Have people label whether the context is relevant. Compare their labels with the judge's labels using agreement, precision, recall, or a correlation for graded scores. Review disagreements. If the judge systematically rewards keyword overlap even when the passage does not answer the question, revise the rubric or prompt.
Check citation accuracy
Citation accuracy asks whether each cited passage supports the claim attached to it. Split an answer into claims, identify each claim's citation, and label the citation as supporting, partially supporting, or unsupported. A fluent answer can still have poor citation accuracy if its references are adjacent but insufficient.
Diagnose the failing component
Compare retrieval scores with answer scores:
- Low context relevance and low faithfulness usually indicate a retriever problem.
- High context relevance but low faithfulness indicates a generator, prompt, or context-order problem.
- High faithfulness but low answer relevance means the answer may be supported yet fail to address the question.
Estimate statistical reliability
Evaluate many independent questions, not repeated runs of one question. Report the mean and uncertainty. A bootstrap confidence interval resamples per-question scores:
import random
def bootstrap_ci(scores, n_resamples=2000, seed=0):
rng = random.Random(seed)
n = len(scores)
means = []
for _ in range(n_resamples):
sample = [scores[rng.randrange(n)] for _ in range(n)]
means.append(sum(sample) / n)
means.sort()
return (sum(scores) / n, means[50], means[1949])
print(bootstrap_ci([1.0, 0.5, 1.0, 0.0, 1.0, 0.75]))Monitor regressions
Keep a fixed evaluation set and run it whenever retrieval, chunking, prompts, or models change. Fail a regression check when a metric drops beyond a chosen threshold or its confidence intervals show a meaningful decline. Add production samples over time because a fixed set cannot reveal every new query type.
Exercise
Retrieved context is highly relevant, but the answer invents a policy detail. Which component should you investigate first?
Show answer
Investigate the generator and its prompt, then verify the claim-level faithfulness checks.