Personalization and Long-Term Memory › What "Memory" Means for a Language Model
Language AI HandbookAll chapters For this design, distinguish parameters, the context available for one inference call, and the records the application retains across calls.
Parametric knowledge is encoded in model weights following training. We keep the shared weights fixed and make no per-user weight writes in this design. That makes personalization reversible at the application layer. It gives no assurance about the original training data: Carlini et al. (2021) recovered verbatim training strings from GPT-2. A private memory store also needs independent account and scope checks before any records reach the model.
Working context is the input the model has available for the current generation. An application can reconstruct it from the conversation transcript, a summary, or a stored conversation state. It can include a current message and selected durable preferences. Part XIII on Self-Attention explains how tokens in the input interact.
Records an application retains across requests or sessions. At inference time the application selects authorized records and presents them in working context.
A long-term memory layer combines a store of typed records with policies for writing, selecting, updating, and removing them. A derived index can help find relevant records. The authoritative record governs whether a selected item is eligible for the current request.
Consider an application that submits successively longer transcripts. At step it submits chunks of 400 input tokens. A second strategy submits a fixed block of 220 memory tokens per step. We count these input tokens over 120 steps, omitting any prompt components shared by the two strategies.
PythonIn [2]Expand
import numpy as np
turns_axis = np.arange(1, 121)
tokens_per_chunk = 400
transcript_tokens = turns_axis * tokens_per_chunk
memory_block_tokens = np.full_like(turns_axis, 220)
transcript_cumulative = np.cumsum(transcript_tokens)
memory_cumulative = np.cumsum(memory_block_tokens)VisualizationOut [3]Expand

If the application retrieves a record such as {user: 42, key: "dietary_preference", value: "vegetarian"}, the answer can reflect that stored preference without a weight update. A correction changes which value future requests can see. Erasure has to account for every retained copy.
Why a memory layer at all?
A long context window lets the application submit more history. There are three reasons to keep a separate record for a preference the assistant will use again.
First, cumulative input length grows with the transcript. In the figure, the transcript uses 2,904,000 input tokens across 120 steps. The fixed block uses 26,400. The comparison is a count of submitted tokens. Actual costs and latency also depend on the serving system, cache behavior, and other request work.
Second, fitting information in the input gives limited assurance that a model will use it. In the tasks and models studied by Liu et al. (2024), performance could drop when relevant information moved toward the middle of the input. A typed memory block lets you select relevant information explicitly. You still need to test how the model uses it.
Third, a typed slot narrows the read, correction, and deletion path. If a product also keeps raw transcripts or cached prompts, it needs a separate policy for those copies. Part XX's chapter on PII removal covers related issues in text corpora.
The chart assigns illustrative investment ratings to three hypothetical products. The scale runs from 0 (omit the layer) to 3 (make it central to the design). For example, the support bot depends mostly on continuity across support sessions.
PythonIn [4]Expand
import numpy as np
product_types = [
"Support\nchatbot",
"General\nassistant",
"Safety-critical\nassistant",
]
layers = ["Episodic", "Semantic", "Instruction"]
need_matrix = np.array(
[
[3, 2, 1], # Episodic
[1, 3, 1], # Semantic
[0, 2, 1], # Instruction
]
)VisualizationOut [5]Expand

Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!