Manuscript Offprint

arXiv:2610.12085

Is Memorization Context-Sensitive? Prefix-Based Extraction Beyond Isolated Prefixes

Ali Satvaty, Narjes Sharafi, Jirui Qi, Suzan Verberne, Fatih Turkmen

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Large language models (LLMs) can expose memorized training sequences under prefix-based extraction: given a prefix from a training example, the model may assign high probability to the original continuation. In deployed systems, however, prefixes are rarely evaluated in isolation. They often appear together with instructions, retrieved documents, or other task-specific context, as in retrieval-augmented generation (RAG). This motivates examining whether contextual conditioning mitigates memorization or merely changes the set of memorized samples that become extractable. We investigate this issue through paired item-level measurements of probabilistic suffix extraction. For each prefix-suffix pair, we score the target suffix under an empty prompt and under retrieved contexts of varying relevance, across three open-weight instruction-tuned models. We find that context does not simply erase memorization. Instead, extractable memorization consists of a context-robust core and a context-sensitive boundary. Many samples that are extractable without context remain extractable under the retrieved context, especially as the prefix length increases. At the same time, context mainly affects marginal samples near the extraction threshold: it suppresses some exposures, but also enables new ones that are missed by prefix-only evaluation. These findings qualify the view that RAG reduces memorization risk. Context can lower aggregate extraction by suppressing boundary cases, yet robustly extractable samples persist, and context-enabled extractability remains security-relevant. 1^{1}

1 Introduction

Language models can memorize parts of their training data, raising privacy and copyright concerns when memorized content can be reproduced at inference time (Carlini et al., 2019; Henderson et al., 2023; Mueller et al., 2024; Freeman et al., 2024). The memorized content may be extracted when an adversary supplies a matching prefix of the original sequence (Carlini et al., 2021, 2023; Hartmann et al., 2023; Satvaty et al., 2024; Tirumala et al., 2022). Prefix-suffix extraction attacks measure this behavior directly: given a prefix from a training sequence, the model may assign unusually high probability to the corresponding suffix, enabling verbatim recovery of memorized text.

In many deployed systems, a model is not prompted with an isolated prefix, but with additional text such as retrieved documents, instructions, or task-specific context (Wei et al., 2022; Gao et al., 2023). This is especially relevant for retrieval-augmented generation (RAG), where external documents are attached to the input of the model (Lewis et al., 2020; Borgeaud et al., 2022). Intuitively, one might expect such context to reduce memorization-based leakage: if the model is grounded in retrieved evidence, it may rely less on parametric memory. This intuition has been explored in recent work suggesting that RAG can reduce leakage (Zeng et al., 2024). However, it remains unclear how contextual conditioning changes prefix-based extraction at the level of individual samples.

In this work, we study how extra context affects memorization under the prefix–suffix extraction setting. For each prefix–suffix sample, we measure the probability assigned to the target suffix when the prefix is evaluated alone and when it is evaluated with different types of preceding context. We consider semantically related retrieved context, and irrelevant context, and compare all conditions through paired item-level measurements. This lets us examine not only whether aggregate extraction changes under context, but also how context changes the set of samples that become extractable.

1^{1}The code is available at: https://github.com/alistvt/context-sensitive-memorization

Our results show that contextual conditioning does not simply remove memorization. Instead, extractable memorization has a context-robust core of samples that remain extractable regardless of the surrounding context, and a context-sensitive boundary consisting of samples near the extraction threshold whose exposure status flips when context is added. Many core samples remain extractable under retrieved contexts, especially as the prefix length increases. At the same time, context changes the exposure status of marginal samples: some prefix-suffix pairs are suppressed by context, while others become extractable only after context is added. This distinction matters for interpreting claims that retrieval reduces memorization. We find that context can lower aggregate extraction by suppressing boundary cases, but this aggregate reduction should not be interpreted as eliminating memorization risk. Robustly extractable samples remain extractable across contexts, and context-enabled samples are missed by prefix-only evaluation. Thus, contextual conditioning is better understood as reshaping the exposure boundary rather than erasing memorized content.

Taken together, our contributions are:

• We formulate prefix–suffix memorization under contextual conditioning and conduct paired item-level comparisons across empty, relevant, and irrelevant contexts.

• We show that extractable memorization is composed of a high-confidence core that persists across contexts and weaker extractions that are more sensitive to surrounding context, with robustness increasing as prefix length grows.

• We show that aggregate reductions in exposure can hide security-relevant sample-level behavior, including robust exposures that persist across contexts and examples that become extractable only after context is added.

References (22)