Lesson 2 of 2 Hybrid Search and RAG Evaluation

Evaluating and A/B Testing RAG Systems

This lesson explains how RAG systems are evaluated offline, how failures are analyzed, and how A/B tests confirm improvements with real users.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe offline evaluation of retrieval and generation.
  • Classify RAG failures.
  • Describe the design of an A/B test.
  • Explain why significance is checked before switching.

Offline evaluation of RAG

Offline evaluation measures a configuration on a labelled dataset before any user sees it. It evaluates the two halves of RAG separately, because a combined score cannot tell the team where to work.

HalfMetricsNeeds
RetrievalDocument retrieval evaluator (NDCG, precision and related measures), recall at k, MRR, the AI-assisted retrieval evaluatorQueries with labelled relevant documents, or a judge model
GenerationGroundedness, relevance, response completeness, similarity or F1 against ground truthQueries, retrieved context, responses, and ground truth where used
EfficiencyPrompt tokens, latency, cost per queryTraces or usage data

Running the same dataset against the baseline and the candidate, and comparing per-row results as well as averages, shows which questions improved and which regressed, which is more useful than a single number.

Failure analysis

Low-scoring rows are grouped by cause. A simple classification already directs the work: retrieval misses (the relevant document was not retrieved), ranking problems (it was retrieved but too low to be used), generation errors (it was used but the answer was wrong or unsupported), content gaps (no document contains the answer) and dataset issues (the label was wrong).

Each group has a different fix: retrieval and ranking problems call for retrieval tuning, generation errors for prompt changes, content gaps for new documents or a better refusal, and dataset issues for correcting the labels. The proportions also show where effort pays off most.

A/B testing design

Offline datasets cannot capture everything real users do. An A/B test compares the current configuration (A, the control) with a candidate (B) on live traffic. Each user is assigned to one variant randomly and consistently, for example by hashing the user ID, so that the same user always sees the same variant and the groups are comparable.

  1. Define the hypothesis and metrics

    For example, hybrid search increases the share of answered questions without raising escalations.

  2. Set guardrail metrics

    Metrics that must not get worse, such as latency, cost per query and safety defects.

  3. Size the test

    Estimate the users or sessions needed to detect the expected difference.

  4. Split traffic

    Assign users with a feature flag variant, such as Azure App Configuration variant feature flags, or at a gateway.

  5. Collect metrics per variant

    Tag traces and feedback events with the variant.

  6. Analyse and decide

    Check statistical significance before declaring a winner.

Online metrics and significance

Online metrics reflect user outcomes, which offline metrics approximate. Typical RAG metrics include explicit feedback (thumbs up or down), task success such as the share of conversations that end without escalation to a human, follow-up rate (users rephrasing the same question), citation clicks, plus continuous evaluation scores, latency and tokens for each variant.

A difference between variants can be chance. A statistical test appropriate to the metric, such as a two-proportion test for rates, tells whether it is significant at the chosen level, and the test should run for its planned duration rather than stop as soon as the result looks good, which inflates false positives. A winning candidate then becomes the new control, rolled out to everyone gradually.

Offline evaluation
DataA labelled, fixed dataset
Speed and costMinutes to hours, cheap
MeasuresRetrieval and answer quality against labels
Choose when Every change, before users see it
A/B test
DataLive user traffic
Speed and costDays to weeks, exposes users
MeasuresUser outcomes and real behaviour
Choose when Changes that pass offline and affect user experience
Worked example

Proving a retrieval change

Offline evaluation shows that semantic reranking with a threshold raises groundedness from 3.8 to 4.3 on the regression dataset. The product owner wants evidence that it also reduces escalations to human agents, currently 14 percent of conversations, before enabling it for all 200,000 monthly users. Latency must not increase by more than 300 ms at P95.

Run an A/B test: assign users consistently to the control or the reranking variant with a variant feature flag, tag traces and conversation outcomes with the variant, and use escalation rate as the primary metric with P95 latency and cost as guardrails. Size the test to detect the expected reduction, run it for the planned period, and roll out only if the reduction is statistically significant and the guardrails hold.

Enabling reranking for everyone on the strength of the offline result skips the product owner's requirement. Comparing this week's escalations with last week's mixes the change with other differences between the weeks. Asking a few users for their opinion is not a measurement.

Check yourself

Why must users be assigned to A/B test variants consistently, rather than per request?

Show answer

Consistent assignment gives each user one experience, so outcomes such as satisfaction and task completion can be attributed to one variant, and multi-turn conversations do not mix variants.

Exam Tips

Remember for the exam

  • Evaluate retrieval and generation separately; compare per-row results, not just averages.
  • Group failures into retrieval misses, ranking problems, generation errors, content gaps and dataset issues.
  • A/B tests assign users randomly and consistently, with primary and guardrail metrics.
  • Check statistical significance over the planned duration before switching.