How Offline Memory for AI Cuts Cost and Latency
This article examines why updating large language model knowledge is difficult, compares continued pre-training, retrieval-augmented generation, and parametric memory, and explains how Deep Fusion Memory (DFM) uses block-level retrieval and deep fusion to reduce data construction and inference costs. It also covers practical deployment tips, common pitfalls, and how to decide between offline memory and online retrieval.
1. The Starting Point: Why Model “Retraining” Is So Hard
A model that can already write code, read contracts, and solve calculus problems often struggles to absorb a batch of new knowledge without degrading its existing capabilities. This difficulty is routinely underestimated. It is closer to asking an experienced clinician to learn a new technique: too much intensity dilutes the solid clinical instincts built over years, while too little intensity fails to teach anything real. Knowledge updates for large models face exactly this dilemma.
In engineering terms, the dilemma breaks down into three measurable metrics:
- Knowledge injection success rate: whether the model can correctly invoke facts from new corpora when answering;
- Retention of existing capabilities: whether general reasoning, coding, math, and other established abilities degrade;
- Cost per unit of knowledge: the training and inference overhead required to make the model “remember” one new piece of knowledge.
No existing approach performs well on all three at once. Each is broken down below.
2. Three Existing Approaches and Where They Get Stuck
1. Continued Pre-training: Direct but Prone to Forgetting
Continuing to train on new corpora is the simplest to implement, but the price is catastrophic forgetting. The model distribution is pulled toward the new corpora, and performance on old tasks declines monotonically with training steps. It is like someone who was good at Western cuisine spending months practicing only Chinese cooking: when they return to making an omelet, both the heat control and technique have gone rusty.
Mitigation methods (replaying old data, regularization constraints, parameter isolation) can only reduce the problem, not eliminate it, and all of them require additional compute budget.
2. Retrieval-Augmented Generation: Flexible but Dependent on Live Retrieval
Before generation, relevant snippets are fetched from an external knowledge base, concatenated into the input, and then used to answer. Its strengths are that knowledge can be updated instantly and is traceable; its weaknesses are equally clear:
- Latency: every request adds one or more retrieval hops, amplifying tail latency;
- Quality coupling: if recall is inaccurate, the model will fabricate along the wrong context;
- Context budget: long snippets crowd the window and drive up the cost of each inference.
3. Parametric Memory: A New Idea, but Uncontrollable Construction Cost
Parametric memory “internalizes” external knowledge into a small module ahead of time, so no lookup is needed at inference time; the module supplies information to assist generation. The problem lies in how the training data is constructed.
One common approach requires the model to learn “the distribution each token should exhibit under retrieval conditions,” which means that when building the corpus, a retrieval result must be prepared for almost every token. A 100,000-word book would require 100,000 reference materials, with annotation and retrieval overhead growing linearly with corpus size.
More critically, there is the fusion position. This class of methods typically performs only one probability interpolation between the retrieval information and the model’s original distribution at the output stage. This is shallow fusion: the knowledge never enters the model’s intermediate representations and is only mixed in as a bit of weight at the last moment, so it is hard to influence multi-step reasoning and hard to take effect stably in long-chain tasks.
3. Deep Fusion Memory: Saving Retrieval Cost While Making Memory Part of Thinking
A scheme called Deep Fusion Memory (DFM) addresses the two pain points above separately.
1. Block as the Granularity: Cutting Down Retrieval Count
Instead of retrieving separately for each token, the text is split into fixed-length blocks (the paper uses 32 tokens per block), each block is retrieved only once, and all tokens within the block share the same reference information.
The benefit is direct: retrieval and annotation overhead for training data drops by about two orders of magnitude, bringing corpus preparation back from “unbearable” to a “routine budget.” At the same time, sharing context within a block is more semantically coherent and avoids the fragmented noise caused by per-token retrieval.
In engineering terms, this step is equivalent to adding a layer of chunking and deduplication to the corpus pipeline:
BLOCK = 32def build_memory_samples(text, retriever, block=BLOCK):tokens = tokenize(text)for start in range(0, len(tokens), block):chunk = tokens[start:start + block]refs = retriever.search(detach(chunk)) # one retrieval per blockyield {"input": chunk, "ref": refs, "target": tokens[start:start + block]}
2. Deep Fusion: Making Knowledge Change Intermediate Representations
The second step of DFM is to inject reference information at the model’s intermediate layers, fusing it with hidden states via cross-attention or gating, so that knowledge participates in the computation of every subsequent layer rather than only weighting the output distribution. It can be understood as: retrieval results are no longer a “reference appendix” but part of working memory.
A schematic structure (pseudocode):
for layer in model.layers:h = layer.attn(h)if layer.has_memory:mem = memory_module.encode(refs) # encode external knowledgeh = layer.gate(h, cross_attn(h, mem)) # deep fusion, effective layer by layerh = layer.ffn(h)logits = model.head(h)
The observable difference brought by deep fusion is that tasks requiring “thinking while using,” such as multi-hop reasoning, long-form generation, and structured extraction, benefit significantly, while the gain for single-point factual question answering is relatively limited.
4. How Much Effort Can Be Saved: Four Dimensions of Cost
- Data construction: retrieval count drops from “once per token” to “once per block,” shortening corpus preparation from weeks to hours;
- Training overhead: only the new memory module and fusion layers are trained while the backbone parameters are frozen, so memory and compute requirements are far lower than full continued pre-training;
- Inference overhead: no live retrieval is needed, eliminating the retrieval chain and long-context concatenation, resulting in a flatter latency curve and controllable tail latency;
- Operational complexity: knowledge can be mounted, replaced, and rolled back as a module, without retraining the entire model.
It should be stated objectively that specific numbers vary with corpus size, block size, and model structure, and there is no universal fixed ratio; the dimensions above are suitable as a checklist for evaluating a solution, not as guaranteed metrics.
5. Implementation Points and Common Pitfalls
- Match block size to the task. Too small a block drives retrieval counts back up; too large a block dilutes the reference information. 32 tokens is a usable starting point and needs fine-tuning according to the corpus and task.
- Keep knowledge boundaries clear. The memory module is suited to carrying relatively stable domain knowledge (terminology, standards, internal documents); high-frequency changing facts should still be left to online retrieval.
- Make fusion layers switchable. Keeping a switch makes ablation and fault isolation easier, and allows quick bypass when abnormal knowledge injection occurs.
- Evaluate on two tracks. One set measures recall and invocation of new knowledge; the other measures retention of general capabilities. Looking at only one will lead to wrong conclusions.
- Complement online retrieval rather than replace it. Offline memory handles the low-latency “common-sense layer,” while online retrieval handles the high-freshness “fact layer”; layered scheduling is a more robust engineering form.
When deploying in the cloud, corpora and indexes can be placed in object storage, training jobs can run on a container platform, and results and latency can be observed through logging services and monitoring alerts; the relevant general capabilities of Baidu AI Cloud can serve as a foundation, with specific choices still depending on your own scale and compliance requirements.
6. Conclusion
The essence of knowledge updates is not “stuffing in more text” but choosing an acceptable balance among forgetting, latency, and cost. Block-level retrieval solves the feasibility of data construction, and deep fusion solves the effectiveness of whether knowledge truly participates in reasoning; together, they make an offline memory base a pragmatic technical path alongside online retrieval. The criterion is simple: if your scenario “needs to look up the latest facts every time,” choose retrieval; if “knowledge is stable and low latency is required,” offline memory is more cost-effective.
