Manuscript Offprint

arXiv:2610.20399

Cortex: Consolidating Context into Parametric Memory

Jintian Zhang, Feng He, Xinnian Liang, Ziwen Xu, Haoming Xu, Haojing Huang, Shuangzhi Wu, Ningyu Zhang

Abstract

Context can improve large language model performance, but these gains may be lost after context removal. Inspired by biological systems consolidation, we formulate Memory Consolidation (MC) as internalizing these gains while preserving non-target capabilities, connecting context-specified editing, skill learning, and behavioral steering under a common objective. We introduce a five-task-family testbed measuring consolidation and retention under single, batch, and sequential updates. We propose CORTEX, which generates prospective queries to anticipate uses of context and distills context-conditioned outputs into mergeable low-rank or structural feed-forward network updates. Across 4B–120B dense and mixture-of-experts backbones, including both text-only and multimodal models, CORTEX lies on the empirical consolidation–retention Pareto frontier in most evaluated settings. After 50 sequential factual edits on a 14B model, CORTEX-Structural recovers 88.9% of the context-induced gain while retaining 99.8% of original non-target performance.

Date: October 15, 2026

Correspondence: Jintian at mikedean.2367@bytedance.com, Ningyu Zhang at zhangningyu@zju.edu.cn

Code: https://github.com/zjunlp/cortex

Figure

Rapid Episodic Encoding (Hippocampus)

Neocortex

Distributed storage

across cortical areas over time

Hippocampus

Initial encoding and

temporary storage

"Systems Consolidation"

Figure

Long-term

Representation

(Neocortex)

a) Biological Systems Consolidation

Figure

b) Memory Consolidation in LLMs.

Figure 1 Biological inspiration and the memory consolidation objective.(a) Hippocampal–neocortical interactions support integration of newly acquired information into long-term cortical memory.(b) MC aims to transform a context-conditioned model M into an updated model M′M' that retains the context-induced gains without the original context C, while preserving non-target capabilities. The highlighted FFN region represents the learned changes in CORTEX.

1 Introduction

The value of experience extends beyond the situation in which it is acquired. New knowledge can inform later inferences, learned procedures can support unfamiliar tasks, and feedback can guide subsequent decisions. Building agents whose capabilities accumulate over time therefore requires mechanisms that allow past experience to continue shaping future behavior. In humans, long-term memory supports such reuse, while systems consolidation helps integrate new experiences with existing knowledge. The complementary learning systems (CLS) framework describes how rapid hippocampal encoding and slower neocortical learning, supported by reactivation and replay, contribute to this integration while limiting interference with prior knowledge [42, 55], as illustrated in Figure 1. Beyond preserving individual experiences, consolidation can reshape internal representations and sometimes promote insight into more general regularities [82].

Language models can already exploit new information when it is provided in context [7]. Given documentation for an unfamiliar API, for example, a model can combine it with existing programming knowledge to produce correct calls. When this improves performance, the resulting behavior offers a concrete reference for what the experience can teach. However, conventional in-context inference leaves model parameters unchanged, so these gains do not automatically persist once the supporting context is removed. External memory systems can preserve experiences or derived knowledge for later use [45, 62], yet their contribution depends on retrieving and supplying relevant content at inference time; indirectly relevant experiences may be overlooked. Parameter updates offer a complementary route: encoding useful effects of experience in parametric memory, which can be accessed through attention and feed-forward computation, with additional reasoning sometimes helping surface otherwise hard-to-recall knowledge [25, 28]. This motivates our goal: consolidating context-induced behavioral gains into the model so they persist and generalize to related queries without supporting context, while preserving previously acquired capabilities.

We formalize this objective as Memory Consolidation (MC) for LLMs (Fig. 2). Given a model M and a context C that substantially improves performance under task-specific criteria, MC seeks an updated model M′M' that operates without C, recovers the context-induced gains on target queries, and preserves the initial model's performance outside the intended change. These requirements apply after every update. Sequential updates additionally require retaining what was learned from earlier contexts, provided it remains valid.

MC is an outcome-based formulation: C supplies the experience, and context-induced gains provide a behavioral reference rather than a prescribed training signal, leaving learning-input construction and optimization to the method. Knowledge editing, skill learning, behavioral steering, and knowledge suppression are often studied separately, with specialized interfaces such as factual edit requests [22, 56, 57, 103] or forget and retain datasets [46]. MC instead uses context as a common description of the desired change, bringing context-specified forms of these tasks into one learning problem. It is compatible with context distillation and shares continual learning's concern for retention, but does not require the separately supplied task-input distributions or training datasets used in the cited formulations [75, 85]. Where context injection formally defines retention over previously injected contexts [87], MC also requires preservation of the initial model's non-target capabilities after every update. Different update methods can therefore be compared under shared requirements for reuse without C, generalization, and capability preservation.

We introduce the Memory Consolidation Testbed, designed to cover declarative knowledge, procedural knowledge, and behavioral control. It comprises five task families: agent experience consolidation, novel API learning, persona steering, knowledge suppression, and factual editing. These tasks span addition, revision, and suppression with local or global scope, under a common protocol supporting single, batch, and sequential updates. For each evaluated model–task pair, we manually construct contexts that elicit substantial gains. We measure Consolidation Rate (CR), the fraction of the context-induced performance gain recovered after context removal, and Retention Rate (RR), the proportion of original performance retained on queries outside the intended change.

We develop CORTEX as a common consolidation procedure around three connected questions. 1) What should be learned from the context? Drawing on the role of memory in imagining future situations [68], CORTEX anticipates where the context will be useful. It generates prospective queries to specify such situations and context-conditioned responses as learning targets, without accessing held-out evaluation data. 2) Where and in what form should updates be made? CORTEX confines updates to feed-forward networks (FFNs). Using changes in synaptic efficacy [6] and new synaptic connections [91] as design analogies, Synaptic adds low-rank updates to existing projections [35], whereas Structural adds nonlinear feature channels while preserving existing weight blocks. Unlike expert-specific expansions, our shared expansion for pretrained mixture-of-experts (MoE) models gives every token a direct path through the same added parameters, with router parameters fixed. Both variants fold into standard FFN/MoE layers. A finite-state analysis establishes conditions for realizing context-induced corrections with fixed FFN updates (see Appx. A). 3) How can these updates be learned while limiting interference? A context-conditioned teacher supervises a context-free student through output-distribution KL and hidden-state MSE alignment. Sequential updates freeze the pre-update model and train only newly introduced parameters. Query replay retains generated queries and regenerates their targets with the pre-update checkpoint, without storing past contexts.

Our evaluation first characterizes the context gap across the testbed, then measures consolidation and retention. It spans 4B–120B dense and MoE backbones, including instruction-tuned, thinking, and multimodal models, with text inputs throughout. Against applicable task-specific, distillation-based, and hypernetwork baselines, CORTEX lies on the empirical CR–RR Pareto frontier in most evaluated settings. After 50 sequential factual edits on a 14B model, CORTEX-Structural reaches 88.9% CR and 99.8% RR, exceeding AlphaEdit by 66.2 and 3.8 percentage points, respectively. Ablations show improved CR and RR from FFN-only updates relative to also updating attention, reduced forgetting from structural expansion even without replay, and higher CR from shared rather than independent MoE expansion. Hidden-state alignment improves RR with a modest reduction in CR.

Our contributions are: 1) We formalize memory consolidation (MC) with explicit requirements to recover context-induced gains and preserve non-target capabilities, thereby unifying previously isolated changes in knowledge, skills, and behavior under a single persistence objective. 2) We develop CORTEX, a common consolidation framework with mergeable synaptic and structural FFN updates, including shared expansion for pretrained MoEs. 3) We introduce a testbed spanning five task families, with model-specific contexts and paired CR/RR metrics for single, batch, and sequential consolidation. 4) We systematically evaluate CORTEX across diverse models and task settings, and characterize the consolidation–retention trade-off through baseline comparisons and ablations. We will publicly release the Testbed and open-source the CORTEX implementation.

References (100)

Couldn't load all references. Reload the page to try again.