Sparse Latents Steer Retrieval-Augmented Generation

Chunlei Xin, Shuheng Zhou, Huijia Zhu, Weiqiang Wang, Xuanang Chen, Xinyan Guan, Yaojie Lu, Hongyu Lin, Xianpei Han, Le Sun

Introduction

Retrieval-Augmented Generation (RAG) has become the standard architecture for grounding Large Language Models (LLMs) in external data, significantly reducing hallucinations. However, RAG systems often face internal conflicts: a model might ignore a relevant document in favor of its own internal memory, or it might hallucinate an answer when the provided context is irrelevant. Until now, the internal mechanisms governing these decisions—choosing between memory and context, or deciding when to refuse a query—remained a "black box."

This research identifies specific "interpretable latents" within LLMs that act as steering wheels for RAG behavior. By leveraging Sparse Autoencoders (SAEs), researchers can now precisely manipulate these hidden switches to prioritize external context or enforce query rejection without altering the model's underlying architecture.

Methodology: Finding the Neural Knobs

The core of this approach involves Sparse Autoencoders (SAEs) from the LLaMA Scope framework. SAEs decompose the dense activations of an LLM into millions of sparse, human-interpretable directions (latents) that often correspond to single concepts.

Overview of identifying meaningful directions and steering model behavior using SAE latents.

The researchers followed a three-step process to gain control over RAG behaviors:

  1. Identifying Meaningful Directions: By comparing model activations during "correct" behavior (e.g., following context) versus "incorrect" behavior (e.g., relying on memory), they isolated candidate latents.
  2. Calculating Separation Scores: A metric was developed to identify latents that are highly active during one specific behavior but remain silent during others.
  3. Latent Steering: Once identified, these latents are manually amplified during the generation process. This "steering" forces the model to adopt the desired behavior, such as switching from a memory-based response to a context-based one by "turning up the volume" on the relevant latent.

Experimental Setup and Datasets

To evaluate these latents, the team constructed a specialized comparative dataset based on the SQuAD (Stanford Question Answering Dataset). They paired questions with either "golden" relevant documents or irrelevant Wikipedia snippets. This allowed them to categorize and study four distinct model behaviors:

  • Memory-based response: Relying on internal knowledge despite provided context.
  • Context-based response: Correctly using the provided document to answer.
  • Refusal: Outputting "Unknown" when the context is missing or irrelevant.
  • Non-refusal: Attempting to answer despite a lack of relevant information.

The dataset consisted of 500 instances per category for detection, 100 for validation, and 300 for testing.

Key Insights: The Layer Hierarchy of Decisions

A primary discovery of this work is the hierarchical nature of RAG decision-making within the model's layers. The paper reveals a fascinating "early-to-late" pipeline where different layers handle different levels of abstraction.

Distribution of latents across layers showing the concentration of steering directions for context vs. memory.
  • Early vs. Late Layers: Decision-making follows a clear progression. Latents in early layers (up to layer 19) represent abstract logic, such as the fundamental decision to "use the provided text." In contrast, latents in later layers are more closely tied to specific output tokens, like the word "Unknown."
  • Generalizability: Latents discovered in the base LLaMA-3.1-8B model were found to be effective even in instruction-tuned versions. This suggests that RAG logic is a fundamental property of the model's internal representations, not just a surface-level instruction-following behavior.
  • Mechanistic Attention Shifts: Mechanistic analysis revealed that steering these latents reconfigures the model's "retrieval heads." These are specific attention heads responsible for copying information from the context. Steering a context-prioritization latent literally forces the model's attention to remain on the document.

Results and Performance

The intervention results demonstrate high precision and robustness across various scenarios:

  • Near-Perfect Control: Steering with the top identified latents achieved nearly 100% success in moving models from memory-based to context-based responses.
  • Scalability: The steering remained effective (over 80% success) even as the context length increased from one to five documents.
  • Prompt Independence: Early-layer latents proved robust to prompt variations. For instance, a refusal latent worked even if the required output token was changed from "Unknown" to "NULL," indicating the latent controls the high-level intent to refuse rather than just a specific string.

Limitations and Future Outlook

While the results on LLaMA-3.1-8B are promising, further research is needed to confirm if these mechanisms are universal across other architectures like GPT-4 or Claude. Additionally, this study focused on short-form question answering. Future work will explore whether these "steering wheels" can manage more complex RAG tasks, such as multi-hop reasoning or long-form document synthesis, where the model must integrate information across multiple disparate sources.

Summary updated

BibTeX
@inproceedings{xin2025sparse,
  author = {Chunlei Xin and Shuheng Zhou and Huijia Zhu and Weiqiang Wang and Xuanang Chen and Xinyan Guan and Yaojie Lu and Hongyu Lin and Xianpei Han and Le Sun},
  title = {{Sparse Latents Steer Retrieval-Augmented Generation}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure