The Atlas of In-Context Learning: How Attention Heads Shape In-Context Retrieval Augmentation
Patrick Kahardipraja, Reduan Achtibat, Thomas Wiegand, Wojciech Samek, Sebastian Lapuschkin
TL;DR
This work interrogates how attention heads drive in-context retrieval augmentation in large language models. By introducing AttnLRP, an attribution framework for transformer heads, it separates in-context heads (processing the prompt) from parametric heads (storing relational knowledge) and demonstrates their distinct functional roles. The authors show that in-context heads specialize into task- and retrieval-related functions, and that manipulating per-head function vectors or attention weights can causally influence generation and enable source tracking of retrieved knowledge. A retrieval-head probe further enables efficient provenance tracing, contributing to safer and more transparent retrieval-augmented LMs. The findings suggest practical pathways for controlling knowledge sources and improving interpretability in RAG systems, while acknowledging limitations and avenues for future work.
Abstract
Large language models are able to exploit in-context learning to access external knowledge beyond their training data through retrieval-augmentation. While promising, its inner workings remain unclear. In this work, we shed light on the mechanism of in-context retrieval augmentation for question answering by viewing a prompt as a composition of informational components. We propose an attribution-based method to identify specialized attention heads, revealing in-context heads that comprehend instructions and retrieve relevant contextual information, and parametric heads that store entities' relational knowledge. To better understand their roles, we extract function vectors and modify their attention weights to show how they can influence the answer generation process. Finally, we leverage the gained insights to trace the sources of knowledge used during inference, paving the way towards more safe and transparent language models.
