Skip to content
EvalSuite
Documentation menu

Retrieval and RAG

Precision@k

Implementedrag.precision_at_k

Definition

Share of the top k retrieved documents that are relevant (k in the denominator even when fewer are returned), averaged over queries.

Formula

|relevant ∩ top_k| / 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.precision_at_k(relevant, retrieved, k=5)

References

  1. Manning CD, Raghavan P, Schütze H. Introduction to Information Retrieval. Cambridge University Press; 2008. Chapter 8.

Implementation status