Recall at K Retrieval Score
The share of queries whose true match lands in the top K returns, the headline for image and cross-modal search.
Why Does This Exist?
Retrieval returns ranked lists, not single labels. Users scan the top few, so scoring must ask whether truth appears early. Recall at K marks 1 when any true match sits in the top K and 0 otherwise, then averages over queries. Retrieval and cross-modal search report it at several K.
This page computes toy top-1 and top-5 with gallery traps.
Think of It Like This
Finding a book on the display shelf
A shop displays five books face-out. Recall at 5 asks whether your title made that shelf.
Top 1 is the single spotlight slot. Larger shelves always help, which is why K must be stated.
How It Actually Works
For queries, , higher is better. Report together because top-1 prices precision while larger K prices coverage. Gallery size, deduplication and same-instance leakage change numbers, so fix the protocol before comparing.
Worked toy ranking
Take 10 queries where 6 hit at rank 1 and 9 hit within rank 5. and . The gap prices early-rank quality on this toy set.
Code
Recall at K from rank lists.
import numpy as np
def recall_at_k(ranks: np.ndarray, k: int) -> float: return round(float(np.mean(ranks <= k)), 3)
ranks = np.array([1, 1, 2, 1, 8, 3, 1, 12, 1, 4])print(recall_at_k(ranks, 1), recall_at_k(ranks, 5))# -> 0.5 0.8Five rank-1 hits give 0.5 at 1, eight within five give 0.8.
Watch Out For
Leaking near-duplicates into the gallery
Same-instance crops in gallery and query inflate hits. The symptom is a strong number with weak new-place search. Fix it with grouped splits and deduped galleries.
The Quick Version
- Recall at K averages whether truth ranks within K per query.
- Toy 6 of 10 at 1 gives 0.6, 9 of 10 within 5 gives 0.9.
- Larger K always scores higher, so always state K.
- Use it with several K for image and cross-modal search.
- Fix gallery dedup and splits before comparing.