Conversational AI Memory Systems: Principles, Architecture, and Implementation

    Learn how conversational AI memory systems preserve useful context across sessions. This article covers explicit and automatic memory, a five-layer reference architecture, extraction and retrieval workflows, conflict resolution, privacy controls, evaluation, and cloud deployment practices. The focus is on keeping memory accurate, current, reversible, and within a limited context budget.

    1. Why Conversational AI Needs Memory

    An LLM’s inference context is inherently stateless across sessions unless an external system preserves and supplies relevant information. When a conversation ends, the model does not independently retain who the user is, what they prefer, or which project they are working on. This creates three common problems:

    • Repeated context-setting: Users must explain the same background in each new conversation.
    • Preference drift: Answers to the same question may vary substantially in style across sessions.
    • Task discontinuity: Multi-step tasks spanning several days lose their context.

    A memory system is not intended to make the model “remember everything.” Its purpose is to reintroduce information likely to be useful again into the prompt at minimal cost, within a limited context budget. This principle should guide the architecture.

    2. Two Memory Approaches: Explicit Saving and Automatic Extraction

    Most implementations follow two complementary approaches:

    • Explicit memory: The user asks the system to remember something, and the system saves a memory entry. This approach is precise, explainable, and less prone to incorrect writes, but depends on user participation and has limited coverage.
    • Implicit memory: The system periodically scans conversation history, extracts candidate memories, and merges them into storage. This offers broader coverage with little user effort, but introduces risks such as incorrect extraction, overgeneralization, privacy overreach, and stale information.

    The source article describes the following evolution of memory capabilities in a mainstream conversational AI assistant, based on public materials:

    • April 2024: An initial rollout focused primarily on explicitly saved memory.
    • April 2025: A mechanism was introduced to supplement memory automatically using past conversations.
    • June 2025: A lightweight version supporting short-term conversational continuity became available to free users.
    • June 2026: A new memory architecture focused on reducing stale information and improving accuracy. It initially targeted higher-tier subscribers in selected regions, offered twice the memory capacity, and was subsequently expanded.

    The source also cites public evaluations reporting an increase in factual recall from roughly 40% to more than 80%, and in preference adherence from roughly 30% to around 70%. These figures illustrate a shift in the central challenge: from whether a system can remember information to whether that information is correct and still current.

    A more robust engineering approach combines both modes: automatic extraction provides coverage, explicit saving provides calibration, and users can switch back to manual-only memory at any time.

    3. Reference Architecture: Five Layers

    1. Raw conversation layer: Stores original conversations, or hashes plus summaries, as traceable memory sources. This supports audits and explanations of why an entry was saved.
    2. Working memory layer: Maintains a rolling summary within the current session. It lasts only for the session’s lifecycle and compresses long conversations.
    3. Long-term memory layer: Stores structured entries. Suggested fields include memory_id, type (preference, fact, project, or plan), content, confidence, source_refs, created_at, updated_at, expire_at, and version.
    4. Retrieval layer: Combines vector similarity with keyword search and structured filtering, then reranks results using relevance × freshness × confidence.
    5. Injection layer: Assembles memory into the prompt within a token budget and provides a fallback when memory is unavailable.

    4. Key Engineering Challenges and Solutions

    4.1 When to Write Memory—and What to Save

    Do not trigger extraction on every turn. Use a combination of session completion, accumulated turn thresholds, and explicit user instructions.

    Apply rule-based filtering before storage. One-off task details and sensitive information, such as identity documents, secrets, and health information, should not be saved. Extraction prompts should request structured entries with confidence scores rather than free-form text.

    4.2 Resolving Conflicts and Managing Stale Memory

    Stale information is a major concern for newer memory architectures. A combined strategy can include:

    • Merge related entries: Semantically deduplicate entries sharing the same (type, subject) and retain the more informative formulation.
    • Versioned replacement: Assign the new entry version+1 and mark the previous entry as superseded. Retain the old version for traceability rather than physically deleting it.
    • Time decay: Multiply retrieval scores by exp(-λ·Δt). Preference entries can decay more slowly, while factual entries can decay more quickly.
    • TTL and reconfirmation: Set expire_at for project and plan entries. After expiration, request a lightweight confirmation before renewing or archiving them.

    4.3 Controlling the Context Budget

    Memory injection needs a firm upper limit—for example, 10%–15% of the prompt. If retrieved entries exceed that budget, truncate them according to their reranked scores.

    The prompt should also state: “The following entries describe the user’s historical preferences. If they conflict with the current instructions, follow the current instructions.”

    This prevents stored memory from overriding the user’s present request.

    4.4 Privacy, Visibility, and Reversibility

    Memory is a user data asset. Users should be able to:

    • View memory entries and summaries.
    • Edit entries.
    • Delete individual entries.
    • Clear all memory.
    • Disable automatic extraction.

    Data should be encrypted in transit and at rest. Deletion must also remove corresponding vector index entries and derived summaries, preventing deleted information from remaining retrievable.

    5. Illustrative Pseudocode

    1. # Illustrative workflow only; not an interface for any specific product
    2. def maybe_extract(session):
    3. if not (session.ended or session.turns % 20 == 0):
    4. return
    5. for item in llm_extract(session.recent_history): # Structured output
    6. if item.sensitive or item.confidence < 0.6:
    7. continue
    8. memory_store.upsert(item) # Merge related entries + versioning
    9. def recall(query, user_id, budget_ratio=0.12):
    10. cands = hybrid_search(query, user_id) # Vector search + structured filtering
    11. scored = [(c, relevance(c, query)
    12. * math.exp(-LAMBDA[c.type] * age(c))
    13. * c.confidence) for c in cands]
    14. scored = [x for x in scored if not expired(x)]
    15. return pack_within_budget(scored, budget_ratio) # Truncate to fit the budget

    6. Evaluation and Observability

    Offline evaluation should track four groups of metrics:

    • Factual recall: Whether the system correctly reproduces historical facts.
    • Preference adherence: Whether output style follows established user preferences.
    • Freshness and stale-memory rate: Whether the system references outdated information that has already been superseded.
    • Incorrect-write rate and revocation success rate: Whether inappropriate entries are saved and whether their removal takes effect.

    In production, logging and monitoring should capture memory hit rate, the proportion of prompt tokens used by injected memory, and deletion propagation latency. Conversations in which memory causes an abnormal response should have a traceable path back to the relevant entries and sources.

    Use staged rollouts, and load-test storage and retrieval before doubling memory capacity.

    7. Cloud Deployment Considerations

    A self-managed implementation can be assembled from general-purpose cloud services:

    • Object storage for raw conversations and cold data.
    • A container platform for extraction and retrieval services.
    • Message queues to absorb traffic spikes and support asynchronous extraction.
    • Caching services for session-level working memory.
    • Logging, monitoring, and alerting for auditing and operational metrics.

    Baidu AI Cloud offers capabilities in these general categories. Service selection should reflect data classification, compliance requirements, and availability in the intended deployment region, rather than assuming global availability.

    The central requirement is an observable, rollback-capable lifecycle covering memory writes, retrieval, injection, and deletion.

    8. Common Pitfalls

    Four mistakes frequently undermine memory systems:

    1. Treating memory as an append-only cache: Without ongoing maintenance, low-value entries accumulate and overwhelm the prompt.
    2. Ignoring reversibility: Inadequate deletion and user controls create compliance risks.
    3. Extracting too aggressively: One-off details become incorrectly classified as long-term preferences.
    4. Omitting fallback behavior: A retrieval failure makes the entire assistant unavailable.

    A mature memory system is not defined by how many entries it stores. It is defined by whether incorrect memories can be corrected, outdated memories can be retired, and failures can degrade gracefully.