1. RAG Evaluation Metrics
To measure RAG performance, systems are evaluated across two halves of the pipeline:1.1 Retrieval Metrics
Retrieval metrics evaluate the quality of the documents fetched from the vector database:- Context Recall: Measures if the retriever found all the necessary facts required to answer the user query.
- Context Precision: Measures if the retrieved text chunks are highly relevant, minimizing noise and distractors.
1.2 Generation Metrics
Generation metrics evaluate the quality of the LLM’s synthesized response based on the retrieved context:- Faithfulness (Groundedness): Measures if the generated response is based only on the retrieved context, indicating the absence of hallucinations.
- Answer Relevance: Measures if the response directly addresses the user’s question, rather than introducing irrelevant topics.
2. Evaluation Frameworks
In production environments, developers automate these evaluations using specialized LLM-as-a-judge frameworks:- Ragas: An open-source framework specifically designed for evaluating RAG pipelines, offering built-in metrics for precision, recall, and faithfulness.
- TruLens: An evaluation tool that uses a “Feedback Functions” paradigm to track and score RAG triad metrics over time.
3. Practice Exercises
Practice 1: Identifying RAG Failure Modes
Identify which evaluation metric is failing in the following scenarios:- The LLM answers a query by fabricating customer support numbers that were not present in the retrieved policy documents.
- A user asks about office hours, but the retriever returns documents about reimbursement guidelines, leading to a generic “I don’t know” answer.
Solution
Solution
- Faithfulness (Groundedness) is failing because the model is hallucinating information outside of the provided context.
- Context Recall is failing because the database retriever failed to locate and return the correct document chunks regarding office hours.
Summary
- RAG Evaluation Stages: Divided into Retrieval (evaluating document relevance) and Generation (evaluating LLM response quality).
- Key Metrics:
- Context Recall: Finding all necessary facts.
- Context Precision: Avoiding irrelevant text chunks.
- Faithfulness: Grounding answers in the context to prevent hallucinations.
- Answer Relevance: Directly addressing the query.
- Frameworks: Tools like Ragas and TruLens automate evaluations using LLMs to score pipeline quality.