AI Engineeringcalculator

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.

Room to reorder

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.

nDCG@50.9051 is the best order
Precision@50.63 relevant ÷ 5 results
Recall@50.63 found ÷ 5 in the corpus
Hit rate@51At least one relevant result in the first 5
MRR11 ÷ rank 1, the first relevant result
Average precision0.553Precision at each relevant rank, summed ÷ 5
nDCG@50.905DCG 8.887 ÷ best order 9.823

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.

Relevance labels
nDCG gain

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.

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

Explore further

  • BEIRBenchmark that scores retrieval models on many datasets with nDCG, recall and MAP.

Last updated

More tools

All tools

Your first senior-level
lesson is free.

Choose a course, open a free lesson, and explore an idea you’ve wanted to understand.