Failures and Fixes in Retrieval-Augmented Generation

Dive into Deep Learning · §19.6

Failures and Fixes in Retrieval-Augmented Generation
one change at a time · failures by stage · a fix chosen in advance · marginalizing over documents · cost

21 Answers Are Wrong, Though Retrieval Finds the Passage for 213 of 220

The problem

  • Baseline: 0.91 of 240 dev questions about this book.
  • 15 of its 20 errors on answerable questions had the passage in context.
  • Favorite repairs: smaller chunks, query rewrites, more context.
  • dev (240 questions) chooses; test (240 more) is read once.

Which repair can help such a system, and how would we know?

By the End of This Deck You Can

Goals

  • predict a perfect retriever’s gain from the share of hits;
  • change one stage at a time, read a paired interval;
  • blame each wrong answer on the first stage that lost it;
  • test a fix written down in advance, once;
  • derive RAG-Sequence, RAG-Token and the retriever’s gradient.

Running example: 240 dev questions; Qwen3.5-9B answers, Qwen3.8-27B judges.

Locating Failures Comes Before Fixing Them

Where this fits

movement section
vectors Word Embeddings
Pretrained Encoders
Text Embeddings
finding Sparse, Dense and Approximate Retrieval
using what is found Retrieval-Augmented Generation
Failures and Fixes in RAG
  • Uses: the question set, judge, baseline and paired intervals of the previous section.
  • Skips: training retriever and generator together (derived, not run); retrieval inside agent loops.

With 213 of 220 Hits, a Perfect Retriever Could Add About 0.02

A prediction before any run

\text{accuracy} = h\, a_1 + (1 - h)\, a_0

  • Hit: the context holds a relevant chunk. h: share of hits, 213/220.
  • a_1 = 0.93 on hits, a_0 = 0.29 on misses.
  • Perfect retriever, a_1 unchanged: (1 - h)(a_1 - a_0) \approx 0.032 \times 0.64 \approx 0.02.

Inside the \pm 0.03 that 240 questions resolve: retrieval has no room here.

Section Chunks Cover More Than Fixed Windows at Small Budgets

Chunking at equal tokens

budget T, 220 questions sections fixed 256/64 fixed − sections
1,000 tokens 0.91 0.86 -0.05 [-0.09, -0.01]
2,000 tokens 0.97 0.95 -0.02 [-0.05, +0.01]
3,000 tokens 0.99 0.97 -0.01 [-0.04, +0.01]

cov@T: the first chunks, up to T tokens, hold half a gold span.

Compare chunkings at equal tokens, not equal k: five sections hold more text than five windows.

No Stage Change Raised Accuracy; Two Lowered It

One change at a time

change, 240 dev questions context tokens accuracy − baseline interval excludes 0
baseline: 5 section chunks, no reranker 1,700
fixed windows 1,600 -0.09 yes
rewrite + rerank top 50 (two changes) 1,700 -0.01 no
reverse order 1,700 -0.01 no
budget 1,500, no 5-chunk limit 1,300 -0.06 yes
budget 6,000, no 5-chunk limit 5,800 +0.01 no

Baseline ranking: BM25 and dense, fused by reciprocal ranks.

As predicted for retrieval; and three times the text did not help the generator either.

The Cut, Not the Token Count, Cost Fixed Windows Their Accuracy

A control

arm context tokens accuracy − baseline
fixed windows, up to the baseline’s tokens 1,600 -0.09
control: windows just past the baseline’s tokens 1,800 -0.05
  • Coverage near these budgets trails by 0.02 to 0.05: worth at most 0.01 to 0.03 of accuracy.
  • Coverage counts half a span; a window can cut off the key fact.

Chunks that follow the text’s structure give better answers.

Each Wrong Answer Is Blamed on the First Stage That Lost It

Failures by stage

class condition, checked in this order of 21 answer cites a relevant chunk
false answer unanswerable, yet answered 1 0
not retrieved no relevant chunk in the top 50 0 0
ranked low in the top 50, not in the context 5 0
false abstention in the context, answer abstains 0 0
ignored in the context, faithful, misses a key fact 8 5
unsupported in the context, not faithful 7 7

Ignored 0.38 [0.19, 0.57], unsupported 0.33 [0.14, 0.52]: 21 failures cannot rank the two.

Fixes Are Written Down Before Any Failure Is Counted

Pre-registration

class its fix
not retrieved rewritten query as a third ranking
ranked low rerank the top 100, pass 8 chunks
ignored quote, then answer; best passages at both ends; 500 new tokens
unsupported drop sentences their citations do not support
false answer abstain below a reranker score tuned on train
false abstention abstention rule after the passages

A rule picks the largest class and carries the largest stage gain to test, read once: with the earlier 8-bit judge, unsupported and reverse order.

Check: The Largest Stage Gain on Dev Is Two Verdicts. What Will Test Show?

Check

Reverse order led on dev by two verdicts of 240 under the 8-bit judge’s verdicts. The rule carried it to test. Under the 4-bit judge’s it is -0.008 and the 6,000-token budget leads instead.

Answer. +0.004, interval -0.03 to +0.04: noise again. Picking the largest of near-equal numbers picks noise.

A Second Labeler Confirms Most Ignored Answers and Few Unsupported Ones

A second labeler

Claude Opus 5.5 labeled the cards of the 21 failures.

the labeler failures
agrees with the rule 12
calls the answer correct 4
blames another stage 5

Of the 4: in 3 the judge insists on a key fact the labeler finds stated; 1 unanswerable question was declined in other words. The labeler confirms 6 of 8 ignored answers, but only 2 of 7 unsupported ones.

The Answering Passage Was Ranked First, and the Answer Ignored It

One failure

Q. What happens to PyTorch modules kept in a plain Python list?

  • Passage [1] ends: “Modules in a plain list stay unregistered, without any warning.”
  • The answer cites [2] and [3] and never says that nothing warns.

Neither missing nor contradicted. Ignored, say the rule and the labeler; and the missing fact is the one a user needs.

Both Fixes Chosen in Advance Lowered Accuracy

Quote first; check each cited sentence

accuracy − baseline quote, then answer (ignored) sentence check (unsupported)
dev -0.08 [-0.14, -0.04] -0.15 [-0.19, -0.10]
test, read once not read -0.09 [-0.14, -0.04]
  • Baseline: 0.91 on dev, 0.86 on test.
  • The sentence check raised citation precision (+0.02 dev, +0.04 test): it did what it was built for.
  • test was read once, with the earlier judge’s choice; the rule’s new choice runs on dev only.

Each Fix Filled Classes Other Than the One It Aimed At

Where the failures went

dev answers baseline quote first sentence check
correct 219 199 184
ranked low 5 6 5
ignored 8 17 31
unsupported 7 5 6
false answer 1 13 0
false abstention 0 0 14
  • Quote first: the aimed-at class doubled, and 13 of 20 unanswerable questions were answered.
  • Sentence check: uncited sentences dropped unread; empty answers abstain.

Test a fix’s mechanism with the habits of the model it acts on. Never search for a better fix on the same data.

On Test, Every Difference from the Baseline Agrees with Dev

The results at a glance

Left: share of dev answers per class. Right: dev scores with 95% intervals; crosses are test, read once. Closed: no passages.

The Original RAG Treats the Retrieved Document as a Hidden Variable

From pipeline to model

  • Our pipeline: retrieve, concatenate, read. The retriever is never told whether the generator could use a passage.
  • RAG: the generator reads one document z at a time; the answer’s probability sums over documents, weighted by the retriever’s p(z \mid x).

Then the answers alone give the retriever a gradient.

Check: Which Is Larger, RAG-Sequence or RAG-Token?

Two marginalizations

Question x, answer y_1 \ldots y_n, document z with retriever probability p(z \mid x):

p_S = \sum_z p(z \mid x) \prod_t p(y_t \mid x, z, y_{<t})

p_T = \prod_t \sum_z p(z \mid x)\, p(y_t \mid x, z, y_{<t})

Two documents, p(z \mid x) = (0.6, 0.4); token probabilities (0.9, 0.2) and (0.1, 0.8).

Answer. p_S = 0.140, p_T = 0.2552: each document supports half the answer, and only RAG-Token combines the halves.

Keeping the Top k Documents Loses at Most the Mass Outside Them

Truncation

L_z = p(y \mid x, z); \mathcal{K}: the k documents of largest p(z \mid x); m_k: their total probability.

0 \le p_S - p_S^{(k)} \le (1 - m_k) \max_z L_z

  • Eight random documents, k = 5: lost 0.028, bound 0.037.

A peaked retriever loses little; one that spreads its mass can lose much, however good its ranking.

The Retriever Learns What the Generator Uses, Not What Is Relevant

Training signal

With p(z \mid x) = \mathrm{softmax}(\mathbf{s})_z:

\frac{\partial \log p_S}{\partial s_z} = \underbrace{\frac{p(z \mid x) L_z}{p_S}}_{\text{posterior}} - \underbrace{p(z \mid x)}_{\text{prior}}

  • Score rises if L_z > p_S, the average; falls otherwise. No relevance label needed. Checked against autograd to within 10^{-16}.

Generator ignores every document: no signal. Ignores one relevant passage that others outdo: that passage is pushed down.

First-Stage Retrieval Costs Milliseconds; Reranking and Long Prompts Cost Seconds

Cost

per question prompt tokens seconds
retrieval 0.03
rerank 50 chunks (not in the baseline) 0.5
closed book 90 0.8
baseline 1,900 1.2
budget 6,000 6,300 2.6
fix: check each sentence (answer only) 1,900 1.2

Qwen3.5-9B on one RTX 4090, batches of 8 (4 at 6,000 tokens); retrieval and reranking one question at a time.

Check: With 70% Hits, What Could a Perfect Retriever Add?

Check

Another collection: a relevant chunk reaches the context for 70% of the questions; accuracy 0.9 on hits, 0.2 on misses.

\text{accuracy} = h\, a_1 + (1 - h)\, a_0

Answer. 0.3 \times 0.7 = 0.21, ten times our 0.02. There, fix retrieval first.

Recap

Recap

  • 213 of 220 hits: about 0.02 to gain; no stage change helped measurably.
  • Fixed windows -0.09, and -0.05 even with more tokens than the baseline: the cut costs accuracy. Budget 1,500: -0.06.
  • Largest class: ignored, 8 of 21, beside unsupported, 7: too few to rank.
  • Both fixes chosen in advance lost: quoting -0.08 on dev; the sentence check -0.15 on dev and -0.09 on test.
  • Gradient = posterior − prior: the retriever learns what the generator uses.

Next: Whole Chapters in the Context, or Retrieval on Demand

Next

Three times the context gained nothing measurable at twice the time. Would whole chapters in a 32,000-token context beat retrieval on questions that need several passages? Agents take a third path: they retrieve when they decide they need to.