LLMs & GenAI

Evaluating a RAG Pipeline

Evaluating retrieval and generation component quality using the RAG Triad framework.

🔴 advanced5 min readragevaluation
Evaluating a RAG Pipeline requires disentangling Retrieval performance from LLM Generation performance. The RAG Triad framework (Ragas / TruLens) measures three core dimensions: Context Relevance (evaluating whether vector search retrieved accurate context chunks), Groundedness / Faithfulness (evaluating whether the LLM answer is supported by retrieved context), and Answer Relevance (evaluating whether the LLM answered the user question).

Disentangling RAG Evaluation

When a user complains that a RAG pipeline gave a bad answer, where did the system fail?

  1. Did Retrieval Fail? Vector search fetched irrelevant, noisy document chunks.
  2. Did Generation Fail? Vector search fetched perfect chunks, but the LLM hallucinated or ignored the context.

To fix RAG systems, you must evaluate Retrieval and Generation separately.

The RAG Triad Framework (Ragas / TruLens) provides automated metrics for both components:

                              THE RAG TRIAD
                               User Query
                                ╱     ╲
            Context Relevance  ╱       ╲  Answer Relevance
                              ▼         ▼
                      Retrieved Context ──► Generated Answer
                              Groundedness / Faithfulness

The RAG Triad Metrics

┌──────────────────────────┬──────────────────────────┬──────────────────────────┐
│ 1. CONTEXT RELEVANCE     │ 2. GROUNDEDNESS          │ 3. ANSWER RELEVANCE      │
├──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ Evaluates RETRIEVAL.     │ Evaluates GENERATION.    │ Evaluates ALIGNMENT.     │
│ "Are the retrieved       │ "Is every claim in the   │ "Does the generated      │
│ chunks relevant to the   │ answer supported by the  │ response directly answer │
│ user query?"             │ retrieved context?"      │ the user question?"      │
└──────────────────────────┴──────────────────────────┴──────────────────────────┘

1. Context Relevance (Retrieval Score)

Measures the proportion of sentences in the retrieved context chunks that are directly relevant to the user query:

$$\text{Context Relevance} = \frac{|\text{Sentences in Chunks Relevant to Query}|}{|\text{Total Sentences in Chunks}|}$$

2. Groundedness / Faithfulness (Hallucination Score)

Measures whether every factual statement in the LLM answer can be inferred directly from the retrieved context:

$$\text{Groundedness} = \frac{|\text{Claims in Answer Supported by Context}|}{|\text{Total Claims in Answer}|}$$

3. Answer Relevance (Intent Alignment)

Measures whether the generated response directly addresses the user query:

$$\text{Answer Relevance} = \text{CosineSim}\left( \text{Embed}(\text{User Query}), ; \text{Mean}(\text{Embed}(\text{Generated Questions})) \right)$$

Evaluating RAG in Production (Ragas / TruLens)

Automated RAG evaluation tools (Ragas, TruLens, DeepEval) use an LLM-as-a-Judge (GPT-4) to compute RAG Triad scores continuously on real production telemetry logs:

from ragas import evaluate
from ragas.metrics import context_relevance, faithfulness, answer_relevancy

results = evaluate(
    dataset=rag_telemetry_dataset,
    metrics=[context_relevance, faithfulness, answer_relevancy]
)

print(results)
# Output: {'context_relevance': 0.88, 'faithfulness': 0.96, 'answer_relevancy': 0.92}

Say this out loud

Evaluating RAG requires separating Retrieval from Generation using the RAG Triad framework. Context Relevance evaluates if vector search retrieved relevant chunks. Groundedness checks if LLM answer claims are supported by context to catch hallucinations. Answer Relevance checks if the output directly answers the user question.

Followups to expect

  1. What is Noise Sensitivity in RAG? Evaluating how gracefully an LLM handles irrelevant background sentences inside retrieved context chunks without being distracted into wrong answers.
  2. What is Negative Rejection in RAG? Testing whether the RAG pipeline correctly outputs "I cannot answer based on provided context" when vector search fails to retrieve relevant document chunks.

Check yourself

Question 1 of 3

What are the three core evaluation dimensions comprising the RAG Triad framework in Ragas?

More in LLMs & GenAI

See all →
Pretraining → SFT → RLHF5 minFine-Tune vs RAG vs Prompt: Choosing5 minRetrieval-Augmented Generation5 min