Personalization and Long-Term Memory › What "Memory" Means for a Language Model

Michael BrenndoerferDecember 1, 20265 min read
Language AI HandbookAll chapters
Part 45 of 67Knowledge, Memory, Editing, and Unlearning
Chapter 349Personalization and Long-Term Memory › What "Memory" Means for a Language Model
Reading section 2 of 15 · What "Memory" Means for a Language Model · 5 minSection 2 of 15 · 5 min

Section 2 of 15 · 5 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

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.

Long-term memory

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 nn it submits nn 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]
CollapseExpand
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]
CollapseExpand
The solid full-transcript line curves upward to 2.904 million tokens. The dashed fixed-block line reaches 26,400 tokens.
Across 120 modeled inputs, submitting one more 400-token transcript chunk each turn produces 2,904,000 cumulative input tokens. A 220-token memory block each turn produces 26,400.

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]
CollapseExpand
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]
CollapseExpand
Bar groups show episodic, semantic, and instruction ratings from left to right: support 3, 1, 0; general 2, 3, 2; safety-critical 1, 1, 1.
Illustrative product investment ratings on an ordinal scale from 0 (omit) to 3 (central). The support chatbot gives its highest rating to episodic memory and the general assistant gives its highest rating to semantic memory. The safety-critical example rates all three layers at 1.

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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy