TL;DR
Adding context—like retrieved documents in a RAG system—doesn't "erase" an LLM's tendency to leak memorized training data. While context can suppress some marginal leaks, a robust core of memorized sequences remains extractable regardless of the surrounding text, and in some cases, adding context can even trigger new leaks that weren't visible in isolation.
What Problem Does This Paper Address?
We know that Large Language Models (LLMs) memorize chunks of their training data. Researchers typically measure this using "prefix-based extraction": give the model a snippet of training text (the prefix) and see if it can complete the rest (the suffix) verbatim.
However, in real-world applications like Retrieval-Augmented Generation (RAG), models are rarely prompted with an isolated prefix. They are usually given instructions and retrieved documents first. The prevailing intuition was that "grounding" a model in external context might reduce its reliance on internal parametric memory, thereby mitigating privacy and copyright risks. This paper asks: Is memorization actually context-sensitive? Does RAG act as a shield, or does it just change which parts of the training data are currently "at the surface"?
Methods
The authors moved beyond binary "yes/no" extraction counts and adopted a probabilistic extraction framework. Instead of just checking if a model generates a suffix via greedy decoding, they measured the exact log-probability the model assigns to the target suffix.
They conducted paired item-level measurements across three open-weight, instruction-tuned models: Llama-3-8B, Falcon-7B, and OLMo-2-7B. For 50,000 prefix-suffix pairs, they compared the suffix probability under three conditions:
- Empty Context: The prefix alone.
- Relevant Context: The prefix preceded by the most semantically similar document from a retrieval collection.
- Irrelevant Context: The prefix preceded by the least relevant document.
By comparing these scores for the same samples, they could categorize memorized items into a "context-robust core" (always leaks) and a "context-sensitive boundary" (leaks depending on the prompt).
Datasets
- Prefixes/Suffixes: 50,000 sequences sampled uniformly at random from the Pile-CC (CommonCrawl subset of The Pile). They tested prefix lengths of 32, 64, and 128 tokens, with a fixed suffix length of 32 tokens.
- Retrieval Collection: A mixture of ~67,000 documents from StackExchange, PubMed, and Wikipedia.
- Retriever: The E5 dense retriever was used to select relevant and irrelevant contexts.
Key Insights and Ideas
- The Robust Core vs. The Sensitive Boundary: Memorization isn't a monolith. There is a "high-confidence core" of samples that the model "knows" so well that no amount of context—relevant or otherwise—can stop them from being extractable. Context mostly reshapes the "boundary," affecting marginal samples that are near the threshold of being forgotten.
- Prefix Length Dominates Context: As the prefix gets longer, the model's behavior becomes increasingly context-independent. A 128-token prefix provides such a strong signal that the preceding RAG documents become almost irrelevant to the extraction probability.
- Context as a Filter, Not a Shield: While RAG can lower aggregate memorization scores by suppressing some boundary cases, it is not a reliable defense. It acts more like a filter that shifts which specific samples are exposed.
- The "Enabled" Leak: Most surprisingly, the authors found "context-enabled" samples—sequences that the model wouldn't leak in isolation but does leak when a specific (sometimes even irrelevant) document is placed in the prompt.
Key Results
- Stability Increases with Length: The Jaccard overlap (a measure of how much the set of leaked samples stays the same across different contexts) increases sharply with prefix length. For Llama-3, the overlap between empty and relevant context jumps from 0.72 at 32 tokens to 0.91 at 128 tokens.
- Distribution Shifts: Figure 1 shows that while context shifts the probability distribution slightly for short prefixes, the curves for "empty" and "relevant context" converge as the prefix length grows.
- Decomposition of Exposure: In all models, "Robust Exposure" (samples that leak in all three context conditions) is the dominant category, especially for longer prefixes.
Limitations and Future Work
- Model Scale: The study focused on ~10B parameter models. While these are large enough to show significant memorization, the dynamics might shift in "frontier" models (100B+ parameters).
- Suffix Length: The suffix was fixed at 32 tokens. Longer suffixes might compound probability gaps, potentially making them more sensitive to context.
- Domain Specificity: The Pile-CC is general web text. The authors suggest that specialized domains like source code or medical records might exhibit different levels of context sensitivity.
- Defense Mechanisms: The paper argues that RAG is not a defense, but it doesn't evaluate active defenses like differential privacy or output filtering, which remain important areas for future research.
Summary updated