RAG retrieval metrics calculator
Compare two ordered result lists for one query. See why coverage, first-hit position and graded ranking quality can disagree.
Set the judgments and rankings
Use the same judged pool and cutoff for both rankings. IDs are case-sensitive. Grade 0 means not relevant; grades 1–3 indicate increasing relevance.
Comparison at k = 3
Positive grades count as relevant for recall, precision and reciprocal rank. nDCG uses the full 0–3 grades.
| Metric | Ranking A | Ranking B |
|---|---|---|
| Recall@k | 0.6667 | 0.3333 |
| Precision@k | 0.6667 | 0.3333 |
| Reciprocal rank@k (RR) | 0.5000 | 1.0000 |
| nDCG@k | 0.6299 | 0.1065 |
| DCG@k | 5.9165 | 1.0000 |
| Ideal DCG@k | 9.3928 | 9.3928 |
A retrieves 2 of 3 judged relevant IDs; B retrieves 1 of 3, within the first 3 positions.
There is no automatic winner: choose a metric that matches the retrieval task. These are one-query scores, not evidence of a production quality improvement.
Ranking A: inspect each contribution
Only the first 3 retrieved IDs contribute. Missing positions contribute zero. Results are calculated before rounding to four decimals.
| Rank | ID | Grade | Gain (2^grade − 1) | log₂(rank + 1) | DCG contribution | Cumulative DCG |
|---|---|---|---|---|---|---|
| 1 | x | 0 | 0 | 1.0000 | 0.0000 | 0.0000 |
| 2 | a | 3 | 7 | 1.5850 | 4.4165 | 4.4165 |
| 3 | b | 2 | 3 | 2.0000 | 1.5000 | 5.9165 |
Ranking B: inspect each contribution
Only the first 3 retrieved IDs contribute. Missing positions contribute zero. Results are calculated before rounding to four decimals.
| Rank | ID | Grade | Gain (2^grade − 1) | log₂(rank + 1) | DCG contribution | Cumulative DCG |
|---|---|---|---|---|---|---|
| 1 | c | 1 | 1 | 1.0000 | 1.0000 | 1.0000 |
| 2 | x | 0 | 0 | 1.5850 | 0.0000 | 1.0000 |
| 3 | y | 0 | 0 | 2.0000 | 0.0000 | 1.0000 |
How the metrics are calculated
Recall@k = relevant IDs retrieved in the first k positions / all positive-grade IDs in the judged pool. Precision@k = relevant IDs retrieved in the first k positions / k. The precision denominator stays k even if fewer results are returned. These are distinct, unique IDs; duplicates are rejected rather than counted twice.
Reciprocal rank@k is 1 / the first relevant rank, or 0 if no relevant ID occurs within k. This tool evaluates a single query, so it reports RR. MRR@k is the arithmetic mean of RR@k over a defined set of queries, including zero-hit queries; one convenient example cannot establish MRR.
DCG@k = Σ (2^grade − 1) / log₂(rank + 1), with ranks starting at 1. Ideal DCG sorts all judged grades from highest to lowest and takes the first k, padding missing positions with zero. nDCG = DCG / ideal DCG. A judged pool without positive relevance has zero ideal gain, so the tool rejects it instead of silently choosing a convention.
Use judgments consistently
For the default example, A finds more relevant IDs, while B puts a relevant ID first. B therefore has a higher reciprocal rank but lower recall and nDCG. Try sorting both lists differently while keeping the judgments fixed to see which metric responds to ordering.
The judged pool is the denominator and the source of the ideal ranking. Incomplete judgments make these pool-based scores incomplete. Unknown IDs are rejected; they are never silently treated as irrelevant. Define whether an ID represents a chunk, document, or evidence group before labeling, and keep that unit fixed. Several chunks from one document can otherwise inflate apparent coverage.
The order you enter breaks retrieval-score ties explicitly; no tie averaging is applied. Other libraries may use linear graded gains instead of this tool’s exponential gains. When comparing with scikit-learn ndcg_score, pass 2^grade − 1 as the relevance values, use distinct descending prediction scores for your ranking, and align the cutoff and judged pool. For a short returned list, do not let a library fill its missing ranks with other judged IDs: those missing positions contribute zero here.
What this tool does not measure
These deterministic calculations do not run a retriever or language model and do not evaluate factual accuracy, citation support, latency or answer usefulness. Compare changes over representative held-out queries and inspect failure cases. A strong retrieval score can still accompany an unsupported generated answer.
Form submissions put inputs in the URL and send them to this website. Use short synthetic IDs; do not enter private questions, document text or credentials. No signup or external AI service is required.
Read the metric definitions and tested Python example →