Evaluate retrieval before tuning the answer
Measure evidence coverage, position, source selection and reranking separately.
Evaluate retrieval before tuning the answer
Work through the decision
A policy question has two labeled relevant passages. The first-stage top three contain one of them at rank three. The model omits the exception found in the second passage. What can ranking alone improve?
Check your reasoning
At k=3 the candidate recall is one half. Reciprocal rank for the first relevant passage is one third. A reranker can move the retrieved passage higher, improving ordering, but it cannot introduce the absent passage. Check source eligibility, parsing, chunking and candidate depth before modifying the generator.
Compare the choices
- Recall at k
- Divide the number of labeled relevant passages present in the top k by the total labeled relevant passages for that query.
- Reciprocal rank
- Take one divided by the rank of the first relevant result, or zero when absent. Average across queries for mean reciprocal rank.
- Reranking
- Rescore a bounded set of retrieved candidates using a stronger relevance signal. Measure latency and quality against the original ordering.
- Source eligibility filtering
- Restrict candidates to approved, applicable, permitted revisions. Keep the eligibility rule consistent across retrieval and evaluation.
Test the decision
An obsolete and a current manual may be semantically similar. Use effective dates and entitlement filters to define eligible sources. Evaluate candidate recall on that eligible population and identify whether extra context helps or crowds out the evidence.
Practice the guide skills
- Two documents conflict about a warranty period. Watch 15:48 · Continue at 16:13
Check your answer
Prefer an approved source for the product, jurisdiction and effective date. Preserve superseded versions for historical questions and avoid mixing incompatible editions in one unqualified answer.
- Test whether gold passages enter the top results. Watch 28:00 · Continue at 28:34
Check your answer
Define relevance labels and candidate depth. Recall at k measures the fraction of labeled relevant items found. Reciprocal rank rewards the first relevant item appearing early. Evaluate by query segment.
- A long policy separates exceptions from the rule they modify. Watch 23:45 · Continue at 24:00
Check your answer
Try section-aware, semantic or parent-child chunking. Retrieve a small child for precise matching, then supply a bounded parent section with its original provenance where appropriate.
- Which stage can improve ordering but cannot recover an omitted passage? Watch 30:36 · Continue at 30:42
Check your answer
A reranker rescores a candidate list. Increase first-stage coverage or repair the index if the reference is absent. Measure ranking and latency separately.
Official objectives for this lesson
Lab · Measure candidate recall and the effect of reranking
Save as retrieval.py and run python3 retrieval.py. These synthetic first-stage rankings contain three authorized passage IDs per query. The judgments list all acceptable evidence. The reranker supplies one fixed score per candidate. Predict which question reranking alone can repair.
judgments = {"filter": {"B", "D"}, "reset": {"E"}, "torque": {"J"}}
candidates = {"filter": ["A", "B", "D"], "reset": ["E", "F", "G"],
"torque": ["H", "I", "K"]}
scores = {"A": 1, "B": 6, "D": 4, "E": 5, "F": 3, "G": 1,
"H": 3, "I": 4, "K": 5}
def evaluate(rankings):
recall = []
reciprocal_ranks = []
for query, ranking in rankings.items():
relevant = judgments[query]
recall.append(len(set(ranking[:3]) & relevant) / len(relevant))
hits = [i for i, passage in enumerate(ranking[:3], 1) if passage in relevant]
reciprocal_ranks.append(1 / hits[0] if hits else 0)
return sum(recall) / len(recall), sum(reciprocal_ranks) / len(reciprocal_ranks)
reranked = {query: sorted(ids, key=scores.get, reverse=True)
for query, ids in candidates.items()}
for name, ranking in [("first pass", candidates), ("reranked", reranked)]:
recall, mrr = evaluate(ranking)
print(f"{name}: recall@3 {recall:.3f}, MRR@3 {mrr:.3f}")
Check the result
first pass: recall@3 0.667, MRR@3 0.500 reranked: recall@3 0.667, MRR@3 0.667
Moving B to first position improves reciprocal rank on the filter question. The torque query still misses J in both runs. Inspect its source, filter, chunk boundary and candidate depth. Replace K with the authorized passage J, give J score 6, and verify that both reranked metrics reach 1.000.
Related lesson · Delta Lake
Evaluate retrieval before tuning the answer quiz
Answer 3 questions. Check each answer for an explanation.
Worked example · Evaluate retrieval before tuning the answer