Long-Term Memory for Dialogue Models: Architecture and Governance

    Dialogue models need memory outside the context window: a retrievable, updatable, and revocable working set distinct from raw chat logs. This article covers what to store, a four-layer architecture, write/update/inject practices, privacy controls, evaluation, and how memory differs from RAG.

    Why memory must sit outside the context window

    A large language model can only see a limited amount of text in one inference. Even with longer windows, stuffing the full history into the prompt raises cost, dilutes attention, and lets older statements overwrite facts. If a product only uses the current turn plus a few recent turns, users still have to restate identity, stack, delivery constraints, and taboos. Long-term memory maintains retrievable, updatable, and revocable state outside the model so later answers can cite that state instead of pretending the model permanently remembers every chat.

    Memory is not a synonym for the transcript. The transcript is the raw event stream, suited to audit and replay. Memory is a filtered, compressed working set with recency and confidence. Store them separately: raw logs for traceability, memory items for injection at inference time.

    Three kinds of information memory should hold

    In practice, content worth keeping usually falls into three classes.

    Stable preferences: tone, level of detail, whether code comments are required, forbidden topics, or output format. These change slowly, but a wrong write pollutes answers for a long time, so users should be able to see and edit them.

    In-progress task state: current goals, confirmed technical choices, open questions, and milestones. Lifetime is task-scoped. When a task ends or the direction changes, demote or archive the items so they do not compete with new work.

    Verifiable facts: API contracts, environment differences, decisions that already happened. Fact memories must carry provenance (which conversation, which user quote, or which document). Otherwise you cannot tell model inference from user statement.

    Do not put into long-term memory: one-off calculations, fragments with secrets, unconfirmed guesses, or the model’s own elaboration. Writing model output back as “user fact” is the most common source of contamination.

    Layered architecture

    A scalable design can use four layers that talk through explicit contracts rather than stuffing all logic into the prompt.

    Collection. Sources include explicit user instructions (“please remember”), end-of-session summarization, and async cleanup of history. Explicit writes have highest priority. Async jobs may only produce candidate memories and must not overwrite user-confirmed items by default.

    Storage. Each item should include at least: subject scope (user, workspace, or a single project), type, text, evidence pointer, created/updated time, TTL or version, confidence, and sensitivity. Use structured documents plus a vector index: exact fields filter (who, kind, expired or not); vectors support semantic recall. Object storage holds raw dialogue and summary snapshots; the online store keeps only the currently effective version.

    Retrieval and injection. Each turn, recall against the current question, rerank by relevance, recency, and user priority, then inject a short context with a note such as: saved memory below; if it conflicts with this turn, this turn wins. Hard-cap the injection budget so memory does not crowd out the actual question and code.

    Governance. View, edit, delete, export, and “pause automatic writes.” Delete must invalidate vectors and caches, not only the UI.

    A simple, auditable item shape:

    1. memory_item:
    2. scope: user | workspace | task
    3. kind: preference | task_state | fact
    4. text: "API errors always return a problem ID, never a stack trace."
    5. evidence: conversation_ref
    6. status: candidate | confirmed | archived
    7. updated_at: timestamp
    8. supersedes: previous_id | null

    Writes: from “user said save this” to background cleanup

    Early products often only support manual save: the user states what to remember, the system stores a summary. Consent is clear; coverage is low, and longer projects still lose context.

    A fuller flow is dual-channel.

    Manual channel: user commands or a settings form create confirmed items that take effect immediately.

    Automatic channel: a background job reads recent dialogue, extracts candidate facts and preferences, and marks them candidate. Candidates enter the default retrievable set only if confidence is high enough and they do not contradict confirmed items. On conflict, keep both, down-weight the automatic item, or ask the user. Deduplicate: if the same preference appears many times, update time and evidence instead of stacking near-duplicate sentences.

    Run cleanup asynchronously with a queue so summarization cost is off the user-facing path. Failures should be retryable and idempotent, using the evidence pointer as the dedup key.

    Updates and expiry: remembering the old thing is worse than remembering nothing

    Stale memory is more dangerous than no memory, because the model confidently reuses outdated constraints. Use three mechanisms together.

    Explicit supersede. If a new user statement conflicts with an old item, write a new version and chain the old one via supersedes. Online retrieval uses only the latest confirmed version.

    Time decay. Task state gets a short default TTL; preferences get a long TTL but periodic review. Decay changes ranking weight rather than physical delete, so users can recover items.

    Usage feedback. If the user contradicts an item in chat, demote it immediately and record the contradiction. Do not only suppress it in this turn’s prompt and let the next turn retrieve it again.

    At large scale, pressure is on recall and cleanup, not model weights. Shard by user and split hot/cold: hot memory in low-latency storage, cold memory and raw logs in object storage. Schedule cleanup by activity; idle sessions get less frequent jobs so compute goes to conversations that are still happening.

    Behavioral constraints at injection time

    Even after retrieval, the model may ignore memory or over-elaborate. State priority in the prompt: safety and compliance above memory; this turn’s instructions above long-term memory; long-term memory above guesses about what the user “probably wants.” Keep memory text as short phrases close to the user’s wording; do not add unproven causal inference during cleanup.

    If recall is empty, answer normally; do not invent “based on your habits.” If multiple confirmed items conflict, briefly flag the conflict and ask which one wins rather than silently picking one.

    Permissions, privacy, and minimization

    Memory widens how long personal information is kept. Default to minimization: store only fields needed for coherent dialogue. Reject or redact secrets, ID numbers, precise locations, and similar sensitive patterns. Isolate indexes by subject; never recall across users. Enterprises need workspace policy: admins can turn off automatic memory, set retention, and bulk-delete after offboarding or project close.

    User visibility is a trust requirement. Settings should let people browse summaries by time and type, delete one item or everything, and explain which history automatic cleanup reads. Export should be human-readable summaries plus metadata, not opaque vectors.

    How to evaluate without chasing a single score

    Memory quality is not “can it recite one sentence.” Split at least four axes and regress on a fixed eval set rather than citing an unexplained accuracy number.

    Fact recall: given constraints that clearly appeared in history, does a new session cite them on relevant questions without inventing details that never appeared.

    Preference following: do style and format memories show up in answers without overriding an opposite request this turn.

    Stale handling: do items the user updated or denied stop dominating answers.

    Refuse-to-write and forget: sensitive content never lands in storage; after delete it is unavailable in later turns and caches.

    Eval samples should come from de-identified chats or synthetic scripts covering manual save, automatic candidate conflict, and re-asking after a long gap. Online, watch indirect signals: fewer repeated self-introductions, user delete rate, and negative feedback from “remembered wrong.” Those find problems; they do not replace offline controlled tests.

    Boundary with retrieval-augmented generation

    Document retrieval answers “where does knowledge come from.” Long-term memory answers “what state does this user or this task currently have with me.” They can share vectors and rerankers, but namespaces, permissions, and update rates differ. Treating a whole project corpus as memory drowns personal preferences in public docs; dumping all chit-chat into a knowledge base pollutes shared knowledge with personal wording. Injection order is usually task memory and hard constraints first, then retrieved references, with the answer required to distinguish “your standing requirements” from “what the reference material says.”

    A minimal closed loop to ship

    Start narrow, then add automatic cleanup.

    1. Explicit save and settings-page management only, with evidence and delete.
    2. Small-budget recall each turn against the current question; this turn wins on conflict.
    3. Archive conditions for task memory so expired projects stop interrupting.
    4. After the manual path is stable, add async candidates plus human or rule confirmation.
    5. Regress on the four eval axes; monitor write rejects and residual recall after delete.

    Logs, metrics, and alerts should cover cleanup failures, recall latency, and abnormal write volume so you can tell whether growth pain is index, queue, or policy.

    Summary

    Dialogue memory extends a limited context into governed external state: separate raw logs from effective memory, separate confirmed writes from automatic candidates, fight staleness with versions and TTL, and keep user control with permissions and delete. It does not replace a longer window or document retrieval; it supplies the small slice of state that stays valid for this interlocutor. Once write, update, inject, and eval form an observable loop, coherence can improve with use instead of getting worse as history grows.