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
The problem
dev questions about this book.dev (240 questions) chooses; test (240 more) is read once.Which repair can help such a system, and how would we know?
Goals
Running example: 240 dev questions; Qwen3.5-9B answers, Qwen3.8-27B judges.
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 |
A prediction before any run
\text{accuracy} = h\, a_1 + (1 - h)\, a_0
Inside the \pm 0.03 that 240 questions resolve: retrieval has no room here.
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.
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.
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 |
Chunks that follow the text’s structure give better answers.
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.
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
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
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.
One failure
Q. What happens to PyTorch modules kept in a plain Python list?
Neither missing nor contradicted. Ignored, say the rule and the labeler; and the missing fact is the one a user needs.
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] |
dev, 0.86 on test.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.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 |
Test a fix’s mechanism with the habits of the model it acts on. Never search for a better fix on the same data.
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.
From pipeline to model
Then the answers alone give the retriever a gradient.
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.
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
A peaked retriever loses little; one that spreads its mass can lose much, however good its ranking.
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}}
Generator ignores every document: no signal. Ignores one relevant passage that others outdo: that passage is pushed down.
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
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
dev; the sentence check -0.15 on dev and -0.09 on test.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.