11.4 RAG and Agent Performance Evaluation

Key Takeaways

  • Use retrieve-only and retrieve-and-generate metrics to distinguish discovery from generation failures.
  • Agent success includes correct tools, valid arguments, safe stopping, latency, cost, and business outcome.
  • A plausible final answer can conceal failed or unauthorized tool actions, so inspect task traces and outcomes.
Last updated: September 2026

11.4 RAG and Agent Performance Evaluation

Ragas Framework Deep-Dive (Retrieval Augmented Generation Assessment)

Ragas is an open-source evaluation framework specifically architected to benchmark RAG pipelines using "LLM-as-a-judge" methodologies. Ragas evaluates four core metrics that map directly to the RAG Triad:

                  ┌───────────────────┐
                  │    User Query     │
                  └─────────┬─────────┘
                            │
           Context Precision│▲ Context Recall
                   (Retriever Evaluation)
                            │
                            ▼
                  ┌───────────────────┐
                  │ Retrieved Context │
                  └─────────┬─────────┘
                            │
               Faithfulness │  Answer Relevance
                    (Generator Evaluation)
                            │
                            ▼
                  ┌───────────────────┐
                  │ Generated Answer  │
                  └───────────────────┘

1. Faithfulness (Groundedness)

  • Definition: The ratio of claims made in the generated answer that can be directly verified against the retrieved context.
  • Scoring Process: The evaluator LLM parses the generated answer into discrete atomic claims. For each claim, the evaluator checks if it is logically entailed by the retrieved context chunks.
  • Formula: Faithfulness=∣Number of verifiable claims in answer supported by context∣∣Total claims generated in answer∣\text{Faithfulness} = \frac{|\text{Number of verifiable claims in answer supported by context}|}{|\text{Total claims generated in answer}|}
  • Target: A score approaching 1.0 indicates zero hallucination.

2. Answer Relevance

  • Definition: Measures how pertinent the generated response is to the input query.
  • Scoring Process: Ragas instructs an evaluator model to generate $N$ potential questions based exclusively on the generated answer. It then calculates the mean cosine similarity between the embeddings of the generated questions and the original user query.
  • Key Characteristic: Highly penalizes evasive answers, incomplete responses, or tangential verbosity, even if the answer is factually grounded.

3. Context Precision

  • Definition: Evaluates whether all ground-truth-relevant context chunks are ranked at the very top of the retrieved context list.
  • Calculation: Employs Mean Reciprocal Rank (MRR) and Average Precision principles. If relevant chunks are buried at positions 4 and 5 while positions 1 and 2 contain irrelevant filler, Context Precision drops significantly.
  • Impact: LLMs suffer from the "lost in the middle" phenomenon—information placed at the top or bottom of a context window is recalled far more reliably than information in the middle.

4. Context Recall

  • Definition: Measures whether the retrieved context contains all the necessary information required to answer the prompt, evaluated against a reference ground truth.
  • Formula: Context Recall=∣Number of reference ground-truth sentences attributable to context∣∣Total sentences in reference ground truth∣\text{Context Recall} = \frac{|\text{Number of reference ground-truth sentences attributable to context}|}{|\text{Total sentences in reference ground truth}|}
  • Impact: Reflects the fundamental performance of the retrieval engine (embedding model + vector index).

Diagnostic Matrix: Pinpointing & Fixing RAG Failure Signatures

The true power of Ragas metrics lies in cross-metric diagnostic analysis. By inspecting metric combinations, developers can pinpoint the exact architectural component causing failures and apply targeted AWS remediations:

Diagnostic Metric SignatureRoot Cause AnalysisPrescribed AWS Architectural Remediation
High Context Recall (0.95+)<br/>Low Faithfulness (<0.50)LLM Hallucination: The retriever found all necessary facts, but the generator model ignored the context or fabricated unsupported assertions.1. Attach an Amazon Bedrock Guardrail with Contextual Grounding Checks (grounding threshold $\ge 0.75$).<br/>2. Lower model temperature to 0.0 or 0.1.<br/>3. Refine system prompts to strictly mandate: "Answer only using provided documents. State 'I do not know' if information is missing."
Low Context Precision (<0.40)<br/>High Faithfulness (0.90+)Retrieval Noise: The vector store retrieved too many irrelevant or tangentially related chunks. The model answered correctly from the few good chunks, but latency and token costs are inflated.1. Implement a Reranker Model (e.g., Cohere Rerank on Bedrock) to re-order chunks by relevance.<br/>2. Add Metadata Filtering in Bedrock Knowledge Bases to constrain search scope.<br/>3. Reduce numberOfResults (top-K) parameter.
Low Context Recall (<0.40)<br/>Low Faithfulness (<0.50)Retriever Inadequacy: The retriever failed to locate relevant chunks from the vector database, forcing the LLM to either refuse or hallucinate answers.1. Switch from pure vector search to Hybrid Search (combining dense vector embeddings with sparse BM25 lexical search).<br/>2. Optimize chunking strategy (e.g., transition from fixed-size 300-token chunking to hierarchical or semantic chunking).<br/>3. Upgrade the embedding model (e.g., to Amazon Titan Text Embeddings V2).
High Faithfulness (0.95+)<br/>Low Answer Relevance (<0.40)Model Drift / Prompt Evasion: The model grounded its answer in the context, but failed to address the user's actual question (e.g., returning generic boilerplate or answering a different question).1. Implement automated Query Rewriting or query decomposition prior to retrieval.<br/>2. Provide few-shot exemplar demonstrations in the system prompt illustrating direct answers.<br/>3. Switch to a more capable reasoning foundation model (e.g., Claude 3.5 Sonnet).

[!IMPORTANT] Exam Diagnostic Tip: On the AIP-C01 exam, if a question describes a scenario where "the retrieved passages contain the exact answer, but the model outputs unverified claims not present in the reference documents," the failure is Low Faithfulness (hallucination). The correct architectural fix on AWS is configuring Contextual Grounding Checks in Amazon Bedrock Guardrails, not altering the chunking strategy or vector database.

Native RAG and agent evaluation

Amazon Bedrock RAG evaluation can score retrieve-only behavior separately from retrieve-and-generate behavior. Current built-in concepts include context relevance and coverage for retrieval and correctness, completeness, helpfulness, coherence, faithfulness, citation quality, harmfulness, stereotyping, and refusal for generated responses. Supply ground truth where the selected metric requires it and preserve evaluator-model configuration.

Agent evaluation adds task-level evidence. Measure task completion, correct tool selection, parameter validity, tool success, unnecessary calls, latency, cost, stopping behavior, and the quality of multi-step outcomes. Amazon Bedrock agent evaluations can support managed assessment for eligible agents; custom traces and golden workflows cover application-specific tools. Do not grade an agent only on final prose—a plausible answer can hide a failed or unauthorized action path.

Test Your Knowledge

An engineering team is benchmarking automated customer support response summarization. They need an automated evaluation metric to compare candidate summaries against gold-standard reference summaries. The evaluation must award high scores when the model uses valid synonyms and paraphrased syntax (such as substituting 'terminated the agreement' for 'ended the contract'), while heavily penalizing summaries that omit core reference information. Which metric is best suited for this requirement?

A
B
C
D
Test Your Knowledge

A developer monitoring a Bedrock Knowledge Base application discovers that user queries frequently receive low-quality answers. Ragas evaluation reveals that Context Recall is high (0.92), but Context Precision is very low (0.31). Detailed trace inspection shows that while the single chunk containing the actual answer is retrieved, it is consistently ranked in the fifth or sixth position, buried underneath irrelevant marketing text. Which architectural improvement will directly increase Context Precision?

A
B
C
D