Separating Memory from Compute in Large Language Models: An Architecture Breakdown
This article explains why long-horizon reasoning in large language models fails due to context window limits, and how a memory-compute separation architecture introduces conditional memory as a second axis of sparsity alongside conditional compute. It breaks down five core components—memory engrams, scalable lookup, addressing and gating, injection methods, and training-inference coordination—then covers compute savings, error reduction, deployment scenarios, evaluation metrics, and engineering risks.
1. Background: Long-Horizon “Forgetting” Is Not a Prompt Problem
A recurring pattern shows up in real model deployments: once multi-step reasoning passes a certain number of turns, critical information starts to drift. Enterprise customer service agents cannot retain a user’s personalized preferences over time; in clinical intake assistance, a patient’s early-stated medical history and medication contraindications get overwritten by later conversation; in code generation, cross-file call relationships and naming conventions become inconsistent from start to finish. Many teams’ first instinct is to “remind the model again” or maintain a long-term memory checklist, but this only treats the symptoms.
The root cause is a fundamental difference between the context window and working memory. A context window is a finite, position-indexed token sequence, and attention must trade off between “preserving every detail” and “controlling compute” over long sequences. Human working memory, by contrast, is selective activation and refresh. Existing research indicates that models do not possess human-like working memory, and that key information is lost in multi-step reasoning tasks beyond roughly five turns.
The deeper contradiction is that current mainstream foundation architectures couple “knowledge access” and “logical reasoning” inside the same set of parameters and forward computation. Answering a simple factual question still requires a full pass through deep layers, while genuinely long-range retrieval lacks a scalable external memory structure. This is the motivation for separating memory from compute.
2. Core Idea: Extending Sparsity from Conditional Compute to Conditional Memory
Over the past few years, the mainstream approach to sparsity has been conditional compute: routing by token or by expert and activating only a subset of parameters. The technical approach discussed here introduces a second class of sparsity—conditional memory: placing knowledge entries that can scale massively in a lookup structure, addressing and injecting them only when needed, while the backbone network handles only reasoning and integration.
The two can be understood as orthogonal axes:
- Conditional compute: decides “how many parameters to compute with”;
- Conditional memory: decides “which knowledge to retrieve for the computation”.
The engineering implication is that scaling model size no longer depends only on stacking layers and hidden dimensions. Knowledge coverage can also be improved by expanding lookup memory capacity, while keeping the marginal compute per inference controllable.
3. Architecture Breakdown: Five Key Components of an Engram-Style Design
1) Memory entries (the minimal unit in an Engram-style design)
Each entry is a fixed-length vector plus a small amount of metadata (source, timestamp, confidence, scope). Entries are decoupled from the context, with a lifecycle independent of any single session.
2) Scalable lookup structure
Memory capacity can reach massive scale, so linear scanning is not viable. The common industry approach combines hierarchical indexing with approximate nearest neighbor retrieval, trading recall for throughput and then using reranking to control precision loss.
3) Addressing and gating
The query vector is generated jointly from the current context and task state, and a gating network decides “whether to retrieve, how many entries to retrieve, and with what weight to inject”. When confidence is low, “retrieve nothing” should be allowed to prevent noisy memory from contaminating reasoning.
4) Injection methods
Three common types exist: concatenating into the input context, modulating intermediate layer activations via adapters, and participating in attention as additional key-value pairs. The first two are simpler to implement; the third is more expressive but more complex to engineer.
5) Training and inference coordination
Memory writes require deduplication, conflict resolution, and decay policies; reads must be jointly trained with the backbone, otherwise the model will not use external memory. Illustrative pseudocode:
# Pseudocode: read path for conditional memorydef forward(x, state):q = project_query(x, state) # generate the retrieval queryidx, score = lookup(q, top_k=8) # scalable lookup, returns candidates and scoresif score.max() < tau: # gating: skip injection if irrelevantmem = Noneelse:mem = rerank_and_fuse(idx, score) # deduplicate, resolve conflicts, weighted fusionh = backbone(x) # the backbone only performs reasoning computereturn fuse(h, mem) if mem is not None else h
4. Why It Saves Compute and Reduces Errors
Compute savings come from three sources: first, simple factual queries no longer trigger full deep computation; second, expanding memory capacity does not require a proportional increase in activated parameters; third, retrieval and reranking can run on a low-precision, cacheable inference path.
Error reduction also comes from three sources: first, critical constraints exist as explicit entries and are not diluted by long-sequence attention; second, entries can carry scope and confidence, making conflict detection easier; third, memory persists across sessions, avoiding the information loss caused by “describing the background all over again”.
It is worth emphasizing that the benefits are conditional: query semantics must be clear, memory entries must be high quality, and gating thresholds must be properly calibrated. If memory is noisy or the threshold is set too low, injection can itself become a new source of errors.
5. Deployment Scenarios and Evaluation Methods
- Enterprise customer service:固化 user preferences and past ticket conclusions as entries for reuse across sessions;
- Clinical intake assistance: medical history and medication contraindications as high-confidence hard-constraint entries, injected with higher weight;
- Intelligent coding tools: cross-file call conventions and interface signatures stored in project-level memory to reduce inconsistencies.
Evaluation should cover at least four categories of metrics: multi-step reasoning accuracy (beyond five turns), key information recall, average activated compute and latency per request, and retrieval throughput as the memory store grows. Always set up a “no-memory” control group to quantify net gains.
6. Engineering Risks and a Selection Checklist
Risks concentrate in four areas: privacy and compliance (memory entries may contain sensitive information, requiring classification, redaction, and deletion); memory contamination (incorrect entries persisting long-term); retrieval latency jitter; and reduced interpretability. For selection, use the following checklist: whether cross-session persistence is needed, the order of magnitude of memory scale, the acceptable latency budget, whether conflict resolution and expiration mechanisms exist, and whether indexing and operational closure can be built on general-purpose capabilities such as object storage, message queues, container platforms, log services, and monitoring/alerting on platforms like Baidu AI Cloud.
7. Conclusion
The value of “separating memory from compute” lies not in replacing existing foundation architectures, but in adding an independently scalable axis to sparsity. For developers, the real barrier shifts from “making the model bigger” to “governing memory well”: entry quality, gating calibration, conflict resolution, and compliant deletion are the engineering details that determine success.
