Memorized Answers Versus Retrieved Rules in Domain RAG

When a language model is given the right textbook theorem or the right regulation in its prompt and still answers a specialist question wrongly, we usually conclude one of two things. Either it cannot apply knowledge it has been handed, or it ignored the handed knowledge in favour of what it already "believes." These two diagnoses call for opposite fixes, and current evaluations cannot tell them apart. The reason is benchmark contamination: the test questions themselves have leaked onto the web and into the model's training data. On a leaked question, the model can produce the right answer from memory whether or not it reads the retrieved document. Aggregate accuracy then says little about whether retrieval helped.

We propose a simple instrument that separates the two. Take each question from a static domain benchmark and build a counterfactual twin. The twin keeps the same problem type, the same governing rule and roughly the same difficulty, but its numbers or its referenced document facts are changed so that the memorized answer is now wrong. We then supply retrieved context that is correct for the twin. On twins, any output that matches the original answer is direct evidence that memory overrode the context. The gap between retrieval gains on originals and on twins measures how much contamination hides or fakes the benefit of retrieval-augmented generation (RAG), meaning systems that fetch documents and place them in the prompt before answering. We use the same pairs to test, inside open-weight models, which internal mechanism produces the override.

Core Claim

Our central, falsifiable claim concerns a well-known null result. The finding in TheoremQA that injecting theorem definitions "did not provide a significant performance boost" is partly an artifact of contamination-driven recall, not only a failure to apply rules. If this is right, theorem injection should produce a measurably larger gain on counterfactual twins than on the original items. Where it still fails on twins, the failure should split into two separable patterns. In the first, the model locates the right context but its parametric memory drowns it out. In the second, it never locates the context at all. TheoremQA's authors read their result as a failure of application. ReDeEP found the other pattern in open-domain RAG: in 65–77% of hallucinations the attention heads located the correct context, but later feed-forward layers "over-added" stored knowledge. Neither paper can adjudicate between the two readings. TheoremQA used static, possibly memorized items. ReDeEP studied general QA and summarization, where parametric memory is rich, not sparse technical domains.

The contribution is diagnostic before it is corrective. We would provide paired, contamination-controlled estimates of how often domain RAG failures are memory overrides and how often they are true application failures. We would also give a mechanistic account of each type.

Research Program

The pair construction differs by domain type. The first setting is rule application, and we build it on TheoremQA's math, physics, EE&CS and finance questions. For each question, a model writes an executable solution program. We keep the program only if it reproduces the gold answer on the original. We then resample the input quantities within physically valid ranges and execute the program to obtain the twin's answer. Items whose answers cannot be recomputed this way are dropped rather than hand-guessed. A human-checked sample validates equivalence. DyVal 2 reports a 94% human-verified correctness rate for agent-transformed benchmark items, so we treat roughly that rate as the bar our pipeline must meet. We also add a structural variant in which the question is reworded so that a different, retrieved theorem governs it. This follows the logic of DyVal, which showed that changing a problem's structure or its order of presentation exposes pattern matching.

The second setting is fact grounding over a curated domain corpus. We use the wind-energy and permitting benchmarks WeQA and PermitQA, and DomainRAG. In each case we edit the specific fact in the source document that determines the answer, such as a setback distance or a threshold value, and re-index the edited corpus. The correct twin answer then exists only in the retrieval index, never on the web.

Each setting then gets a third condition that borrows the leak found by Search-Time Data Contamination. That paper showed search agents copying HLE and SimpleQA answer keys from HuggingFace mirrors, which raised Sonar Deep Research from 17.4% to 37.5% accuracy on HLE. We insert a near-duplicate of the original item and its answer into the private index. This lets us ask whether a retrieved leak, a memorized leak, or both dominate the model when they conflict with the correct document. The earlier paper audited only the open web, so this condition extends its question to closed enterprise-style corpora.

We quantify the effect with one pair of quantities. Let $A_{\text{rag}}$ and $A_{\text{cb}}$ be accuracy with and without retrieval, computed separately on originals (superscript $o$) and twins (superscript $t$). Let $M$ be the fraction of twin answers equal to the original's answer. We report

$$\Delta_{\text{mask}} = (A^{t}_{\text{rag}} - A^{t}_{\text{cb}}) - (A^{o}_{\text{rag}} - A^{o}_{\text{cb}}), \qquad M = \Pr[\hat{y}^{t} = y^{o}],$$

Here $\hat{y}^{t}$ is the model's answer on the twin and $y^{o}$ is the original gold answer. A positive $\Delta_{\text{mask}}$ means contamination hides retrieval's real benefit. $M$ is the rate at which memory overrides the context. Accidental matches are estimated from the rate at which random resamples collide, and we subtract that rate.

For the mechanism, we apply ReDeEP's two scores to open-weight LLaMA-family models, the architecture family ReDeEP used. The first score measures how much the answer draws on retrieved text through the attention heads that copy from context. The second measures how much the feed-forward layers inject stored knowledge. We compute both on every twin failure. Failures with high context-copying and high stored-knowledge injection match ReDeEP's override pattern. Failures with low context-copying are the "cannot parse unfamiliar technical text" pattern that the research file's Gap 4 hypothesizes for sparse domains. This split directly tests the tension between ReDeEP's claim that memory is too strong and the claim, in the work by Shao et al. on statistical de-grounding in Grounding AI Explanations in Experience, that memory in niche domains is too sparse. The contamination axis also makes a prediction here: override should be concentrated on memorized items, and copying failure on genuinely sparse ones.

Baselines

The naive reference point is closed-book answering with no retrieval, run on both originals and twins. It anchors $\Delta_{\text{mask}}$ and shows how much of each model's original-item accuracy vanishes when memorized answers stop being correct. This is the paired analogue of the post-cutoff collapse reported for CausalProbe-2024 in Unveiling Causal Reasoning in Large Language Models.

The strongest existing method on the TheoremQA side is program-of-thought prompting, where the model writes code whose execution gives the answer. The file reports GPT-4 at 51.0% accuracy on TheoremQA with this prompting, and open-source models below 15% (TheoremQA). We run program-of-thought with and without theorem injection. The prompts, number of samples, and retrieved theorem text are identical across originals and twins, so any difference in gain can come only from the item change. On twins, "beating" this baseline has a specific meaning. The retrieval-with-theorem arm must show a gain over program-of-thought alone that is statistically larger than the corresponding gain on originals, tested with a paired bootstrap over items.

For detecting override failures, the strongest competitor is ReDeEP itself. The file reports a chunk-level AUC of 0.7458 on RAGTruth with LLaMA2-7B, against 0.7290 for RAGAS and 0.5844 for SelfCheckGPT (ReDeEP). We run all three as detectors on our twin failures, using the same model and the same retrieved chunks, and compute AUC against the ground-truth override label that the twins give for free. We have no reported number for ReDeEP on technical-domain twins. If its AUC drops well below its RAGTruth figure there, that is itself a finding about sparse domains.

For the retrieval side, the dynamic-retrieval method RaDIO triggers retrieval when its hallucination detector fires. It reports 0.254 exact match on 2WikiMultihopQA with SBERT, against 0.214 for DRAGIN with BM25. We run it as an alternative pipeline with the same corpora and the same generator. This checks whether retrieving more often reduces $M$.

The ablation that isolates our key ingredient is to run every analysis on originals only. The question is whether any finding survives without the paired twin.

Why not just…?

Why not just use fresh post-cutoff questions, as CausalProbe-2024 did? Fresh questions remove memorization, but they also change topic and difficulty. A drop in accuracy on them therefore mixes novelty with hardness. The drop Claude 3 Opus shows on CausalProbe-2024, to below 70% on the hard split, cannot say how much of retrieval's benefit was masked on the original items. Paired twins hold the governing rule and the difficulty fixed, and they give an item-level override label that fresh data cannot give. We still include a fresh-data condition, so a reader can see whether it tells the same story more cheaply.

Why not just split items with a membership-inference score like Min-K% Prob? This is a real threat, because it is cheap and needs no new items. CausalProbe-2024's authors used it to certify freshness. We run it directly. We split originals by Min-K% score and ask whether the retrieval gain differs across the split the way $\Delta_{\text{mask}}$ predicts. If the Min-K% split reproduces our masking estimate and our override rates, the twin machinery is unnecessary for diagnosis, and we will say so. Our expectation is that the split is too noisy at the item level to label individual overrides. The experiment decides this rather than our assertion.

Why not just apply ReDeEP's inference-time fix, which amplifies context-copying heads and dampens knowledge layers, and skip the diagnosis? That fix, called AARF (Add Attention Reduce FFN), presumes that the failure is an override. If most twin failures instead show low context-copying, dampening memory will not help and may hurt. We therefore evaluate AARF on twins split by our mechanistic label. It should reduce $M$ on override failures and leave copying-failure items unchanged. If it helps both groups equally, our two-pattern account is wrong.

Why not just tell the model to trust the context, or use chain-of-thought? Instruction-following of this kind is exactly what the twins test. TheoremQA already found natural-language step-by-step reasoning inferior to program-of-thought, and AppealCase reports that it fails on procedural legal reasoning. We include a "use only the provided document" instruction as an arm and report its $M$. A near-zero override rate under this instruction would mean the problem is solved by prompting, and we would redirect the work toward copying failures.

Proposed Experiments and Decisive Checks

We evaluate open-weight LLaMA-family models, which permit the mechanistic scores, alongside one API model for behavioral comparison. All models run on TheoremQA twins and on the edited WeQA, PermitQA and DomainRAG corpora, each under closed-book, retrieval, and leak-in-index conditions.

Four outcomes decide the proposal. The first is the sign and size of $\Delta_{\text{mask}}$ for theorem injection. A significantly positive value overturns the reading that TheoremQA's null result reflects a pure application deficit. A value near zero confirms that reading and shifts attention to how rules are applied. The second is the override rate $M$ under retrieval, and how it compares across theorem-level and fact-level twins. The third is the mechanistic split of twin failures, and whether override failures concentrate on items with high membership scores, as the contamination account predicts. The fourth is the leak condition. If a retrieved near-duplicate of the original moves accuracy toward the original answer even when the correct document is also retrieved, the search-time contamination problem extends to private domain indexes. That would be a direct practical warning for enterprise RAG evaluation.