Cortex: Integrating context into parameterized memoryCortex: Consolidating Context into Parametric Memory
Cortex writes context gains into the FFN; at 14B, after 50 edits, Structural CR is 88.9% and RR is 99.8%.
- Context can temporarily improve performance, but when parameters are unchanged, the gain does not automatically persist after the context is removed. The authors unify editing, skill learning, behavior guidance, and knowledge suppression under the same goal: recovering that gain and preserving non-target capabilities after each update.
- Cortex uses the frozen pre-update model to generate look-ahead queries and contextual answers; the student removes the context and trains only new low-rank or structured FFN parameters. Supervision is the output distribution KL and the post-FFN hidden state MSE; sequential updates can replay historical queries without storing old contexts.
- The authors say Cortex lies on the CR–RR frontier in most settings. After 50 fact edits on 14B, Structural's CR is 88.9% and RR is 99.8%. On GPT-OSS-20B's τ2-Bench, Synaptic's CR is −92.3%.
- Section 7 lists cross-task continual consolidation, large-batch consolidation, pruning and merging of structural expansions, and using hypernetworks to predict structural parameters from context as future work. The sequential fact editing experiments focus on Qwen2.5-14B-Instruct with 50 zsRE.
- Evaluated models
- Qwen2.5-14B-InstructQwen3-4B-InstructQwen3-4B-ThinkingGemma3-12B-InstructGPT-OSS-20BGPT-OSS-120B
- Benchmarks
- ALFWorldτ2-BenchNovel API learningPower-seekingPsychopathyRWKUBBHZsREMMLUSimpleQALiveCodeBenchGSM8KMATH-500AIME 2026
- Metrics
- CRRRpass@1ROUGE-L recallefficacygeneralizationportabilitylocality
The paper proposes Cortex, which internalizes the performance gains from context into model parameters while preserving non-target capabilities. The method generates forward-looking queries to predict context usage, then distills context-conditioned outputs into mergeable low-rank or structured feedforward network updates. The authors test on dense and MoE backbones from 4B to 120B, covering text-only and multimodal models. The paper claims Cortex lies on the Pareto frontier of merging and preservation in most evaluation settings. After 50 sequential fact edits on a 14B model, Cortex-Structural recovers 88.9% of the context gain and preserves 99.8% of original non-target performance.
Paper analysis
What problem does this paper attempt to solve?
Context gains are lost after the context is removed; the goal is to write into parameters and preserve non-target capabilities.
Core question: How can behavioral gains from context remain in parameters after the context is removed, without harming non-target capabilities.
- Scenario: The authors argue that for an agent to accumulate experience, past experience must continue to influence subsequent behavior. Context can temporarily improve performance, but standard in-context inference does not change parameters, so gains are not automatically preserved after context removal; external memory relies on retrieval at inference, and indirectly relevant experiences may be missed.
- Existing limitations: Knowledge editing, skill learning, behavior guidance, and knowledge suppression are often studied separately and use specialized interfaces such as fact-editing requests or forget/retain datasets. The authors argue these settings do not facilitate comparison under a unified requirement: no-context reuse, generalization, and preserving original capabilities after each update.
- Core observation: If context creates a positive performance gap on target queries, the authors call this a memory failure: it is usable with context but lost without. Low performance that context cannot compensate for is called a capability failure, which is not the target of this paper.
- Proposal: The authors formalize this goal as Memory Consolidation (MC) and provide Cortex with a five-task-family testbed. Cortex generates look-ahead queries and distills contextual outputs into mergeable low-rank or structured feed-forward network (FFN) updates; the testbed uses Consolidation Rate (CR) and Retention Rate (RR) to measure single, batch, and sequential updates.
What related research exists?
The authors map external memory, editing, distillation, and continual learning to the same consolidation goal.
The authors organize related work by how memory is accessed, how behavior is specified, and how changes are written into parameters.
- Memory representation and access: retrieval-augmented generation accesses external information; agent memory stores interactions, reflections, and reusable lessons; context compression lowers the cost of presenting that information. Parametric or latent external memory includes PRAG (retrieval-document-specific LoRA), DyPRAG (generating updates from retrieved documents), Cartridges (learned KV caches), and MemGen (a separate memory weaver generating latent memory for a frozen reasoner). The authors note that parameterization does not determine access, and parametric memory itself is not consolidation.
- Task-specific and test-time adaptation: knowledge editing specifies fact changes, unlearning specifies information to suppress or remove, steering specifies target behavior; IKE does fact editing with in-context examples, and retrieved documents and lessons can also guide later decisions. The authors say MC asks whether these effects can persist after the context is removed. Test-time training adapts with information encountered at deployment; the authors distinguish: it describes when adaptation happens, while MC concerns the persistence and later utility of the resulting change.
- Context distillation and injection: Snell et al.'s context distillation trains a context-free student to reproduce a context-conditioned teacher; Deep Context Distillation applies it to document knowledge modules; SELF-PARAM studies single, batch, and sequential injection of context. The authors' distinction: the former assumes a task input distribution is already provided, while MC hands the method learning data constructed from context; SELF-PARAM's retention criterion targets previously injected context, while MC also requires preserving the initial model's capabilities beyond the cumulative target changes after each update.
- Write location, update methods, and continual learning: key-value interpretations of FFNs and localization of fact associations are used to support treating FFNs as memory substrates; the authors also write that attention participates in fact recall, and causal localization by itself does not determine whether an edit is effective. ROME and MEMIT update selected MLP layers, AlphaEdit constrains update directions, LoRA uses low-rank increments; Transformer-Patcher and Locas add neurons or FFN-compatible branches. Unlike WISE, GRACE, and SERAC, which use memory routing, activation lookup, or auxiliary counterfactual models at inference, the authors say both Cortex variants fold into standard FFN or MoE layers and need no separate recall mechanism. OPCD and SDFT take teacher supervision along an evolving student trajectory; Cortex does teacher forcing on an offline, fixed trajectory. HyperTuning, Text-to-LoRA, Doc-to-LoRA, and SHINE generate adaptation parameters from tasks or contexts; the authors say such generators amortize adaptation through shared training, while Cortex directly optimizes each context's update with rehearsal data and teacher signals. For continual learning, the authors also compare TRACE, regularization and expansion methods, and designs that write persistent state into the architecture such as MemoryLLM, Titans, HOPE, MLP Memory, and Engram.
- Baselines and benchmarks: experiments compare task-specific edits (FT-M, ROME, MEMIT, AlphaEdit, WISE), distillation (OPCD, SELF-PARAM, SDCD), hypernetworks (Doc2LoRA, SHINE), test-time training (Locas, δ-Mem), and external program memory MemP. Evaluation uses five task families; the retention set includes MMLU, SimpleQA, math benchmarks chosen by backbone, LiveCodeBench, BBH, and RWKU Neighbor.
The authors position the paper as: using context as a common description of the desired change, and after removing context, simultaneously requiring recovered gains and preserved non-target capabilities; Cortex is compared with the above lines on what to learn, where to write, and how to update.
How does the paper address this problem?
Cortex uses look-ahead queries to construct targets, then distills teacher behavior into mergeable FFN updates.
Cortex uses the frozen pre-update model for both rehearsal generation and teacher, trains only newly introduced FFN parameters, and distills context-conditioned behavior into a context-free student. The design corresponds to three questions: what to consolidate, where to write, and how to limit interference.
Problem setup and metrics
- Input and output: given model M and a temporarily available context set C. Query q elicits answer y, or an agent interaction trajectory. Perf is a non-negative, higher-is-better expected score.
- Goal: for non-trivial contexts, find M′=A(M,C). At inference, C is not accessed; recover the context gain on target queries and maintain original performance on retention queries. The method does not receive a developer-specified task input distribution; evaluation queries and answers do not enter rehearsal construction or gradient-based training.
- Two ratios: the context gap is the difference between target scores with and without context. CR = (Perf(M′, Q+C) − Perf(M, Q+C)) / Δctx(M, Q+C, C) is the fraction of gain recovered; RR = Perf(M′, Q−C) / Perf(M, Q−C) is the fraction of non-target performance retained. Both can exceed 1. The authors say reliable interpretation requires a large gap and a positive retention baseline.
- Three protocols: single n=1; batch n>1; in sequential updates, new context is written into Mt−1 to get Mt, and past contexts cannot be stored or revisited after the update. After each step, still-valid consolidated memories are evaluated, and non-target capabilities are relative to the initial model M0.
Look-ahead rehearsal
- Construction: the pre-update model generates queries and answers. The prompt requires queries to anticipate the use of the context; answers are sampled conditioned on the context. The authors say using the model's own answers reduces distribution mismatch from externally written targets and limits forgetting. An optional filter may keep all candidates.
- Agent exception: queries for ALFWorld and τ2-Bench come from the training environment, and the filter keeps only successful offline trajectories. Empirical contexts are attached to these queries; the consolidation phase does not interact with the environment. Rehearsal does not access held-out evaluation queries or answers.
- Batch and sequential: batch can concatenate contexts before constructing samples, or construct separately and merge, keeping the teacher context for each sample. In the sequential setting, earlier writes are frozen; current rehearsal can include replay of historical queries.
Two plasticities on FFNs
- Substrate: the authors choose MLP parameters. Synaptic adds low-rank increments of rank at most r to existing gate, up, and down projections, with original matrices frozen. Structural adds k nonlinear channels, the original weight block is fixed, and at deployment the intermediate width grows from dff to dff+k. Both can fold into weights.
- MoE: router parameters are frozen, but upstream representation changes can still change routing. Independent expert expansion gets direct training gradients only through the selected weighted path. The authors use a shared branch: when routing weights sum to 1, the branch can fold equivalently into each expert, and every token passes through the same new parameters.
- Representation results: Appendix A gives sufficient conditions for fixed Structural parameters to exactly match a given FFN correction on a finite state set, and shows that independent expansion has direct gradients with routing coefficients, while shared expansion pools signals across positions. The authors say this provides a representational rationale for local hidden-state distillation in FFNs; behavior on unseen states depends on the learned approximation and rehearsal coverage. Cortex learns updates with gradient optimization, not by directly applying the construction.
Context-to-memory distillation
- Teacher and student: the teacher receives sequences containing C, the student removes C; both can use the same fixed scaffold and train on teacher-forced answers y. The teacher is the frozen pre-update model; the student trains only new parameters: Synaptic's low-rank factors or Structural's new channels. Existing parameters and earlier writes stay frozen.
- Loss: minimize truncated forward KL at aligned positions plus MSE of hidden states after FFN residual updates. KL keeps the teacher's top-Kv vocabulary entries, the teacher distribution is normalized over that subset, and the student still normalizes over the full vocabulary. Supervised positions are chosen by task as answer or action prediction positions, or all aligned non-context positions, excluding padding. An empty supervision set contributes 0.
- Replay and generic samples: optional query replay keeps only earlier queries, regenerates answers with the pre-update model, and does not save past contexts; on replay samples the teacher and student inputs are the same, and the buffer is not used for inference. A small number of generic queries with the model's own answers are mixed into rehearsal data. In continual editing, these generic answers and distillation targets are generated once by the initial model and cached.
How the testbed operationalizes the goal
- Five families: agent experience consolidation, new API learning, personality steering, knowledge suppression, fact editing. They cover procedural, behavioral, and declarative memory, and addition, revision, suppression, and local or global scope. Scope describes expected effect, not parameter location.
- Contexts: hand-constructed by task source and adjusted by backbone when needed to elicit a large context gap; construction does not use held-out evaluation queries or reference answers. Personality steering is evaluated only in the single setting because the chosen personality instructions may conflict. Psychopathy does not report RR.
- Scoring: compare the context-free original model, the context-conditioned original model, and the updated model with the source context removed. Repeated generations are aggregated within a query or turn, then averaged across items and merged across task components; CR and RR are computed from these aggregated scores, not by averaging component ratios.
What experiments did the paper conduct?
Structural on 14B after 50 edits has CR 88.9% and RR 99.8%; the authors state most settings lie on the CR–RR frontier.
Experimental Setup
- Backbones: Qwen2.5-14B-Instruct, Qwen3-4B-Instruct, Qwen3-4B-Thinking, Gemma3-12B-Instruct, GPT-OSS-20B, GPT-OSS-120B. The authors state coverage spans 4B–120B dense and MoE models, including instruction-tuned, thinking, and multimodal models; all experimental inputs are text. Coverage varies by task, see Table 2.
- Task Scale: Agent experience with 2 context segments; new API with 15 packages, 150 executable problems (7 usage and 3 debugging per package); personality with 2 instruction segments; knowledge suppression with 10 entities; fact editing with 50 non-conflicting facts. Single updates are applied per context individually, batch updates write multiple contexts into the same model.
- Baselines: No-context Vanilla, Context with context provided at inference, and task-specific editing, distillation, hypernetwork, and test-time training baselines. Baselines requiring hyperparameter tuning select hyperparameters and training duration on held-out query CR, with retention scores not used in selection, then retrain and evaluate on target test queries with full repetitions.
- Metrics: CR is the proportion of recovered context gain, RR is the retention proportion under the specified retention criteria. API uses pass@1; RWKU Forget/Neighbor uses ROUGE-L recall, with suppressed CR using 1−R; editing targets are the average of efficacy, generalization, portability, with locality included in retention.
- Judging and Repetitions: Editing and Power-seeking are judged by Gemini 3 Pro; SimpleQA is judged by gpt-4.1-2025-04-14 at temperature 0 with three-way classification. Editing uses 7 generations per question. Power-seeking has 200 questions with 5 generations each, CR from concept mean, RR from fluency mean of the same batch. Psychopathy has 1,000 questions with 3 generations each, RR not reported. ALFWorld evaluation seeds are 2026, 2027, 2028.
- Sequential Protocol: The same sequence of 50 zsRE edits on Qwen2.5-14B-Instruct, seeds 43, 44, 45. Cortex trains a new adapter each step and freezes the backbone and old adapters; Structural uses k=1, Synaptic uses r=1. Each step has 30 epochs, learning rate 5×10−4. Historical query replay does not revisit source contexts. After each step, seen facts are evaluated with 7 generations; every 5 steps, fixed subsets of MMLU, SimpleQA, and GSM8K are evaluated.
Main Results
The final accuracy after 50 sequential fact edits is as follows. Table shows mean of three runs; sample standard deviation in Figure 6(a).
Swipe horizontally to read the table
Method Efficacy Generalization Portability Locality Vanilla 2.9 4.3 19.1 40.3 FT-M 22.8 15.7 17.8 32.7 ROME 26.2 28.9 39.0 32.2 MEMIT 22.9 22.1 36.5 35.1 AlphaEdit 21.6 23.1 35.6 34.8 WISE 34.3 27.7 30.9 39.7 Cortex-Synaptic 95.6 91.7 30.7 33.8 Cortex-Structural 95.3 93.1 49.4 38.3 - CR and RR: The authors report that after 50 edits, Structural and Synaptic have CR of 88.9% and 80.6%, and RR of 99.8% and 97.2%; by final CR, the strongest baseline ROME is 28.5% (Figure 6(a,b)). The introduction states Structural is 66.2 and 3.8 percentage points higher than AlphaEdit. Per-step new parameters are 0.74M and 2.73M. Appendix B.2 specifies that this RR is the ratio relative to a 55.00% reference after equal-weight aggregation of locality, MMLU, SimpleQA, GSM8K, not that each dataset reaches 99.8%.
- Authors' interpretation: The authors state that large context gains can be accumulated through small sequential updates while largely retaining evaluated capabilities. Final efficacy is similar for both variants, but portability is 49.4% vs 30.7%; the authors state that for both variants, providing the updated fact answer is easier than applying it on the evaluated compositional questions.
- Local retention: In Figure 6(a), Structural locality is 38.3, lower than Vanilla's 40.3; MMLU is 81.7 vs Vanilla's 80.9. Aggregate RR near 1 does not imply every retention metric is above the original model.
Single and Batch Consolidation
- Frontier and task differences: Among no-context methods with both CR and RR, the authors state that in each of the 15 panels of Figure 5, at least one Cortex variant lies on the empirical CR–RR Pareto frontier. The authors state that both variants recover approximately 95–100% of context gain on guiding tasks, and fluency-based RR is approximately 99–100% on Gemma3 and Qwen2.5; batch editing CR across three Qwen backbones is approximately 80–91%.
- Baseline trade-offs: The authors report Doc2LoRA achieves 95% CR on single editing on Qwen3-Instruct, higher than Cortex's 84–89%, but locality-based RR is 86% vs Cortex's 103–110%; in batch editing, Doc2LoRA only has 24% CR. In the shown suppression comparison, SHINE has CR of approximately 100–103% but RR of only 4–10%. On two Qwen batch code tasks, LoCAS and δ-Mem have RR of approximately 98–101% and CR of −9% to 11%, versus Cortex 47–74%. On Qwen2.5 batch code, Cortex has 66–74% CR and 98–99% RR; OPCD has 41% CR and about 100% RR, SELF-PARAM and SDCD have 29% and 19% CR.
- Exceptions: On ALFWorld with GPT-OSS-20B, Structural and Synaptic have CR of 97% and 101%, RR of 95% and 23%. On τ2-Bench, Structural CR is 38.5%, Synaptic −92.3%; success rates are 62.0% and 56.3%, Vanilla 60.3%, Context 64.7%, Synaptic RR remains 98.5%. GPT-OSS-20B suppression CR is 97–100%, RR 76–83%. In Appendix B.3.1, on Qwen2.5-14B batch editing, LoRA-CE on the same Cortex data achieves 91.9% CR, Synaptic 90.8%, Structural 88.6%.
Acquisition, Retention, and Termination in Sequential Updates
- Immediate to final: Figure 6(c) compares immediately after writing vs checkpoint 50 for all 50 facts. Structural CR goes from 91.3% to 88.9%, Synaptic from 85.8% to 80.6%; the authors state corresponding drops of 2.4 and 5.2 points. WISE goes from 52.0% to 28.0%, the authors state losing 24.0 points.
- Early facts: After the first 10 facts undergo 40 more edits, Structural and Synaptic have average CR of 97.2% and 92.6%. Portability already has gaps at the time of writing: Structural from 52.4% to 49.4%, Synaptic from 36.1% to 30.7% (Table 7).
- Termination modes: At checkpoint 50, within a 512-token observation window, repetition or length-limit termination accounts for 0.0% of Structural answers, 0.8% of Synaptic, while FT-M, ROME, MEMIT, and AlphaEdit are 86.2–91.3% (Figure 6(d)). 700 answers per round. The authors state all Cortex answers end before 512 tokens.
Other Ablations and Analyses
- Same Cortex data: On Qwen2.5-14B batch code, Structural is 23.0 CR points higher than LoRA-KL; on GPT-OSS-120B, LoRA-KL is 16.6 points higher than LoRA-CE (Figure 7(a,b)).
- Sequential editing with r=4, KL: updating only FFN yields CR and RR 3.8 and 4.0 points higher than updating attention as well (Figure 7(c)).
- Removing historical query replay, the efficacy/rephrase accuracy of the first 25 facts after 25 more edits: Structural 40.5%, Synaptic 8.0%; with replay both are above 96% (Figure 7(e)). Final CR without replay is 45.9% and 6.6%, with fixed QA replay 88.1% and 81.3% (Appendix B.3.3).
- Synaptic r=4 with hidden state MSE: RR increases 2.7 points, CR decreases 4.0 points; Structural k=16 improves both (Figure 7(f), Figures 19–20).
- Under the same total weight budget, shared MoE is 4.6 CR points higher on ALFWorld and 10.3 points higher on Code than independent expansion, with RR about 1 point lower (Figure 7(h,i)). On ALFWorld, 32 of 768 layer–expert branches have exposure below 1% of the layer mean in every seed (Figure 7(l)).
- Under the same KL+MSE recipe, the smallest capacity per family has the highest mean CR; Structural k=1 has 88.9% CR and 0.74M parameters per step. Increasing trainable parameters does not consistently improve performance (Figure 7(m,n)).
What are some points that can be further explored?
The authors list cross-task continual consolidation, pruning and merging of structural expansions, and hypernetwork amortization as future work.
Limitations and Future Directions Noted by the Authors
- Cross-task continual consolidation: Section 7 lists cross-task continual consolidation as future work.
- Large-batch consolidation: Section 7 lists large-batch consolidation as future work.
- Tidying structural expansions: Section 7 proposes pruning and merging for structural expansions.
- Amortizing consolidation cost: Section 7 proposes using a hypernetwork to predict structural parameters from context to amortize consolidation cost.
Experimental Coverage
- Backbones and inputs: Experimental backbones are Qwen2.5-14B-Instruct, Qwen3-4B-Instruct, Qwen3-4B-Thinking, Gemma3-12B-Instruct, GPT-OSS-20B, GPT-OSS-120B; the authors state scale 4B–120B, including dense and MoE, and experimental inputs are text (Section 5.1, Table 2).
- Tasks and protocols: The five task families support single, batch, or sequential per Table 1, but Figure 4 notes this is protocol support, not that every task–setting combination has full experiments. Personality guidance only evaluates single; τ2-Bench backbone is GPT-OSS-20B (Table 2). Sequential editing is fixed-order 50 zsRE on Qwen2.5-14B-Instruct with three seeds (Section 5.2, Appendix B.2).
- Baselines and ablations: Single and batch baselines include task-specific methods, distillation, hypernetworks, and test-time training; sequential editing baselines are FT-M, ROME, MEMIT, AlphaEdit, WISE. Ablations compare LoRA, FFN vs attention, query replay, hidden state MSE, MoE sharing, and update capacity on Cortex data (Section 5.3).
- Judging and repetitions: Editing and Power-seeking use Gemini 3 Pro, SimpleQA uses gpt-4.1-2025-04-14. Editing uses 7 generations per question; sequential protocol general capabilities are tested every 5 updates, with subsets fixed by seed 42 (Appendices B.1–B.2, Table 4). The paper reports sample standard deviation across three runs and does not report statistical significance tests.
- Unreported retention scores: Table 1 states Psychopathy does not report RR; Power-seeking RR is fluency on the same batch, which the authors state does not measure broad capability retention. Supplementary MMLU and SimpleQA for suppression tasks are reported separately.
Summarize the main content of the paper
Cortex writes context gains into FFN; after 50 edits on 14B, Structural CR is 88.9% and RR is 99.8%.
Cortex studies how to write behavior gains already provided by context into parameters so they remain usable after the context is removed, while preserving non-target capabilities. The authors call this goal Memory Consolidation, unifying context-specified knowledge editing, skill learning, behavior steering, and knowledge suppression.
- Problem: a positive context gap is treated by the authors as a memory failure. The updated model cannot see C at inference, must recover that gain on target queries, and maintain original performance on retention queries; after sequential updates it cannot revisit old contexts.
- Method: the frozen pre-update model generates look-ahead queries and context-conditioned answers, without accessing held-out evaluation data. The student removes the context and trains only new FFN parameters. Synaptic is a low-rank increment, Structural is new nonlinear channels; on MoE a shared branch is used with the router frozen. Supervision is truncated output KL plus MSE of hidden states after FFN. Sequential updates can keep only historical queries and regenerate answers.
- Testbed: five task families support single, batch, and sequential protocols, scored with paired CR and RR. Contexts are hand-constructed by backbone.
- Results: the authors say Cortex lies on the empirical CR–RR Pareto frontier in most evaluated settings. After 50 zsRE edits on Qwen2.5-14B-Instruct, Structural has CR 88.9% and RR 99.8%, Synaptic 80.6% and 97.2%; the authors say the strongest baseline by final CR, ROME, is 28.5%. Structural's portability is 49.4%, below its 95.3% efficacy. There are also reverse cases: on GPT-OSS-20B's τ2-Bench, Synaptic's CR is −92.3%, success rate 56.3% below Vanilla's 60.3%, while RR remains 98.5%.
- Authors' conclusion: the authors believe small successive FFN updates can accumulate context gains and maintain high RR on evaluated non-target capabilities; the write form affects what is gained and retained. Section 7 lists cross-task continual consolidation, large-batch consolidation, pruning and merging of structural expansion, and using hypernetworks to predict structural parameters as future work. The authors plan to release the testbed publicly and open-source the implementation.