Retrieval metrics calculator
A retriever returns a ranked list, and different metrics reward different things about it. Precision asks how much of the top is relevant, recall asks how much of the relevant material you found, and MRR and nDCG care about where in the list the good results sit.
The top 5 hold 3 of the 5 relevant items, and the first relevant one is at rank 1. The best order of this list would score 1.
Results and judgements
The ranked list has this many places.
Precision, recall, hit rate and nDCG look at the first k results.
Every item that answers the query, including any the search missed. It can’t be lower than the relevant items in the list.
Ranked results
Set how relevant each result is, from 0 to 3. Then use Up and Down to move a result one rank and watch the metrics change.
- 1gain 7
- 2gain 0
- 3gain 3
- 4gain 0
- 5gain 1
- 6gain 0
- 7gain 0
- 8gain 1
- 9gain 0
- 10gain 0
A green bar marks a relevant result. Rows below the cut-off count for MRR and average precision, but not for the @k metrics.
Gain is 2^rel − 1 for a result graded rel, discounted by 1 ÷ log₂(rank + 1), then summed over the first 5 ranks. nDCG divides by the same sum for the best possible order of this list. MRR and average precision read the whole list; MRR is this query’s reciprocal rank, and averaging it across queries gives the mean.
| Metric | Rewards | Ignores |
|---|---|---|
| Precision@k | A top k with few irrelevant results. | Order inside the top k, and relevant items you missed. |
| Recall@k | Finding as many relevant items as possible in the top k. | Order inside the top k, and how many irrelevant results come with them. |
| Hit rate@k | Having at least one relevant result in the top k. | Everything after the first hit. |
| MRR | Putting the first relevant result near the top. | Every relevant result after the first. |
| Average precision | Ranking all relevant items high, and retrieving all of them. | Grades: a slightly relevant item counts the same as a highly relevant one. |
| nDCG@k | Putting the best-graded results first, with less credit further down. | Results past k, and relevant items missing from the list. |
What it shows
Different metrics reward different things about a ranked list. Precision asks how much of the top is relevant. Recall asks how much of the relevant material you found. MRR and nDCG care where the good results sit.
Build one query’s results, grade each one, and move results up or down. After every move, each metric shows how much it changed, so you can see which care about order. A real evaluation averages many queries.
How to read it
- Relevant means graded 1 or higher. Grades run from 0 (not relevant) to 3 (highly relevant). Binary mode uses only relevant and not relevant.
- Precision@k is the share of the first k results that are relevant. Recall@k is the share of all relevant items in the corpus found in the first k.
- Set “Relevant items in the corpus” above the number in your list to model items the search missed.
- Hit rate@k is 1 if any relevant result is in the first k. MRR is 1 ÷ the rank of the first relevant result.
- Average precision sums the precision at each relevant rank, divided by relevant items in the corpus. A missed item pulls it down.
- nDCG@k rewards highly graded results near the top. The gain is 2^rel − 1 by default; “rel” uses the grade itself. ▲ and ▼ compare with your last move.
Questions
What is the difference between precision@k and recall@k?
Precision@k divides the relevant results in the top k by k, so it measures how clean the top of the list is. Recall@k divides them by all relevant items in the corpus, so it measures how much you found. Raising k tends to lift recall and lower precision.
Why does nDCG use a logarithm?
The log₂(rank + 1) discount lowers the credit for a result smoothly as it moves down the list: rank 1 counts in full, rank 3 counts half, rank 7 a third. It models a reader who is less likely to look at lower results.
Should I use 2^rel − 1 or rel as the gain?
The original nDCG paper used the grade itself, and many search teams use 2^rel − 1 to make highly relevant results count for much more. Pick one, state it, and keep it fixed when you compare systems, because the two give different scores.
Why is nDCG shown as n/a?
nDCG divides by the best possible DCG. If no result in the list is relevant, that is zero and the ratio is undefined, so the calculator shows n/a rather than a made-up score.
Does the ideal order include relevant items that are not in my list?
No. The ideal order here re-sorts the grades in your list. Relevant items the search missed lower recall and average precision, but they don’t change the nDCG denominator.
Sources
- Järvelin, K. and Kekäläinen, J. (2002). Cumulated gain-based evaluation of IR techniques. ACM Transactions on Information Systems 20(4).
- Manning, C. D., Raghavan, P. and Schütze, H. (2008). Introduction to Information Retrieval, chapter 8: Evaluation in information retrieval. Cambridge University Press.
Explore further
- BEIRBenchmark that scores retrieval models on many datasets with nDCG, recall and MAP.
Last updated
More tools
All tools- estimatorLLM cost estimatorCost per request and per month across LLM APIs, with caching, batch pricing and routing.Open tool
- estimatorAgent run cost estimatorCost of an agent run by model, steps and prompt caching, with context growth and the step where the window fills.Open tool
- estimatorVector index memory plannerRAM for a vector index by type, element size and replicas, with a breakdown of vectors, links, ids and codebooks.Open tool