Skip to content
Raisalon

Artificial Intelligence

Recall@k vs. MRR: evaluate RAG retrieval with three queries

Score the same ranked documents with Recall@3, hit rate and MRR@3. See which metric detects missing evidence and which detects a useful result arriving late.

Author
3 min read

A retrieval-augmented generation (RAG) system can put a relevant document first and still leave out half the evidence needed for an answer. Mean reciprocal rank (MRR) rewards an early first relevant result. Recall at a cutoff k measures how much of the known relevant set appears in the first k positions. Track both when a question can require several sources.

Label the evidence before comparing retrievers

Consider a fictional benefits handbook. The question “Can I cancel after renewal, and what refund applies?” requires the cancellation rule and the refund schedule. A question about the postal address needs only the contact page. Assign stable identifiers to relevant documents before looking at which system retrieved them. Otherwise the system that generated your candidate pool can influence the definition of success.

Query Relevant identifiers First three results, in rank order
Renewal cancellation cancel, refund cancel, home, terms
Mailing address contact home, terms, contact
Account closure close home, terms, faq

An identifier appearing anywhere in the first three is a hit. Two queries out of three have a hit, giving a hit rate of two thirds. Hit rate doesn’t distinguish the cancellation query, which found half its evidence, from the address query, which found everything. That difference matters when the generator must cite both a rule and an exception.

Compute the score for each query

For cancellation, Recall@3 is 1/2 and reciprocal rank is 1 because the first relevant result is at rank one. For the address, Recall@3 is 1 and reciprocal rank is 1/3. For closure, both scores are zero at this cutoff. Averaging equally across the three queries gives Recall@3 of 0.5 and MRR@3 of 4/9, about 0.444. This cutoff-limited MRR gives a query zero credit when its first relevant result arrives after rank three. TorchMetrics retrieval reciprocal rank

def score(ranked, relevant, k):
    if not relevant or k < 1:
        raise ValueError("Expected a labeled query and a positive cutoff")
    top = ranked[:k]
    recall = len(set(top) & relevant) / len(relevant)
    first = next((i for i, doc in enumerate(top, 1) if doc in relevant), None)
    return recall, (1 / first if first else 0.0), int(first is not None)

cases = [
    (["cancel", "home", "terms"], {"cancel", "refund"}),
    (["home", "terms", "contact"], {"contact"}),
    (["home", "terms", "faq"], {"close"}),
]
scores = [score(ranked, relevant, 3) for ranked, relevant in cases]
print(scores)
print([round(sum(col) / len(scores), 3) for col in zip(*scores)])
# [0.5, 0.444, 0.667] for recall, reciprocal rank and hit rate

The set in the recall numerator prevents the same identifier from earning credit twice. Duplicate entries still occupy ranks if that’s what the downstream system actually sees. If the application deduplicates by parent document, apply that operation in the same place in the evaluation. Deduplicating before the cutoff can admit another document. Doing it afterward cannot.

Try two changes with different payoffs

Move the contact page from third place to first for the address query. Query recall stays at one because the document was already present. Its reciprocal rank rises from one third to one. A reranker that moves useful material toward the top can therefore improve MRR without changing which documents were retrieved.

Instead, replace “terms” with “refund” at rank three for the cancellation query. Query recall rises from one half to one. Reciprocal rank stays at one because the first result already matched. For an answer that must quote the refund schedule, this second change could matter more to a reader. Inspect the answer and citations separately before claiming an improvement in answer correctness. Singapore Government RAG evaluation playbook

Match the unit of relevance to the evidence

A page-level label can be too generous. Suppose the retriever returns a footer from the correct document while the refund rule lives on another page. Document recall credits the hit, yet the model has no supporting passage. Use stable section or evidence identifiers when a successful answer depends on a particular clause. With tables, preserving row and header context can decide whether the retrieved evidence is usable.

Keep genuinely unanswerable questions in a separate evaluation. A query with no labeled relevant documents gives recall a zero denominator. Forcing it to zero alongside retrieval misses mixes two very different cases. State whether labels are exhaustive or just the sources a reviewer happened to find. An unjudged but correct document is reason to revisit the judgments.

Next steps

Keep the ranked identifiers alongside the aggregate scores. Review one case with perfect MRR and partial recall, and another with complete recall but a late first hit. Finally, measure at the number of passages the application actually passes forward. Reporting Recall@10 for a generator that sees only three chunks can hide the exact failure you are trying to fix.

Share

Written by