Skip to content

Retrieval Evaluation Metrics

Purpose

Retrieval Evaluation Metrics are used to measure the effectiveness of the retrieval component in RAG systems. They evaluate how well the system finds relevant documents or fragments based on a query. Metrics are applied during the development phase as well as for monitoring in production.

Main Metrics

Metric Description Formula
Precision@k Proportion of relevant among the top k results TP@k / k
Recall@k Proportion of found relevant among all relevant TP@k / Total Relevant
MRR Mean reciprocal rank of the first relevant 1 / rank_first_relevant
NDCG Normalized discounted cumulative gain DCG / IDCG
MAP Mean average precision across all queries Average Precision

Example Calculation of Precision@k

def precision_at_k(retrieved, relevant, k):
    retrieved_k = retrieved[:k]
    relevant_count = sum(1 for doc in retrieved_k if doc in relevant)
    return relevant_count / k

See also