AI engineering glossary · Evaluation metrics
What is recall at k?
Recall at k (also called R@k, recall@k): Among all the relevant items that exist for a query, the fraction that appear in the top k results. It measures whether retrieval brings the needed material into view at all, which matters for the first stage of a search or retrieval pipeline.
Recall at k: an example
A query has 6 relevant documents and 3 of them are in the top 10, so recall at 10 is 0.5.
Recall at k in Python
A short example you can run (Python 3.11). The output below is what it really prints.
def recall_at_k(retrieved, relevant, k):
return len(set(retrieved[:k]) & set(relevant)) / len(relevant)
retrieved = ["d3", "d7", "d1", "d9", "d2"]
relevant = ["d1", "d2"]
for k in (1, 3, 5):
print(f"recall@{k} = {recall_at_k(retrieved, relevant, k):.2f}")Output
recall@1 = 0.00 recall@3 = 0.50 recall@5 = 1.00
Related terms
More Evaluation metrics terms
- Reciprocal rank
- Relevance judgments
- Reliability diagram
- Residual plot
- ROC curve
- Root mean squared error
- Root mean squared logarithmic error
- ROUGE
Where you learn it
Recall at k is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.