About What I Do Selected Work Methodology Experience Resume Contact Let's Talk →
Back to Selected Work
RAG EVALUATION Independent Portfolio Demonstration

RAG Pipeline Evaluation & Faithfulness Auditing

An end-to-end evaluation benchmarking vector retrieval precision, passage-level attribution, and answer groundedness across an enterprise technical infrastructure knowledge base.

ARCHITECTURE Retrieval-Augmented Generation (Vector Search + LLM)
EVALUATION METRICS Context Relevance · Faithfulness · Answer Relevance
FAILURE MODE FOCUS Distractor Chunk Contamination & Hallucinated Extrapolation
EVALUATOR Fikri Irawan Abdurahman (15+ Yrs Enterprise Data QA)
01

Test Inquiry & Retrieved Context Chunks

Auditing a RAG assistant deployed to answer cloud engineering disaster recovery compliance inquiries.

USER INQUIRY Task: Retrieve Tier-1 Database SLA Constraints
“What is the mandatory backup retention policy and maximum permissible RPO and RTO for Tier-1 financial transaction databases under the 2026 Disaster Recovery standard?”
Chunk 1

Retrieved Context (Rank 1 · Relevant)

[DOC-SEC-2026-T1]: “Tier-1 Financial Transaction Databases (PostgreSQL Core, Oracle Ledger) must maintain automated continuous WAL transaction log archiving. Mandatory point-in-time recovery (PITR) retention is exactly 35 calendar days on live encrypted storage. Maximum permissible Recovery Point Objective (RPO) is ≤ 5 minutes.”

Chunk 2

Retrieved Context (Rank 2 · Distractor Chunk)

[DOC-SEC-2026-T2]: “Tier-2 Analytical & Reporting Data Marts must perform daily differential snapshots with a 14-day retention cycle. Maximum permissible RPO is ≤ 4 hours, and maximum permissible Recovery Time Objective (RTO) is ≤ 24 hours.”

Chunk 3

Retrieved Context (Rank 3 · Cold Storage)

[DOC-SEC-2026-ARCHIVE]: “Annual regulatory compliance archives for all database tiers must be replicated to immutable WORM cold storage vaults with a mandatory 7-year retention horizon.”

Evaluator Diagnostic Note: Notice that while Chunk 1 contains the Tier-1 retention policy (35 days) and RPO (≤ 5 minutes), **it does NOT contain an RTO specification**. The RTO specification (≤ 24 hours) exists only in Chunk 2 for Tier-2 databases. A faithful generator must explicitly acknowledge that Tier-1 RTO is absent from the retrieved passages rather than extrapolating or conflating Tier-2 metrics!
02

Candidate Generator Outputs

Testing two generator implementations against identical retrieved contexts.

Generator Output A (Faithful & Calibrated) 100% Grounded
“Under the 2026 Disaster Recovery standard [DOC-SEC-2026-T1]:

• Backup Retention: Mandatory continuous WAL transaction log archiving with a 35-calendar-day point-in-time recovery (PITR) retention policy on encrypted live storage (with annual archives stored for 7 years in immutable vaults [DOC-SEC-2026-ARCHIVE]).
• Recovery Point Objective (RPO): Maximum permissible RPO is ≤ 5 minutes.

Documentation Gap Note: The provided documentation specifies an RTO (≤ 24 hours) strictly for Tier-2 reporting systems [DOC-SEC-2026-T2]. The maximum permissible Recovery Time Objective (RTO) for Tier-1 transaction databases is not specified in the retrieved passages and requires confirmation from the Cloud Infrastructure SLA appendix.”
Generator Output B (Unfaithful & Hallucinated) Contaminated with Distractor Chunks
“For Tier-1 financial transaction databases under the 2026 Disaster Recovery standard:

• The backup retention policy requires [Claim 1: daily differential snapshots with a 14-day retention cycle].
• The maximum permissible Recovery Point Objective (RPO) is [Claim 2: ≤ 5 minutes].
• The maximum permissible Recovery Time Objective (RTO) is [Claim 3: ≤ 24 hours].
• In addition, industry best practices dictate that Tier-1 databases [Claim 4: must maintain active-active multi-region failover with zero seconds RTO].”
03

Decoupled RAG Evaluation: Retriever vs. Generator Scorecards

Disentangling whether pipeline defects originate in vector search or text generation.

GOLD EXPECTED GROUND TRUTH (BENCHMARK TARGET) Strict Faithfulness & Absence Handling
• Tier-1 Retention: Continuous WAL log archiving + 35-day Point-in-Time Recovery (PITR) on encrypted live storage (7-year annual archive in immutable vaults).
• Tier-1 RPO: ≤ 5 minutes.
• Tier-1 RTO: ABSENT FROM RETRIEVED CONTEXT. Target behavior is explicit abstention (stating Tier-1 RTO is unprovided and noting that ≤ 24h applies only to Tier-2 systems). Any numerical assertion for Tier-1 RTO is a hallucination defect.

1. Retriever Component Scorecard (Context Quality)

Retriever Metric Observed Score Diagnostic Telemetry
Context Precision@3 66.7% (2 / 3 Chunks) Chunk 1 (Tier-1) & Chunk 3 (Archive) relevant. Chunk 2 was an adjacent distractor.
Context Recall Partial (66.7%) Corpus contained Tier-1 Retention and RPO; Tier-1 RTO chunk was missing from vector index.
Distractor Contamination 33.3% (Chunk 2) Dense embedding similarity between "Tier-1" and "Tier-2" caused distractor retrieval.
Mean Reciprocal Rank (MRR) 1.0 (Rank 1 Hit) Primary relevant policy chunk correctly placed at rank 1 in the context window.

2. Generator Component Scorecard (Comparative Generation Quality)

Generator Metric Generator A (Calibrated) Generator B (Ungrounded)
Faithfulness / Groundedness Ratio of claims entailed by context 100% (3 / 3 Claims Grounded)

Every asserted fact is directly cited and verifiable in Chunk 1 or Chunk 3. Refused to hallucinate missing RTO.

25% (1 / 4 Claims Grounded)

Critical grounding failure: Conflated Tier-2 snapshot retention (14 days) and Tier-2 RTO (24 hours) with Tier-1. Hallucinated active-active multi-region failover from pre-training memory.

Abstention Correctness Handling of missing Tier-1 RTO PASS (Explicit Abstention)

Proactively notes that Tier-1 RTO is unprovided in context; cautions against confusing with Tier-2 RTO.

FAIL (Confabulation)

Silently borrowed Tier-2 24h RTO and hallucinated "zero seconds RTO" failover from outside weights.

Answer Relevance Direct alignment to inquiry 100% — Direct Alignment

Answers retention and RPO cleanly, while flagging documentation gaps to prevent operational misconfiguration.

50% — Erroneous Alignment

Appears complete on the surface, but provides false metrics that would cause a regulatory audit failure.

Citation Fidelity & Completeness Exact grounding to source chunks 100% (2 / 2 Chunks Attributed)

Accurate bracketed citations [DOC-SEC-2026-T1] matching ground-truth chunks.

0% (Unattributed / False Source)

No chunk citations provided; fabrications passed off as authoritative system knowledge.

EVALUATION DECISION ACCEPTED FOR PRODUCTION REJECTED (CRITICAL DEFECT)

3. Decoupled 4-Quadrant RAG Failure Triage Matrix

Systematic classification isolating retrieval defects from generative hallucinations.

Retrieval Evaluation Generator Evaluation Failure Classification Root-Cause & Remediation
Correct Retrieval Correct Generation PASS (ROBUST SYSTEM) Optimal pipeline performance. Both vector index and prompt alignment succeeded.
Correct Retrieval Hallucinated Answer GENERATOR FAILURE Retriever delivered facts; generator ignored context or suffered pre-training drift. Remediate with prompt clamping and context constraints.
Wrong Retrieval Faithful Generation RETRIEVER FAILURE Generator faithfully summarized retrieved chunks, but retriever pulled incorrect documents. Remediate chunking, re-ranking, and embeddings.
Wrong Retrieval Hallucinated Answer COMPOUND FAILURE Both sub-systems failed. Retriever pulled noisy distractors and generator manufactured ungrounded fabrications.

4. 25-Question Evaluation Benchmark Suite Taxonomy

To guard enterprise RAG pipelines against silent drift, test suites must cover six distinct query archetypes:

Query Archetype Test Questions Target Evaluation Metric Failure Risk Addressed
Direct Fact Extraction 5 Questions Context Precision@K, Faithfulness Basic factual recall across standard single-chunk lookups.
Multi-Document Synthesis 5 Questions Cross-Chunk Recall, Coreference Fidelity Correctly synthesizing information split across multiple disparate policy documents.
Missing / Unanswerable Info 5 Questions Abstention Correctness, Hedging Rate Preventing confabulation when query variables do not exist in the corpus.
Conflicting / Stale Documents 4 Questions Temporal Grounding, Superseded Chunk Filter Ensuring pipeline prefers newer revisions over outdated archived records.
Distractor-Heavy Noise 3 Questions Semantic Discrimination, Noise Rejection Testing generator resistance when dense embeddings retrieve semantically close but irrelevant chunks.
Access-Controlled / Scoped Info 3 Questions Metadata Filter Precision, Scope Abstention Ensuring pipeline respects document tenant and role-based ACL boundaries.
AUTOMATED PYTHON RAG EVALUATION SCRIPT (rag_faithfulness_evaluator.py) Production QA Assertion Engine
from dataclasses import dataclass
from typing import List, Dict, Optional

@dataclass
class RetrievedChunk:
    chunk_id: str
    text: str
    relevance_score: float
    is_ground_truth: bool

@dataclass
class RAGEvalMetrics:
    context_precision: float
    context_recall: float
    faithfulness_score: float
    abstention_correct: bool
    citation_accuracy: float

class RAGPipelineEvaluator:
    """Evaluates RAG retriever precision and generator faithfulness against gold ground truth."""
    def __init__(self, retrieved_chunks: List[RetrievedChunk], gold_facts: List[str], unanswerable_keys: List[str]):
        self.chunks = retrieved_chunks
        self.gold_facts = gold_facts
        self.unanswerable = unanswerable_keys

    def evaluate(self, generated_response: str, cited_chunk_ids: List[str]) -> RAGEvalMetrics:
        # 1. Retriever Precision@K: Ratio of retrieved chunks that are true gold sources
        true_positives = sum(1 for c in self.chunks if c.is_ground_truth)
        precision = true_positives / len(self.chunks) if self.chunks else 0.0
        recall = 1.0 if true_positives >= len(self.gold_facts) else (true_positives / len(self.gold_facts))

        # 2. Generator Abstention Check: Did model explicitly refuse unanswerable variables?
        refused_missing = all(
            key.lower() in generated_response.lower() and ("not provided" in generated_response.lower() or "absent" in generated_response.lower())
            for key in self.unanswerable
        )

        # 3. Citation Fidelity: Are citations pointing strictly to retrieved ground-truth chunks?
        valid_citations = sum(1 for cid in cited_chunk_ids if any(c.chunk_id == cid and c.is_ground_truth for c in self.chunks))
        citation_acc = valid_citations / len(cited_chunk_ids) if cited_chunk_ids else 0.0

        return RAGEvalMetrics(
            context_precision=precision,
            context_recall=recall,
            faithfulness_score=1.0 if (refused_missing and citation_acc >= 0.8) else 0.25,
            abstention_correct=refused_missing,
            citation_accuracy=citation_acc
        )
04

Deep Evaluator Reasoning & Defect Triage

Analyzing why vector search contaminations cause downstream generator hallucinations.

GENERATOR A ANALYSIS

Why Generator A Succeeded

  • Context Disambiguation: Successfully discriminated between Tier-1 specifications in Chunk 1 and Tier-2 specifications in Chunk 2 despite embedding proximity.
  • Epistemic Honesty: When an inquiry asks for a variable (RTO) that does not exist in the retrieved knowledge base, the model correctly exercised refusal/hedging rather than manufacturing a plausible number.
  • Audit Attribution: Inline chunk citations ([DOC-SEC-2026-T1]) enable downstream automated citation checking.
GENERATOR B ANALYSIS

Why Generator B Failed

  • Cross-Chunk Entity Leakage: The generator suffered from entity confusion, mapping the Tier-2 14-day snapshot and 24-hour RTO onto Tier-1 systems.
  • Pre-training Knowledge Bleed: When the model noticed missing information regarding RTO, it reached into its pre-training weights and hallucinated "active-active multi-region failover".
  • Enterprise Impact: A cloud engineer deploying infrastructure based on Generator B would architect a 14-day backup window instead of 35 days, violating statutory banking regulations.
05

Evaluator Takeaway: Quality Architecture for Enterprise RAG

QA recommendations for decoupling retriever failures from generator failures.

RAG QUALITY ENGINEERING STANDARD Vector Pipeline Quality Assurance Perspective

When diagnosing RAG defects, **an evaluator must isolate whether the bug occurred in the Retriever or the Generator**:

1. Disentangle Retrieval from Generation

If the correct chunk is never retrieved (Context Precision failure), the generator cannot possibly answer correctly. Test the retriever independently using Mean Reciprocal Rank (MRR) and Hit Rate@K.

2. Automated NLI Entailment Checking

Implement Natural Language Inference (NLI) scoring where every sentence in the generator's response is evaluated as a premise/hypothesis against the retrieved chunks. Flag non-entailed sentences as potential hallucinations.

3. Explicit Absence Prompting

System prompts must instruct: “If the answer cannot be determined with certainty strictly from the provided context chunks, explicitly state what information is missing.”