Quantifying reliance on external information over parametric knowledge during Retrieval Augmented Generation (RAG) using mechanistic analysis

Reshmi Ghosh, Rahul Seetharaman, Hitesh Wadhwa, Somyaa Aggarwal, Samyadeep Basu, Soundararajan Srinivasan, Wenlong Zhao, Shreyas Chaudhari, Ehsan Aghazadeh

Abstract

Retrieval Augmented Generation (RAG) is a cornerstone of modern natural language applications, yet the internal mechanics of how Language Models (LMs) prioritize retrieved context over internal knowledge remain poorly understood. This study employs mechanistic interpretability to examine the RAG pipeline, revealing a pronounced "shortcut" effect. Through Causal Mediation Analysis and attention-based probing, we demonstrate that LMs exhibit a strong bias toward external context, significantly suppressing internal parametric pathways. Our findings show a 10x to 35x decrease in reliance on internal factual recall across both Large Language Models (Llama-2) and Small Language Models (Phi-2) when external context is provided.

Introduction

Large Language Models (LLMs) operate as dual-memory systems. They possess parametric knowledge—facts encoded within their weights during pre-training—and non-parametric memory—information provided dynamically via the input prompt, often through Retrieval Augmented Generation (RAG). While RAG is primarily utilized to mitigate hallucinations and incorporate real-time data, the internal "tug-of-war" between these two knowledge sources has lacked quantification.

This research investigates whether models integrate these sources or if one dominates the other. By applying mechanistic analysis—essentially "brain imaging" for neural networks—we quantify the shift in information processing that occurs when a model transitions from a zero-shot "vanilla" query to a RAG-augmented prompt.

Methodology

To observe the internal state transitions, the study utilized three primary mechanistic probing techniques on Llama-2 (7B) and Phi-2 (2.7B):

1. Causal Mediation Analysis (Causal Tracing)

This technique identifies the specific internal activations responsible for a model's output. By "corrupting" the input with noise and then selectively "restoring" hidden states from a clean run, researchers measure the Indirect Effect (IE). A high IE indicates that a specific layer or token representation is critical for the model's factual prediction.

2. Attention Contributions

The researchers analyzed the norm of attention weights to determine the flow of information. Specifically, they measured how much the "last token" (the position where the answer is generated) attends to the "subject token" of the query (internal recall) versus the tokens within the provided RAG context (external reading).

3. Attention Knockouts

By systematically disabling specific attention edges (setting their weights to $-\infty$), the team observed the impact on the model's performance. If the model maintains its accuracy despite the "knockout" of internal factual pathways, it confirms a lack of reliance on those specific parametric connections.

Experimental Setup

The study utilized the Knowns 1000 dataset, consisting of 1,209 factual prompts (e.g., "The Space Needle is in the city of..."). Two scenarios were compared:

  • Vanilla Case: The model answers using only its internal weights.
  • RAG Scenario: Prompts were augmented with context generated by GPT-4, ensuring the model had a clear, high-quality external source to reference.

Key Findings: The "Shortcut" Effect

The analysis reveals a fundamental shift in model behavior: the "Shortcut" Effect. When RAG context is available, LLMs do not merely supplement their knowledge; they actively "mute" the neural pathways typically used for internal recall.

Parametric Suppression

In standard settings, the "Last Subject Token" (LST) acts as the primary engine for factual retrieval. However, in RAG settings, the Indirect Effect of the LST plummets. The model effectively stops "remembering" and starts "reading."

Quantitative Results

  • Internal Reliance Drop: The Average Indirect Effect (AIE) of internal memory pathways decreased by ~10x for Llama-2 and ~35x for Phi-2 when RAG context was introduced.
  • Attention Re-routing: Attention to internal subject tokens decreased by 1.6x in Llama-2 and 7x in Phi-2.
  • Knockout Resilience: In vanilla settings, knocking out attention from the subject token reduced answer probability by 20-25%. In RAG settings, the same intervention caused a negligible drop of less than 5%, proving the model had almost entirely abandoned its internal factual path.

Discussion and Implications

The results suggest that LLMs prioritize efficiency over integration. Rather than cross-referencing internal knowledge with external context, the model's attention mechanism shifts to flow directly from the RAG-provided attribute to the output. This indicates that RAG is not just an additive feature but a catalyst for a fundamental change in the model’s processing strategy.

While this "shortcut" helps reduce hallucinations by favoring provided evidence, it also highlights a potential vulnerability: the model may become overly reliant on external context even when its internal knowledge is more accurate or when the provided context is subtly misleading.

Limitations and Future Work

This study focused on models up to 7B parameters. Future research is required to determine if larger models (>70B) exhibit similar shortcut behaviors or if they possess the capacity for more robust knowledge integration. Additionally, the use of "clean" synthetic context leaves questions about how models handle noisy or conflicting real-world data. Further investigation into positional biases (the "lost in the middle" phenomenon) will also be crucial for understanding how context length affects this parametric suppression.

Summary updated

BibTeX
@inproceedings{ghosh2024quantifying,
  author = {Reshmi Ghosh and Rahul Seetharaman and Hitesh Wadhwa and Somyaa Aggarwal and Samyadeep Basu and Soundararajan Srinivasan and Wenlong Zhao and Shreyas Chaudhari and Ehsan Aghazadeh},
  title = {{Quantifying reliance on external information over parametric knowledge during Retrieval Augmented Generation (RAG) using mechanistic analysis}},
  booktitle = {BlackBoxNLP @ EMNLP},
  year = {2024},
  url = {https://openreview.net/forum?id=PCi5h5PJNw},
}
Figure