Skip to main content
Evaluation helps you measure the quality of your RAG pipeline and identify areas for improvement. LlamaIndex provides evaluators for faithfulness, relevancy, and correctness.

Overview

All evaluators implement the BaseEvaluator interface:
Evaluators return an EvaluationResult:

Faithfulness

What it measures: Whether the response is grounded in the provided context. Faithfulness checks if the answer contains hallucinations or makes claims not supported by the source documents.

Evaluate Response Objects

Directly evaluate query engine responses:

Custom Prompts

Relevancy

What it measures: Whether the response actually answers the question. Relevancy checks if the response addresses the user’s query.

How It Works

Relevancy uses an LLM to determine if the response answers the question:
  1. Formats query and response together
  2. Queries a SummaryIndex of the contexts
  3. LLM answers “yes” or “no”
  4. Returns score (1.0 for yes, 0.0 for no)

Correctness

What it measures: How correct the response is compared to a reference answer. Correctness requires a reference (ground truth) answer:

Score Scale

Correctness uses a 1-5 scale:
  • 5 - Perfect match
  • 4 - Correct with minor differences
  • 3 - Partially correct
  • 2 - Mostly incorrect
  • 1 - Completely incorrect

Custom Parser

Parse LLM responses differently:

Batch Evaluation

Evaluate multiple queries:

Rate Limiting

Avoid API rate limits:

Evaluation Pipeline

Create a comprehensive evaluation workflow:

Best Practices

Test Set Creation:
  • Create diverse test cases covering different query types
  • Include edge cases and common failure modes
  • Use real user queries when possible
  • Maintain reference answers for correctness evaluation
Metric Selection:
  • Faithfulness - Critical for preventing hallucinations
  • Relevancy - Ensures responses answer the question
  • Correctness - Requires reference answers, best for regression testing
Iteration:
  1. Establish baseline scores
  2. Make changes (prompts, retrievers, etc.)
  3. Re-run evaluation
  4. Compare scores to baseline
  5. Keep improvements, discard regressions
Performance:
  • Run evaluations in parallel when possible
  • Cache LLM responses to avoid redundant calls
  • Use rate limiting to avoid API errors

Next Steps

Postprocessors

Improve retrieval quality with filtering and reranking

Memory

Manage conversation context and history