Skip to content
EvalSuite
Documentation menu

Retrieval and RAG

NDCG@k

Implementedrag.ndcg_at_k

Definition

Discounted cumulative gain of the top k (graded relevance, log2 rank discount) divided by the best possible DCG for the query; linear gains (Järvelin & Kekäläinen, trec_eval) or exponential 2^rel − 1 (Burges).

Formula

DCG@k = Σ_{i≤k} gain(rel_i) / log2(i + 1); NDCG@k = DCG@k / IDCG@k

Range: [0, 1]

Inputs and outputs

  • relevant: per query, relevant ids or id -> grade
  • retrieved: per query, ranked ids

Returns: MetricResult (float, or per-example array with average=None)

Assumptions

No assumptions beyond valid, aligned inputs of the documented types.

Limitations

No metric-specific limitations are documented yet. Interpret the value alongside the task, data, and other metrics.

Python API

PythonSince v0.4.0
import evalsuite as es

es.ndcg_at_k(graded, retrieved, k=10)

References

  1. Järvelin K, Kekäläinen J. Cumulated gain-based evaluation of IR techniques. ACM TOIS. 2002;20(4):422-446.
  2. Burges C, et al. Learning to rank using gradient descent. ICML. 2005:89-96.

Implementation status