Dual-Mode Memory Systems: On-Demand Retrieval and Editable Memory
This article explores the dual-mode memory architecture for multi-turn conversational agents, which combines classic memory (session context and rolling summaries) with file memory (structured, editable documents). It covers the responsibilities of each layer, the lifecycle of file memory from extraction to retrieval, intent-based routing and hybrid recall strategies, governance requirements such as traceability and conflict resolution, and evaluation metrics and best practices for building scalable, auditable long-term memory.
1. Background: Why a Single Summary Cannot Sustain Long-Term Memory
As multi-turn conversational assistants are used over time, they accumulate large amounts of information: user preferences, project constraints, historical decisions, coding conventions, schedules, and domain knowledge. Relying solely on in-session context or rolling summaries quickly leads to two bottlenecks. The first is a capacity bottleneck: summaries have limited length, and compressed information is hard to restore losslessly. The second is a retrieval bottleneck: a summary is a mixture—technical discussions may get polluted with travel preferences, while business-rule discussions may miss critical constraints. Simply enlarging the context window alleviates short-term issues but cannot replace long-term, structured, and governable memory management.
A common industry practice is to compress conversation history into summaries or extract a small set of facts. Such “classic memory” is well suited for maintaining immediate continuity, high-confidence user profiles, and short-term task state. However, for large volumes of reusable knowledge, a second form is needed: “file memory,” which uses structured documents as its carrier. The core of a dual-mode memory system is not simply stacking two storage layers, but making the two types of memory work together in terms of responsibility, lifecycle, retrieval path, and governance strategy.
2. Dual-Mode Architecture: The Boundary Between Classic Memory and File Memory
A dual-mode memory system typically consists of two layers:
- Classic memory layer: responsible for in-session context, rolling summaries, short-term task state, high-confidence preferences, and recent facts. It is read and written frequently, latency-sensitive, capacity-constrained, and emphasizes immediate continuity.
- File memory layer: responsible for automatically organizing chat information into structured documents, organized by domain, topic, project, or user, and retrieved on demand. It is scalable in capacity, editable, and auditable, emphasizing long-term reuse and precise recall.
The two layers are not substitutes but complements. Classic memory answers “what continuity does the current conversation need to maintain,” while file memory answers “what long-term knowledge is relevant to this question.” In each turn, the system first identifies intent and task stage, then obtains immediate state from classic memory, retrieves domain documents from file memory, and finally fuses them into a controlled context.
It is important to note that “theoretically scalable” does not mean zero cost. The logical capacity of file memory is not limited by a single summary’s length, but it is still constrained by storage cost, index size, retrieval latency, permission governance, and consistency maintenance. In engineering practice, costs should be controlled through hot/cold tiering, archiving, deduplication, and on-demand loading.
3. The File Memory Lifecycle: From Conversation to Retrievable Documents
File memory should not equate to “slicing all chat logs into a database,” which would introduce noise, duplication, and privacy risks. A more reasonable lifecycle includes:
- Extraction: identify reusable facts, preferences, constraints, decisions, and domain knowledge from conversations, distinguishing temporary information from long-term information.
- Classification: create documents or entries by user, project, domain, and topic to avoid cross-domain pollution.
- Structuring: organize content into fields such as title, body, fact key-value pairs, source, confidence, validity period, and permissions.
- Deduplication and merging: merge repeated occurrences of the same fact; route conflicts into a conflict-resolution process.
- Indexing: build keyword indexes, semantic indexes, and metadata indexes to support hybrid recall.
- Retrieval and use: route by intent to relevant domains, rerank recalled results, and inject them into the context.
- Update and deletion: allow users to browse, edit, and delete memory files, with versioning and audit records retained.
- Archiving and expiration: archive or clean up low-value, expired, or low-confidence memories.
An illustrative memory file data model is as follows:
{"memory_id": "mem_001","scope": "user_project","domain": "software_engineering","title": "Project Build Constraints","content": "This project requires running static checks before commits and maintaining API compatibility.","facts": [{"key": "build.check", "value": "static check before commit", "confidence": 0.92},{"key": "api.compatibility", "value": "maintain backward compatibility", "confidence": 0.88}],"source": {"conversation_id": "conv_123", "message_ids": ["m1", "m2"]},"version": 3,"status": "active","created_at": "2025-01-01T10:00:00Z","updated_at": "2025-01-05T09:00:00Z","ttl": "project_end","permissions": {"editable_by_user": true}}
The value of this model is that memory is no longer an unexplainable summary fragment, but a data asset with source, confidence, version, and permissions. Users can browse, edit, and delete any memory file just like editing a knowledge base entry, and the system can trace which conversation a memory came from, when it was modified, and which requests used it.
4. On-Demand Retrieval: Intent Routing and Hybrid Recall
The key capability of dual-mode memory is “on-demand retrieval.” When a user asks a coding question, the system should prioritize technical documents, project conventions, and API constraints; when the user discusses travel, it should retrieve travel preferences, schedules, and budget constraints. The implementation can be divided into four steps:
- Intent recognition: determine the domain, task type, and required memory scope of the current query.
- Domain routing: select candidate document sets based on intent to reduce cross-domain noise.
- Hybrid recall: within the candidate set, combine keyword matching, semantic similarity, and metadata filtering.
- Reranking and trimming: rank by relevance, recency, confidence, source reliability, and explicit user edits, then trim to fit the context budget.
Illustrative pseudocode:
function retrieve(query, user, session):intent = classify_intent(query)domains = route_domains(intent, session)candidates = []for domain in domains:candidates += lexical_search(query, user, domain)candidates += vector_search(query, user, domain)candidates += metadata_filter(user, domain, intent)ranked = rerank(candidates, weights={"relevance": 0.45,"recency": 0.20,"confidence": 0.20,"user_edited": 0.15})return top_k(ranked, context_budget)
After retrieval, “memory fusion” should be performed: merge the immediate state from classic memory with long-term knowledge from file memory, and flag uncertainty for conflicting information. For example, if a user earlier expressed a preference for one approach but later explicitly changed it, the explicit edit should take precedence over the old summary; if a source has low confidence, it should not be injected as a hard constraint.
5. Editability and Governance: Managing Memory as a Data Asset
Editability is a key feature distinguishing dual-mode memory from pure summarization approaches, but it also introduces governance requirements:
- User visibility and control: provide entry points for listing, viewing, editing, deleting, and disabling memories.
- Source traceability: each memory retains its source conversation, message fragments, extraction time, and update history.
- Conflict resolution: adopt strategies such as “explicit user edits first, then recency, then source confidence, with domain isolation,” so that stale information does not override new decisions.
- Permissions and isolation: scope memories by user, project, and tenant, and enforce metadata filtering during retrieval.
- Privacy and compliance: classify and grade sensitive information, with support for redaction, encryption, retention periods, and deletion propagation.
- Quality monitoring: track memory pollution rate, false recall rate, user revocation rate, and edit rollback rate.
- Audit and versioning: record who modified which memory and when, supporting rollback and issue diagnosis.
In engineering practice, memory content can be stored in object storage, with metadata and indexes kept in databases or retrieval services. Extraction, merging, and index updates can be handled through asynchronous queues, while logging services and monitoring alerts track write failures, retrieval latency, and abnormal deletions. When deployed on Baidu AI Cloud, general-purpose capabilities such as object storage, logging, and monitoring/alerting can be used to build the underlying infrastructure; specific choices should be based on compliance, cost, and performance evaluations.
6. Evaluation and Best Practices
Evaluating a dual-mode memory system should not focus only on “how much is remembered,” but on “whether what should be remembered can be recalled, whether what should not be remembered can be suppressed, and whether erroneous memories can be corrected.” Recommended metrics include: domain recall rate, precision, context token savings, time to first token, memory pollution rate, user edit rate, deletion effectiveness latency, and task completion rate. Best practices include: establish domain isolation before semantic recall; store high-confidence facts and low-confidence inferences in separate tiers; set expiration periods for temporary information; give explicit user modifications the highest priority; inject retrieval results together with source identifiers so the model can distinguish facts from inferences; and build offline evaluation sets covering cross-domain interference, conflicting updates, and deletion propagation scenarios.
In summary, a dual-mode memory system overcomes the capacity and noise bottlenecks of a single summary through a clear division of labor: classic memory preserves continuity, while file memory preserves long-term retrievability. The engineering difficulty lies not in storage itself, but in structured extraction, on-demand routing, conflict resolution, user control, and end-to-end governance. When these elements are done well, memory capability can evolve from unexplainable context compression into a scalable, auditable, and evolvable long-term knowledge asset.
