Skip to content
AI360Xpert
Beta

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.

Recall at K checks whether the true match sits inside the top returns, so larger K always scores higher
Recall at K checks whether the true match sits inside the top returns, so larger K always scores higher

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 NN queries, R@K=(1/N)∑i[ranki≤K]R@K = (1/N)\sum_i [rank_i \le K], higher is better. Report K=1,5,10K = 1, 5, 10 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. R@1=6/10=0.6R@1 = 6 / 10 = 0.6 and R@5=9/10=0.9R@5 = 9 / 10 = 0.9. The 0.30.3 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.8

Five 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.