PREP WITH PROOF
Menu
FREE AI LEARNING TOOL · NO SIGNUP

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.

Separate entries with commas. Up to 20 unique IDs per list; IDs use letters, digits, underscores or hyphens, up to 24 characters. Every retrieved ID needs a judgment. Leave a ranking blank to model no results.

Reset example

Comparison at k = 3

Positive grades count as relevant for recall, precision and reciprocal rank. nDCG uses the full 0–3 grades.

MetricRanking ARanking B
Recall@k0.66670.3333
Precision@k0.66670.3333
Reciprocal rank@k (RR)0.50001.0000
nDCG@k0.62990.1065
DCG@k5.91651.0000
Ideal DCG@k9.39289.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.

RankIDGradeGain (2^grade − 1)log₂(rank + 1)DCG contributionCumulative DCG
1x001.00000.00000.0000
2a371.58504.41654.4165
3b232.00001.50005.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.

RankIDGradeGain (2^grade − 1)log₂(rank + 1)DCG contributionCumulative DCG
1c111.00001.00001.0000
2x001.58500.00001.0000
3y002.00000.00001.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 →

Reference

scikit-learn: nDCG definition, cutoff and ties