MODULE m4 · 8.0 HOURS

Search Quality Metrics (Recall @k, MRR, nDCG)

0% complete

LEARNING OBJECTIVES

Module objectives

  1. Understand the importance of the retrieval step in a Retrieval-Augmented Generation (RAG) pipeline.
  2. Learn the concepts of Recall @k, MRR, nDCG metrics and their significance in RAG system evaluation.
  3. Analyze the impact of retrieved context relevance on subsequent answer generation quality.

The Importance of RAG Search Quality Evaluation

RAG systems retrieve relevant information from external databases and pass it to an LLM to generate answers [S3]. Therefore, if the search stage fails to identify highly relevant and focused context, even a powerful LLM will struggle to generate accurate answers [S3]. Evaluating search quality is the first step toward improving the overall performance of the RAG architecture.

Key Search Evaluation Metrics

  1. Recall @k: Measures whether the actual correct answer is included in the top k retrieved results. In other words, it is a metric to confirm whether the necessary information was captured by the search system.
  2. MRR (Mean Reciprocal Rank): Measures the position of the correct answer (relevant document) for a user query within the search result list. The more the relevant document appears in the first position, the closer the MRR value is to 1, resulting in a higher score.
  3. nDCG (normalized Discounted Cumulative Gain): A metric that considers the ranking of search results; it assigns higher scores as more relevant documents are positioned toward the top. It evaluates the ‘ranking accuracy’ of search results more precisely than simple inclusion (Recall).

These metrics are essential for system improvement when ground truth is available, and frameworks like Ragas provide tools to quantitatively analyze these dimensions [S3, S4].

WORKED EXAMPLES

Worked examples

  1. If the system returned results in the order [DocB, DocA, DocC] for a query, and the relevant document is DocA? MRR calculation: Since DocA is at the 2 position, the Reciprocal Rank is 1/2 = 0.5.
  2. When k=3, if the correct answer document is included in the top 3 search results, Recall @3 = 1, and if not included, Recall @3 = 0.

LAB PROTOCOL

Quantitative Measurement of Retrieval Quality Metrics

  1. 1

    Prepare 50 sample data using an evaluation set (questions, correct answer documents).

  2. 2

    Run the retrieval module to receive the top k (k=3, 5, 10) documents for each question.

  3. 3

    Implement the Recall @k, MRR, and nDCG functions directly in Python or use a library to calculate them.

  4. 4

    Organize and visualize the metric results per question into a dataframe.

Safety check
  • Do not send datasets containing personal information or private documents to external APIs.
  • Set API cost limits during experiments and utilize caching to optimize the number of requests.

Lab deliverables

  • A result dataframe CSV containing Recall @k, MRR, and nDCG values for each query.
  • Histogram and boxplot images showing metric distribution

ASSIGNMENT

Retriever Performance Comparison Report

Deliverables

Rubric

  • Were the Recall @k, MRR, and nDCG metrics calculated accurately?
  • Was the difference in retrieval performance interpreted in a statistically significant way?
  • Were failure types classified systematically?

KNOWLEDGE CHECK

Knowledge check

1What is the impact of retrieval step quality on the generation step in a RAG system?
2When is the MRR metric highest?

FIELD CHECK

Completion criteria

  • Completed the Recall @k, MRR, and nDCG calculation code and applied it to sample data.
  • Derived quantitative analysis results by comparing two retrieval strategies.
  • Classified retrieval failure types into at least 3 categories and included them in the report.

MODULE SOURCES

Module sources

  1. [2309.15217] Ragas: Automated Evaluation of Retrieval ... Ragas: Automated Evaluation of Retrieval Augmented Generation RAGAS: Automated Evaluation of Retrieval Augmented Generation RAGAs: Automated Evaluation of Retrieval Augmented Generation RAGAS: Automated Evaluation of Retrieval Augmented Generation RAGAS: Automated Evaluation of Retrieval Augmented Generationarxiv.org · paper
  2. Ragas: Automated Evaluation of Retrieval Augmented Generationarxiv.org · paper