Skip to content


超越面向智能体记忆的 RAG:通过解耦与聚合实现检索

Abstract

Standard Retrieval Augmented Generation (RAG) is poorly matched to agent memory. Unlike large heterogeneous corpora, agent memory forms a bounded and coherent interaction stream in which many spans are highly correlated or near duplicates. As a result, flat top-k similarity retrieval often returns redundant context, while summary-centric hierarchies can blur the subtle details that distinguish one candidate from another. We argue that agent memory should follow the principle of decoupling before aggregation: the system should first isolate reusable facts, updates, and distinguishing details from similar histories, and only then organise them for efficient retrieval.

标准检索增强生成(RAG)与智能体记忆并不匹配。 不同于大型异构语料库,智能体记忆形成一条有界且连贯的交互流,其中许多片段高度相关或近乎重复。 因此,扁平的 top-k 相似度检索经常返回冗余上下文,而以摘要为中心的层级结构可能模糊区分不同候选项的细微细节。 我们认为,智能体记忆应遵循先解耦、后聚合的原则:系统应先从相似历史中分离出可复用事实、更新和具有区分力的细节,然后再组织它们以实现高效检索。

Based on this principle, we propose xMemory, which constructs a revisable hierarchical memory structure from original messages to segments, memory components, and groups. xMemory segments interaction history into local events, decouples each segment into memory components, aggregates related components into high-level groups using a sparsity--semantic faithfulness objective, and maintains this structure incrementally as memory evolves. At inference time, xMemory retrieves top-down, first selecting a compact backbone of complementary groups and components, and then expanding to segments and raw messages only when additional evidence reduces the reader's uncertainty. Experiments on LoCoMo and PerLTQA across diverse open source and closed source LLMs show consistent gains in answer quality and inference token efficiency, supported by analyses of redundancy, evidence density, and coverage.

基于这一原则,我们提出 xMemory,它构建了一种可修订的层级记忆结构,将原始消息依次组织为片段、记忆组件和分组。 xMemory 将交互历史切分为局部事件,把每个片段解耦为记忆组件,利用稀疏性--语义忠实性目标将相关组件聚合为高层分组,并随着记忆演化增量维护这一结构。 在推理时,xMemory 自顶向下检索:先选择由互补分组和组件构成的紧凑骨架,仅当额外证据能够降低读取模型的不确定性时,才继续扩展到片段和原始消息。 在 LoCoMo 和 PerLTQA 上针对多种开源与闭源 LLM 的实验表明,xMemory 持续提升回答质量和推理 token 效率;关于冗余、证据密度和覆盖率的分析进一步支持了这些结果。

1. Introduction

From similarity top-k retrieval to evidence-oriented retrieval for agent memory
图1:从相似度 top-k 检索转向面向证据的智能体记忆检索。智能体记忆是一条连贯且高度相关的交互流,许多片段近乎重复,因此固定的 top-k 相似度检索容易过度选取冗余证据。xMemory 先把相似历史解耦为能够分离差异性证据的记忆组件,再将其组织成检索层级,从而生成更短且更充分的上下文。

Large language model (LLM) agents increasingly rely on external memory to manage extended interaction histories, enabling capabilities such as multi-session dialogue, personalised assistance, and long-term task execution. In these settings, an agent answers new queries by retrieving useful evidence from memory systems rather than relying only on parametric knowledge. Current systems often approach memory retrieval as a standard RAG problem, relying on fixed top-k similarity. However, agent memory poses a different retrieval challenge from standard RAG corpora.

大语言模型(LLM)智能体越来越依赖外部记忆来管理扩展的交互历史,从而支持多会话对话、个性化辅助和长期任务执行等能力。 在这些场景中,智能体通过从记忆系统检索有用证据来回答新查询,而不是只依赖参数化知识。 当前系统经常把记忆检索视为标准 RAG 问题,并依赖固定的 top-k 相似度。 然而,智能体记忆带来的检索挑战不同于标准 RAG 语料库。

Unlike large heterogeneous document collections, agent memory forms a coherent interaction stream with substantial overlap in events and wording. Consequently, the central retrieval difficulty is no longer merely locating generally relevant text, but rather distinguishing decisive evidence hidden among highly similar histories. As a result, similarity top-k retrieval often returns multiple memories that are generally relevant but largely repetitive. This is particularly problematic when the answer hinges on a small update, constraint, or factual difference among otherwise similar interactions.

不同于大型异构文档集合,智能体记忆形成一条连贯的交互流,其中事件和措辞大量重叠。 因此,检索的核心难点不再只是定位大体相关的文本,而是区分隐藏在高度相似历史中的决定性证据 于是,相似度 top-k 检索经常返回多条总体相关但高度重复的记忆。 当答案取决于其他方面相似的交互之间某个微小更新、约束或事实差异时,这一问题尤其严重。

This mismatch also exposes a limitation of existing memory organisation strategies. Recent systems use summaries, note structures, and hierarchical abstractions to improve scalability and navigation. Although these structures reduce the cost of flat retrieval, many still organise memory into a progressively compressed hierarchy, where nodes become fewer and more compressed at higher levels. Such designs can improve efficiency, but they do not directly address the need to identify answer-critical evidence from highly similar histories. Repeated compression often preserves shared background information while blurring the subtle details that distinguish one candidate from another.

这种不匹配也暴露了现有记忆组织策略的一项局限。 近期系统使用摘要、笔记结构和层级抽象来提升可扩展性与导航能力。 尽管这些结构降低了扁平检索的成本,但许多方法仍将记忆组织成逐步压缩的层级,其中越高层的节点越少、压缩程度越高。 这类设计能够提高效率,却没有直接解决从高度相似历史中识别答案关键证据的需求。 反复压缩往往保留共有背景信息,却会模糊区分候选项的细微细节。

Taken together, these considerations suggest a core design principle: decoupling before aggregation. As shown in Figure 1, rather than treating long, highly similar interaction logs as whole retrieval units, the memory system should first decompose them into smaller evidence units that isolate reusable facts, state updates, and distinguishing details. Aggregation then organises these units into a higher-level memory structure that remains compact and coherent. Crucially, this structure should be revisable rather than fixed: as agent memory evolves, new interactions can reveal better relations among previously stored components and trigger corresponding updates to the high-level organisation.

综合来看,这些考虑指向一项核心设计原则:先解耦、后聚合 图1所示,记忆系统不应把冗长且高度相似的交互日志作为完整检索单元,而应先将其分解为更小的证据单元,以分离可复用事实、状态更新和具有区分力的细节。 随后,聚合过程将这些单元组织为保持紧凑与连贯的高层记忆结构。 关键在于,这一结构应当可修订而非固定不变:随着智能体记忆演化,新交互可能揭示先前存储组件之间更合适的关系,并触发高层组织的相应更新。

Based on this principle, we propose xMemory, a framework that couples memory structuring with adaptive retrieval. Starting from raw messages, xMemory builds a hierarchical memory structure by following the principle of decoupling before aggregation: it extracts segments from raw messages as local events, decouples similar histories into memory components that isolate reusable facts and distinctive attributes, and then aggregates related components into groups for high-level access. To organise these components into useful groups, xMemory evaluates the component-to-group organisation with a guidance objective that balances sparsity and semantic faithfulness. This objective guides structure updates as memory evolves.

基于这一原则,我们提出 xMemory,一个将记忆结构化自适应检索耦合起来的框架。 xMemory 从原始消息出发,遵循先解耦、后聚合的原则构建层级记忆结构:它从原始消息中抽取作为局部事件的片段,把相似历史解耦为能够分离可复用事实和差异性属性的记忆组件,再将相关组件聚合为便于高层访问的分组 为了把这些组件组织成有用分组,xMemory 使用一个在稀疏性与语义忠实性之间取得平衡的引导目标来评估组件到分组的组织方式。 随着记忆演化,该目标会引导结构更新。

When new memory arrives, components are attached to compatible groups when possible, and the structure is revised as needed by splitting overly large or internally heterogeneous groups and merging overly small or isolated ones. Retrieval finally proceeds from coarse units to fine ones: the system first selects complementary groups and components, and expands to segments and original messages only when more detailed evidence is needed.

当新记忆到来时,系统会尽可能将组件连接到兼容分组,并在需要时拆分过大或内部异质的分组、合并过小或孤立的分组,从而修订结构。 最终,检索由粗粒度单元向细粒度单元推进:系统先选择互补分组和组件,仅在需要更详细证据时才扩展到片段和原始消息。

Our contributions are summarised as follows:

我们的贡献总结如下:

  1. We identify a key mismatch between standard RAG and agent memory, and argue that agent memory should follow the principle of decoupling before aggregation.
  2. We propose xMemory, which constructs a revisable hierarchical memory structure by segmenting local interaction history, decoupling segments into memory components, and aggregating related components into high-level groups.
  3. We develop a top-down adaptive retrieval method over this memory structure, and show on LoCoMo and PerLTQA that it improves both answer quality and inference token efficiency.
  1. 我们识别出标准 RAG 与智能体记忆之间的一项关键不匹配,并主张智能体记忆应遵循先解耦、后聚合的原则。
  2. 我们提出 xMemory,它通过切分局部交互历史、将片段解耦为记忆组件,并把相关组件聚合为高层分组,构建一种可修订的层级记忆结构。
  3. 我们在这一记忆结构上开发了自顶向下的自适应检索方法,并在 LoCoMo 和 PerLTQA 上表明,该方法同时提高了回答质量和推理 token 效率。

RAG-style retrieval for agent memory. Many memory systems follow the standard RAG paradigm, storing past interactions as retrievable units and selecting a top-k set by embedding similarity. This works well for heterogeneous corpora, but agent memory is often a coherent interaction stream with many semantically similar spans. As a result, similarity retrieval can return redundant memories while missing small updates or temporal distinctions that determine the answer. xMemory addresses the mismatch by retrieving decoupled evidence units rather than raw spans.

面向智能体记忆的 RAG 式检索。 许多记忆系统遵循标准 RAG 范式,将过去的交互存储为可检索单元,并依据嵌入相似度选择 top-k 集合。 这种方法适用于异构语料库,但智能体记忆通常是一条连贯的交互流,其中包含许多语义相似的片段。 因此,相似度检索可能返回冗余记忆,却遗漏决定答案的微小更新或时间差异。 xMemory 通过检索解耦后的证据单元而非原始片段来解决这种不匹配。

Hierarchical and graph-based memory organisation. Recent systems organise memory into summaries, notes, temporal layers, semantic memories, or graph communities to improve scalability. While these structures reduce the cost of flat retrieval, many remain summary- or schema-centric: higher-level nodes abstract over lower-level content instead of preserving fine-grained distinctions. xMemory instead follows decoupling before aggregation: it first extracts reusable memory components from local segments, and then groups related components for efficient access.

层级与基于图的记忆组织。 近期系统将记忆组织为摘要、笔记、时间层、语义记忆或图社区,以提高可扩展性。 尽管这些结构降低了扁平检索的成本,但许多方法仍以摘要或模式为中心:高层节点对低层内容进行抽象,而不是保留细粒度差异。 xMemory 则遵循先解耦、后聚合:它先从局部片段中抽取可复用记忆组件,再对相关组件进行分组以实现高效访问。

Adaptive retrieval over dynamic memory structures. RAG-style memory systems usually treat past interactions as a static retrieval corpus, accessed by top-k search, neighbour expansion, or multi-stage filtering. Some hierarchical systems support incremental updates by inserting new memories into existing clusters or nodes, but this remains distinct from retroactive reorganisation. This distinction matters for agent memory, where later interactions can change how earlier evidence should be grouped. xMemory therefore maintains a revisable hierarchy that uses split and merge operations to reorganise previously stored components before adaptive retrieval.

动态记忆结构上的自适应检索。 RAG 式记忆系统通常把过去交互视为静态检索语料库,并通过 top-k 搜索、邻居扩展或多阶段过滤进行访问。 一些层级系统支持将新记忆插入现有簇或节点来进行增量更新,但这仍不同于追溯式重组。 这种区别对智能体记忆非常重要,因为后续交互可能改变早期证据应当如何分组。 因此,xMemory 维护一种可修订层级,在自适应检索之前利用拆分与合并操作重新组织先前存储的组件。

3. Method

Overview of xMemory
图2:xMemory 概览。xMemory 遵循先解耦、后聚合的原则:先把原始交互历史组织为局部片段,再将每个片段分解为能够分离决定性证据的可复用记忆组件,最后把相关组件聚合为便于高效检索的高层分组。检索时,系统先选择相关分组和组件构成的紧凑骨架,仅当额外文本证据能够降低读取模型的不确定性时,才扩展到片段和原始消息。

Given an interaction history H={m1,,mT} and a query q, the goal is to construct a context C for answering q. As shown in Figure 2, xMemory first organises the interaction history into a hierarchical memory structure. The structure is built in three stages: raw messages are divided into local segments; each segment is then decoupled into memory components that isolate reusable facts, constraints, and updates; and related components are finally aggregated into higher-level groups for efficient access. Retrieval proceeds top-down over this structure, starting from relevant groups and components, and expanding to segments and original messages only when finer-grained textual evidence is needed.

给定交互历史 H={m1,,mT} 和查询 q,目标是为回答 q 构建上下文 C 图2所示,xMemory 首先将交互历史组织为层级记忆结构。 该结构分三个阶段构建:先将原始消息划分为局部片段;再把每个片段解耦为能够分离可复用事实、约束和更新的记忆组件;最后将相关组件聚合为便于高效访问的高层分组。 检索在这一结构上自顶向下进行,从相关分组和组件出发,仅在需要更细粒度文本证据时才扩展到片段和原始消息。

3.1 Building a Revisable Memory Structure

We next describe how xMemory constructs the hierarchy and updates it as new memory arrives.

下面介绍 xMemory 如何构建这一层级,以及如何在新记忆到来时更新它。

From messages to components. We first partition the message stream into contiguous segments, each capturing a coherent local event, because answer-critical evidence in agent memory is often expressed across neighbouring turns rather than in isolated messages. Segments preserve this intact local context, but they are still too coarse to retrieve directly. We therefore extract one or more memory components from each segment, where each component represents a reusable fact, constraint, attribute, relation, or state update. This is the decoupling step of xMemory: it separates the decisive evidence from the surrounding local context before retrieval, while retaining links back to the source segment so that intact context can still be recovered when needed.

从消息到组件。 我们首先把消息流划分为连续的片段,每个片段捕获一个连贯的局部事件,因为智能体记忆中的答案关键证据往往跨相邻轮次表达,而不是存在于孤立消息中。 片段保留了这一完整局部上下文,但其粒度仍然过粗,不适合直接检索。 因此,我们从每个片段中抽取一个或多个记忆组件,每个组件表示一项可复用事实、约束、属性、关系或状态更新。 这就是 xMemory 的解耦步骤:它在检索前把决定性证据与周围局部上下文分离,同时保留指回源片段的链接,以便在需要时恢复完整上下文。

From components to groups. Once evidence has been decoupled into memory components, xMemory organises these components into higher-level groups, which serve as compact access units for retrieval. This is the aggregation step: rather than building the hierarchy directly over raw spans or summaries, we aggregate over already identified evidence units. The role of grouping is to make high-level retrieval both efficient and discriminative. If groups are too broad, retrieval becomes less discriminative and more redundant; if they are too fragmented, related evidence is scattered across many small units, weakening coverage for multi-fact queries. We therefore organise components into groups using an objective that balances sparsity and semantic faithfulness.

从组件到分组。 证据被解耦为记忆组件后,xMemory 会将这些组件组织为高层分组,作为检索时的紧凑访问单元。 这就是聚合步骤:我们不是直接在原始片段或摘要上构建层级,而是在已经识别出的证据单元上进行聚合。 分组的作用是使高层检索兼具效率和区分力。 如果分组过宽,检索的区分力会下降且冗余增加;如果分组过碎,相关证据会分散在许多小单元中,削弱多事实查询的覆盖能力。 因此,我们使用一个在稀疏性语义忠实性之间取得平衡的目标将组件组织成分组。

Let P={Ck}k=1K denote a partition of N memory components into K groups, where nk=|Ck|. We score an organisation by the following objective.

P={Ck}k=1K 表示将 N 个记忆组件划分为 K 个分组的一个划分,其中 nk=|Ck| 我们使用以下目标对一种组织方式进行评分。

(1)f(P)=SparsityScore(P)+SemScore(P).

The sparsity term favours balanced groups by using the normalised inverse of the expected within-group scanning cost.

稀疏性项使用预期组内扫描成本的归一化倒数,偏好规模均衡的分组。

(2)SparsityScore(P)=N2Kk=1Knk2.

The semantic term encourages intra-group coherence and keeps the inter-group geometry navigable by Stage I's kNN-based retrieval.

语义项鼓励组内一致性,并保持组间几何结构能够被第一阶段基于 kNN 的检索有效导航。

(3)SemScore(P)=1Kk=1K×(1nkiCkcos(xi,μk))g(sk),g(sk)=exp((sks¯)22σ2),sk=maxjkcos(μk,μj),s¯=median({sk}),σ=median({|sks¯|})+ε.

Here xi is the embedding of component i, and μk is the centroid of group k. The bell-shaped g(sk) acts on inter-group geometry: near-duplicate centroids (sk above the median) reintroduce the redundancy that decoupling removes, while isolated ones (sk below the median) drop out of Stage I's kNN expansion as “semantic islands”. Distinctiveness of individual components is already preserved upstream by decoupling; g(sk) only shapes group-centroid geometry.

这里,xi 是组件 i 的嵌入,μk 是分组 k 的质心。 钟形函数 g(sk) 作用于组间几何结构:近乎重复的质心(sk 高于中位数)会重新引入解耦所消除的冗余,而孤立质心(sk 低于中位数)则会在第一阶段的 kNN 扩展中作为“语义孤岛”掉出检索范围。 单个组件的差异性已经由上游解耦步骤保留;g(sk) 只负责塑造分组质心的几何结构。

Dynamic maintenance. Because agent memory evolves over time, the memory structure is maintained incrementally rather than fixed after construction. A new component with embedding x is attached to its nearest group k=argmax1kKcos(x,μk) if the similarity exceeds a threshold; otherwise a new group is created. Groups that become too large or internally incoherent are considered for splitting, while small or isolated groups are considered for merging. In both cases, the selected operation is the one that most improves Eq. (1).

动态维护。 由于智能体记忆会随时间演化,记忆结构采用增量方式维护,而不是构建后保持固定。 对于嵌入为 x 的新组件,如果它与最近分组 k=argmax1kKcos(x,μk) 的相似度超过阈值,就将其连接到该分组;否则创建新分组。 过大或内部不一致的分组会被考虑拆分,而过小或孤立的分组会被考虑合并。 在两种情况下,系统都选择能够最大程度改善式(1)的操作。

We additionally maintain top-k nearest-neighbour links among groups to support local retrieval. Further details and a qualitative example are provided in the appendices.

我们还在分组之间维护 top-k 最近邻链接,以支持局部检索。 更多细节和一个定性示例见附录。

3.2 Retrieval from the Memory Structure

The memory structure separates two roles that raw interaction history entangles: groups and memory components expose high-level evidence, while segments and original messages preserve the intact local context in which that evidence was expressed. Retrieval therefore proceeds in two stages. We first identify a compact high-level backbone of relevant evidence, and only then expand to lower-level text when more context is necessary for answer generation.

记忆结构分离了原始交互历史中相互纠缠的两种作用:分组和记忆组件提供高层证据,而片段和原始消息保留这些证据被表达时的完整局部上下文。 因此,检索分两个阶段进行。 我们首先识别相关证据构成的紧凑高层骨架,仅在回答生成需要更多上下文时才扩展到低层文本。

Stage I: high-level backbone selection. Answers in agent memory are often supported by multiple related evidence units rather than a single best match. Stage I therefore selects a compact set of complementary high-level units, rather than repeatedly retrieving near-duplicate evidence by pure similarity ranking. To support this, we maintain kNN links among groups in the memory structure. These links record which high-level units are semantically close, even when they belong to different groups, allowing Stage I to avoid repeatedly selecting near-duplicate evidence and to identify related evidence regions that remain uncovered.

第一阶段:高层骨架选择。 智能体记忆中的答案通常由多个相关证据单元共同支持,而不是只依赖单个最佳匹配。 因此,第一阶段选择一组紧凑且互补的高层单元,而不是依据纯相似度排序反复检索近乎重复的证据。 为此,我们在记忆结构的分组之间维护 kNN 链接。 即使高层单元属于不同分组,这些链接也会记录它们在语义上的接近关系,使第一阶段能够避免重复选择近乎重复的证据,并识别仍未覆盖的相关证据区域。

We first retrieve a small pool of groups by similarity between query and centroid, and include their neighbouring groups and associated components as candidate set V. Let RV denote the selected evidence backbone. For each candidate node iV, let N(i) denote its neighbours under the kNN links, and let wiu>0 denote the similarity weight on edge (i,u). We define the covered set as C(R), and the newly covered nodes contributed by candidate i as Δ(i;R).

我们首先依据查询与质心之间的相似度检索一个小型分组池,并将其邻近分组和相关组件纳入候选集 V RV 表示选出的证据骨架。 对于每个候选节点 iV,令 N(i) 表示其在 kNN 链接下的邻居,令 wiu>0 表示边 (i,u) 上的相似度权重。 我们将覆盖集合记为 C(R),将候选节点 i 新增覆盖的节点记为 Δ(i;R)

(4)C(R)={uVrR,u{r}N(r)},Δ(i;R)=({i}N(i))C(R).

At each step, we greedily select the next unit by trading off structural coverage against query relevance.

在每一步中,我们通过权衡结构覆盖率与查询相关性,贪心选择下一个单元。

(5)i=argmaxiVR[uΔ(i;R)wiuZ+s~(q,i)].

Here s~(q,i)[0,1] is the normalised query--node similarity, and Z denotes the total candidate coverage weight. We apply Eq. (5) hierarchically, first selecting groups and then refining to components.

这里,s~(q,i)[0,1] 是归一化的查询--节点相似度,Z 表示候选集的总覆盖权重。 我们以层级方式应用式(5),先选择分组,再细化到组件。

Stage II: adaptive text expansion. The high-level backbone indicates where useful evidence resides, but it does not yet determine how much original text should be revealed to the reader. Expanding all linked segments and messages would often reintroduce the same redundancy that the high-level structure is designed to avoid. Stage II therefore adds lower-level text only when it further reduces the reader's uncertainty.

第二阶段:自适应文本扩展。 高层骨架指出了有用证据所在的位置,但尚未决定应向读取模型展示多少原始文本。 扩展所有已链接的片段和消息,往往会重新引入高层结构旨在避免的同类冗余。 因此,第二阶段仅在低层文本能够进一步降低读取模型不确定性时才加入它。

Starting from the selected components, we gather their linked segments and construct a coarse context. Let U(C,q) denote the reader's uncertainty under context C and query q, instantiated in our implementation via predictive entropy; concrete definitions and implementation details are given in the appendix. For a candidate segment s, its marginal uncertainty reduction is defined as follows.

我们从选中的组件出发,收集其链接片段并构建粗粒度上下文。 U(C,q) 表示读取模型在上下文 C 和查询 q 下的不确定性;在我们的实现中,它通过预测熵实例化,具体定义和实现细节见附录。 对于候选片段 s,其边际不确定性降低量定义如下。

(6)ΔU(sC,q)=U(C,q)U(C{s},q).

A segment is included only if it yields a positive marginal reduction, i.e., ΔU(sC,q)>0. For a candidate message m, we analogously compute ΔU(mC,q)=U(C,q)U(C{m},q) and include it only when it further reduces uncertainty. Retrieval stops when no remaining candidate segment or message provides additional uncertainty reduction.

仅当片段带来正的边际降低量,即 ΔU(sC,q)>0 时,系统才将其纳入上下文。 对于候选消息 m,我们以同样方式计算 ΔU(mC,q)=U(C,q)U(C{m},q),并且只在它能够进一步降低不确定性时将其纳入。 当剩余候选片段或消息都无法带来额外的不确定性降低时,检索停止。

4. Experiments

4.1 Experimental Setup

Datasets and metrics. We evaluate long-term agent memory on two complementary benchmarks: LoCoMo and PerLTQA. LoCoMo contains 50 multi-session dialogues, with an average of 18K tokens and 300 turns. Following prior work, we report results on its four answerable categories and omit the adversarial subset, which does not provide gold answers for the metrics used here. PerLTQA evaluates personalised long-term memory over longer contexts (around 25K tokens on average), with answers that are often sentence-style rather than short spans. We report BLEU-1 and token-level F1 on both datasets, and additionally ROUGE-L on PerLTQA to better capture sequence-level overlap for longer-form answers.

数据集与指标。 我们在两个互补基准 LoCoMo 和 PerLTQA 上评估长期智能体记忆。 LoCoMo 包含 50 个多会话对话,平均约有 18K 个 token 和 300 轮交互。 遵循先前工作,我们报告其中四个可回答类别的结果,并省略对抗子集,因为该子集没有为本文所用指标提供标准答案。 PerLTQA 在更长上下文(平均约 25K 个 token)上评估个性化长期记忆,其答案通常是句子形式而非短文本片段。 我们在两个数据集上均报告 BLEU-1 和 token 级 F1,并在 PerLTQA 上额外报告 ROUGE-L,以更好地捕获较长答案的序列级重叠。

Baselines. We compare against six baselines, grouped by how they access and organise memory. These baselines cover full-context reading, flat similarity retrieval, post-retrieval compression, and representative structured-memory designs. Flat or minimally structured baselines include (1) Full Memory, which provides the complete available history to the reader model without retrieval; (2) Naive RAG, which chunks original messages and retrieves the top-20 chunks by vector similarity; and (3) LightMem, which reduces retrieval cost through multi-stage filtering and compression. Structured memory baselines include (4) Nemori, which builds a hierarchical memory from episodic memories to higher-level semantic memories for long-term recall; (5) A-Mem, which stores memory as structured notes connected by dynamic links; and (6) MemoryOS, which organises memory into temporally layered storage with lifecycle management.

基线。 我们与六种基线比较,并按照它们访问和组织记忆的方式进行分组。 这些基线涵盖完整上下文读取、扁平相似度检索、检索后压缩以及具有代表性的结构化记忆设计。 扁平或最低限度结构化的基线包括:(1) Full Memory,不经过检索而向读取模型提供全部可用历史;(2) Naive RAG,切分原始消息并依据向量相似度检索 top-20 个片段;以及 (3) LightMem,通过多阶段过滤与压缩降低检索成本。 结构化记忆基线包括:(4) Nemori,为长期回忆构建从情景记忆到高层语义记忆的层级结构;(5) A-Mem,将记忆存储为通过动态链接连接的结构化笔记;以及 (6) MemoryOS,通过生命周期管理将记忆组织为时间分层存储。

Implementation details. We evaluate all compared methods with three reader LLMs: two recent open-source models, Qwen3-8B and Llama-3.1-8B-Instruct, and one closed-source model, GPT-5 nano. Final answers are generated with greedy decoding (temperature =0.0) for deterministic evaluation. All retrieval and memory construction embeddings use text-embedding-3-small, and each method uses the same backbone model for memory construction and answer generation. Since LoCoMo and PerLTQA require different answer formats, we use dataset-specific answer prompts within each dataset. For GPT-5 nano, which does not expose token-level logits, we estimate uncertainty with GPT-4.1-mini. All xMemory hyperparameters are fixed across datasets and backbone models; their values and implementation details are reported in the appendix for reproducibility.

实现细节。 我们使用三个读取 LLM 评估所有比较方法:两个近期的开源模型 Qwen3-8B 和 Llama-3.1-8B-Instruct,以及一个闭源模型 GPT-5 nano。 最终答案使用贪心解码(温度 =0.0)生成,以进行确定性评估。 所有检索和记忆构建嵌入均使用 text-embedding-3-small,每种方法在记忆构建和答案生成中使用相同的骨干模型。 由于 LoCoMo 和 PerLTQA 要求不同的答案格式,我们在每个数据集内使用数据集专用的回答提示。 对于不提供 token 级 logits 的 GPT-5 nano,我们使用 GPT-4.1-mini 估计不确定性。 xMemory 的所有超参数在不同数据集和骨干模型间保持固定;其数值和实现细节在附录中给出,以便复现。

4.2 Main Results

表1:LoCoMo 上的主结果。上标 F 表示扁平检索基线,上标 S 表示结构化记忆基线。表中报告各问题类别及平均 BLEU 和 F1;Token/query 表示推理期间每个查询的平均总 token 数,越低越好。同一骨干模型内的最佳结果以粗体表示。
ModelMethodMulti-hopTemporalOpen-domainSingle-hopAverageToken
/query
BLEUF1BLEUF1BLEUF1BLEUF1BLEUF1
Qwen3-8BFull MemoryF24.6331.6610.0212.5812.4817.5933.8044.0025.8333.5418535.90
Naive RAGF22.4634.2817.2121.3212.3517.0835.6845.2227.9536.488633.28
LightMemF19.6326.2322.6727.619.8314.3731.3440.6626.0433.665545.35
NemoriS24.6836.8225.7833.7612.7118.4838.0247.5231.4440.887754.66
A-MemS23.3233.2622.2932.539.0816.7233.6142.5227.8437.139103.46
MemoryOSS17.1221.7426.8432.2614.5316.2535.8340.3729.2033.767234.66
xMemory (Ours)27.2438.5729.5837.4615.5520.6940.9450.9434.4843.984711.29
Llama-3.1-8B-InsFull MemoryF15.1121.526.068.067.7811.1323.2935.1317.2325.5018524.70
Naive RAGF13.7719.406.208.616.9910.2221.9035.3716.2125.3011522.60
LightMemF16.4323.7612.4415.619.8313.7021.6825.0818.0522.155708.11
NemoriS18.1826.3019.2326.099.2412.0626.1940.1822.2132.959802.69
A-MemS15.8820.9019.9224.919.9211.3424.8639.9021.5231.5110268.77
MemoryOSS13.2617.8319.8823.9511.4812.9224.7628.6720.8124.727212.07
xMemory (Ours)22.2130.9921.2027.4211.5814.6128.4341.1524.7334.775539.97
GPT-5 nanoFull MemoryF22.9534.0720.0223.5021.6126.4232.7146.9727.5838.4418544.25
Naive RAGF21.3432.3128.4329.0522.6326.5636.6846.3531.2838.947531.46
LightMemF23.1332.0741.0655.2321.2726.3837.5244.3134.6043.236850.04
NemoriS24.8037.1141.5654.2522.6129.2940.3551.6736.6548.179154.76
A-MemS24.1235.8840.8754.6720.8327.6138.4246.1335.2244.889610.94
MemoryOSS24.4736.1339.7855.3421.4528.7139.3948.6835.6246.537029.02
xMemory (Ours)27.5639.9746.1057.6225.5330.9241.1452.6338.7150.006581.20

LoCoMo: retrieval over coherent multi-session histories. Table 1 reports results on LoCoMo. Across all three backbones, xMemory achieves the best average performance, with especially clear gains on multi-hop and temporal questions. For example, with Qwen3-8B, average BLEU/F1 improves from 31.44/40.88 for Nemori to 34.48/43.98; with GPT-5 nano, it improves from 36.65/48.17 to 38.71/50.00 while reducing token usage from 9155 to 6581 per query.

LoCoMo:在连贯多会话历史上检索。 表1报告了 LoCoMo 上的结果。 在三个骨干模型上,xMemory 都取得了最佳平均性能,并且在多跳与时间问题上的提升尤其明显。 例如,使用 Qwen3-8B 时,平均 BLEU/F1 从 Nemori 的 31.44/40.88 提升到 34.48/43.98;使用 GPT-5 nano 时,它从 36.65/48.17 提升到 38.71/50.00,同时把每个查询的 token 用量从 9155 降至 6581

Compared with both flat retrieval and structured memory baselines, these results suggest that agent memory benefits from decoupling decisive evidence before high-level organisation and retrieval. Full Memory and Naive RAG preserve large amounts of raw context but often return redundant or weakly discriminative evidence, while LightMem reduces cost mainly through post-retrieval compression and performs worse on multi-hop and temporal questions. Structured baselines introduce higher-level organisation, but their memory structures are not explicitly centred on decoupled evidence units and revisable grouping. By contrast, xMemory first decouples distinctive evidence into memory components, organises them into revisable groups, and retrieves top-down over this structure.

与扁平检索和结构化记忆基线相比,这些结果表明,在进行高层组织和检索之前先解耦决定性证据有利于智能体记忆。 Full Memory 和 Naive RAG 保留大量原始上下文,但经常返回冗余或区分力较弱的证据;LightMem 则主要通过检索后压缩降低成本,在多跳和时间问题上表现更差。 结构化基线引入了高层组织,但其记忆结构没有明确以解耦后的证据单元和可修订分组为中心。 相比之下,xMemory 先把差异性证据解耦为记忆组件,将其组织成可修订分组,再在该结构上自顶向下检索。

表2:PerLTQA 上的主结果。上标 F 表示扁平检索基线,上标 S 表示结构化记忆基线。表中报告 BLEU、F1、R-L(ROUGE-L)和 Tok.(推理期间每个查询的 token 用量,越低越好)。同一骨干模型内的最佳结果以粗体表示。
MethodQwen3-8BLlama-3.1-8B-InsGPT-5 nano
BLEUF1R-LTok.BLEUF1R-LTok.BLEUF1R-LTok.
Full MemoryF32.7342.1536.652504533.0044.4039.432509824.3734.9729.8125212
Naive RAGF32.0841.3735.95627433.6744.8439.65953127.3537.7632.3510756
LightMemF29.1240.2134.67769231.8342.3338.37545224.8434.5129.337579
NemoriS32.5542.8038.05909241.0149.6244.651144033.4441.7938.4311883
A-MemS31.3640.9236.45986435.5645.7941.38770733.1241.1737.9414718
MemoryOSS35.1442.3538.48649934.7942.0338.22651127.6633.8331.4412669
xMemory (Ours)36.2447.0842.50508742.6852.3747.84606636.7946.2341.257307

PerLTQA: generalisation to longer personalised memory. Table 2 reports results on PerLTQA, which contains longer contexts and more sentence-style answers than LoCoMo. xMemory remains consistently effective across all three backbone models, showing that the proposed retrieval principle transfers beyond multi-session dialogue recall to longer personalised memory reasoning. With Qwen3-8B, it achieves the best BLEU/F1/ROUGE-L at 36.24/47.08/42.50 while using the fewest tokens; with Llama-3.1-8B-Instruct, it reaches 42.68/52.37/47.84. These gains suggest that xMemory improves selective evidence access while preserving the information needed for coherent sentence-level reconstruction.

PerLTQA:向更长个性化记忆泛化。 表2报告了 PerLTQA 上的结果,该数据集比 LoCoMo 包含更长的上下文和更多句子形式的答案。 xMemory 在三个骨干模型上始终有效,表明所提出的检索原则能够从多会话对话回忆迁移到更长的个性化记忆推理。 使用 Qwen3-8B 时,它以最少的 token 用量取得最佳 BLEU/F1/ROUGE-L:36.24/47.08/42.50;使用 Llama-3.1-8B-Instruct 时,则达到 42.68/52.37/47.84 这些提升表明,xMemory 在保留连贯句子级重构所需信息的同时,改善了选择性证据访问。

Efficiency. We report tokens per query as the average end-to-end inference cost, including retrieval, answer generation, and auxiliary calls. Across both datasets, xMemory achieves better answer quality with competitive or fewer tokens than strong memory baselines, indicating that its gains come from delivering more concentrated evidence rather than exposing more history. For example, on LoCoMo with Qwen3-8B, xMemory reduces token usage from 7755 for Nemori to 4711 while also improving average BLEU/F1 from 31.44/40.88 to 34.48/43.98. These results suggest that token efficiency in agent memory should be measured by evidence utility rather than context reduction alone.

效率。 我们使用每个查询的 token 数表示平均端到端推理成本,其中包括检索、答案生成和辅助调用。 在两个数据集上,与强记忆基线相比,xMemory 都以有竞争力或更少的 token 取得更好的回答质量,说明其提升来自提供更集中的证据,而不是暴露更多历史。 例如,在使用 Qwen3-8B 的 LoCoMo 上,xMemory 将 Nemori 的 token 用量从 7755 降至 4711,同时把平均 BLEU/F1 从 31.44/40.88 提升到 34.48/43.98 这些结果表明,智能体记忆中的 token 效率应根据证据效用来衡量,而不能只看上下文缩减量。

5. Analysis

5.1 Ablation Studies

Retrieval stage analysis. We first ablate memory structuring and the two retrieval stages on LoCoMo with Qwen3-8B. As shown in Figure 3 (a), Memory-only improves average BLEU/F1 from 27.95/36.48 for Naive RAG to 31.81/40.77, showing that retrieval over decoupled memory units is more effective than retrieval over flat raw chunks, even with basic similarity matching. Adding Stage I improves selection over groups and components, while Stage II improves uncertainty guided expansion to segments and messages. Combining both stages gives the best trade-off, with the highest average BLEU/F1 and the lowest token usage.

检索阶段分析。 我们首先在采用 Qwen3-8B 的 LoCoMo 上,对记忆结构化和两个检索阶段进行消融。 图3 (a) 所示,Memory-only 将 Naive RAG 的平均 BLEU/F1 从 27.95/36.48 提升到 31.81/40.77,表明即使只使用基本的相似度匹配,在解耦记忆单元上检索也比在扁平原始块上检索更有效。 加入阶段 I 改善了分组与组件层面的选择,而阶段 II 改善了以不确定性为引导、向片段和消息扩展的过程。 结合两个阶段取得最佳权衡,同时获得最高的平均 BLEU/F1 和最低的 token 用量。

Group size upper bound analysis. We next study the upper bound on the number of memory components per group. This parameter controls routing arity: a larger candidate set within each group makes decisive evidence harder to identify in dialogue memory with high semantic similarity, while an overly small group size scatters related facts. Guided by a Fano style lower bound, which shows that routing error increases with candidate size when discriminative information is bounded, we choose 12 as a practical threshold and then validate it empirically. Figure 3 (b) shows that this setting performs best, reaching 34.48 BLEU and 43.98 F1 with 4.48 components per group on average. Larger groups weaken discrimination, while smaller groups fragment the hierarchy. Full results and the detailed theoretical motivation are provided in the appendix.

分组大小上界分析。 接下来,我们研究每个分组所含记忆组件数量的上界。 该参数控制路由分支数:在语义高度相似的对话记忆中,每个分组内更大的候选集会使决定性证据更难识别,而过小的分组则会分散相关事实。 Fano 风格的下界表明,当判别信息受限时,路由误差会随候选集大小增加;在这一结果的指导下,我们选择 12 作为实用阈值,并通过实验加以验证。 图3 (b) 表明该设置表现最佳,达到 34.48 BLEU 和 43.98 F1,且每组平均包含 4.48 个组件。 更大的分组会削弱判别能力,而更小的分组会使层级结构碎片化。 完整结果和详细理论动机见附录。

Ablation studies on LoCoMo with Qwen3-8B
图3:在使用 Qwen3-8B 的 LoCoMo 上进行的消融实验。(a) 检索阶段消融,总结记忆结构化、阶段 I 和阶段 II 对平均 BLEU/F1 与 token 用量的影响。(b) 每组记忆组件数量上界(UB)的影响,同时展示平均 BLEU/F1 和最终每组组件的平均数量。

5.2 Retroactive Restructuring in Memory Construction

Unlike standard RAG, where the retrieval corpus is usually fixed, agent memory evolves as new interactions arrive. In xMemory, later insertions can trigger split or merge operations over high-level groups, thereby revising the assignment of previously created memory components. We measure this effect with the dynamic reassignment ratio, defined as the fraction of existing components whose group assignment changes during later insertions.

标准 RAG 的检索语料库通常是固定的,而智能体记忆会随着新交互到来而演化。 在 xMemory 中,后续插入可以触发高层分组的拆分合并操作,从而修订先前创建的记忆组件的归属。 我们使用动态重分配比例衡量这一效应,它被定义为在后续插入期间分组归属发生变化的现有组件所占比例。

Retroactive restructuring in xMemory
图4:追溯式重构。冻结高层重构会产生 0% 的重分配比例和更低的问答性能,而完整系统会执行大量重分配,并取得最佳平均 BLEU/F1。

Figure 4 shows that such retroactive restructuring improves downstream QA. Disabling both split and merge freezes the structure, yields 0% reassignment, and reduces average F1 to 38.59, whereas the full system reaches the highest reassignment ratio (44.91%) and the best average F1 (43.98). The structure statistics in the appendix further show that split and merge play complementary roles: split enables revision by repartitioning broad groups, while merge prevents the high-level index from becoming unnecessarily fragmented. These results support our claim that revisability is not merely an implementation detail, but a useful property for memory organisation under evolving evidence.

图4表明,这种追溯式重构能够改善下游问答。 同时禁用拆分合并会冻结结构,使重分配比例降至 0%,并将平均 F1 降至 38.59;完整系统则达到最高的重分配比例(44.91%)和最佳平均 F1(43.98)。 附录中的结构统计进一步表明,拆分合并发挥互补作用:拆分通过重新划分宽泛分组实现修订,而合并则防止高层索引产生不必要的碎片。 这些结果支持我们的主张:可修订性不只是实现细节,而是面对不断演化的证据时,记忆组织所需的一项有用属性。

5.3 Retrieval Efficiency and Cost Performance Trade-off

Evidence hit distribution by question category
图5:按问题类别划分的证据命中分布。每个子图展示检索块中 1-hit、2-hit 和 multi-hit 的比例,并比较 Naive RAG、带剪枝的 RAG 与 xMemory。更高的 2-hit 和 multi-hit 比例表示检索到的证据更密集。

Evidence density and coverage efficiency. To understand why xMemory improves answer quality while reducing inference-time context cost, we compare three retrieval settings on LoCoMo with Qwen3-8B: (1) Naive RAG with top-20 chunks; (2) RAG with the LLMLingua-2 pruning module as in LightMem; and (3) xMemory. For each query, we remove stopwords from the reference answer and treat the remaining content words as answer evidence units. A retrieved block is counted as 1-hit, 2-hit, or multi-hit if it contains one, two, or at least three distinct answer evidence units, respectively. Figure 5 shows that xMemory retrieves denser evidence across all question categories, with consistently higher 2-hit and multi-hit proportions than both RAG baselines. This suggests that decoupling memory into finer-grained components helps concentrate answer-relevant evidence before retrieval, rather than leaving it dispersed across redundant raw chunks. By contrast, pruning shifts mass from 2-hit and multi-hit blocks toward 1-hit blocks, suggesting that post-retrieval compression can fragment entangled evidence even when the remaining context is broadly relevant. For example, on multi-hop questions, xMemory increases the 2-hit and multi-hit proportions to 13.14% and 12.19%, compared with 7.82% and 6.53% for Naive RAG.

证据密度与覆盖效率。 为了理解 xMemory 为何能够在降低推理时上下文成本的同时提高回答质量,我们在采用 Qwen3-8B 的 LoCoMo 上比较三种检索设置:(1) 使用 top-20 块的 Naive RAG;(2) 像 LightMem 一样使用 LLMLingua-2 剪枝模块的 RAG;(3) xMemory。 对于每个查询,我们从参考答案中移除停用词,并将剩余实词视为答案证据单元。 如果一个检索块分别包含一个、两个或至少三个不同的答案证据单元,则将其计为 1-hit2-hitmulti-hit 图5表明,xMemory 在所有问题类别中都检索到更密集的证据,其 2-hit 和 multi-hit 比例持续高于两个 RAG 基线。 这说明,在检索前把记忆解耦为更细粒度的组件,有助于集中与答案相关的证据,而不是让这些证据分散在冗余原始块中。 相比之下,剪枝会将命中分布从 2-hit 和 multi-hit 块推向 1-hit 块,说明即使保留的上下文总体相关,检索后压缩仍可能使相互纠缠的证据碎片化。 例如,在多跳问题上,xMemory 将 2-hit 和 multi-hit 比例分别提高到 13.14% 和 12.19%,而 Naive RAG 对应比例仅为 7.82% 和 6.53%。

表3:LoCoMo 上的平均证据覆盖效率。Blocks 表示覆盖全部答案证据单元所需的平均检索块数,Tokens 表示相应的 token 成本;完整的分类结果见附录。
MethodBLEUF1Blocks ↓Tokens ↓
Naive RAG27.9536.4810.811979.26
RAG + Pruning26.5534.5813.311587.99
xMemory34.4843.985.66974.56

We further evaluate coverage efficiency by comparing how many retrieved blocks and tokens are needed to cover all answer evidence units. Table 3 shows that pruning reduces token cost relative to Naive RAG, but requires more blocks and yields lower accuracy, consistent with fragmented evidence after compression. In contrast, xMemory achieves the best BLEU/F1 while covering answer evidence with substantially fewer blocks and tokens. This suggests that xMemory improves not simply by retrieving less context, but by concentrating more answer-relevant evidence into a smaller retrieval budget.

我们进一步评估覆盖效率,比较覆盖全部答案证据单元所需的检索块数和 token 数。 表3表明,与 Naive RAG 相比,剪枝降低了 token 成本,但需要更多检索块且准确率更低,这与压缩后证据碎片化的现象一致。 相比之下,xMemory 以显著更少的检索块和 token 覆盖答案证据,同时取得最佳 BLEU/F1。 这说明 xMemory 的提升并非只是因为检索了更少的上下文,而是因为它把更多答案相关证据集中在更小的检索预算内。

Cost performance trade-off on LoCoMo
图6:LoCoMo 上的成本--性能权衡。图中使用 Qwen3-8B 绘制总 token 成本与平均 BLEU 的关系。

End-to-end cost--performance trade-off. The above analysis focuses on inference-time retrieval efficiency. We next examine whether this advantage remains after accounting for memory construction cost. Following the LightMem-style reporting setup, we calculate construction tokens and compute total token cost as average construction cost plus average inference tokens per query multiplied by the corresponding query count. The exact statistics used for this analysis are reported in the appendix.

端到端成本--性能权衡。 上述分析关注推理时的检索效率。 接下来,我们考察在计入记忆构建成本后,这项优势是否仍然存在。 按照 LightMem 风格的报告设置,我们计算构建 token,并将总 token 成本定义为平均构建成本,加上每个查询的平均推理 token 数与相应查询数量的乘积。 该分析使用的精确统计数据见附录。

As shown in Figure 6, xMemory achieves the most favourable trade-off. Flat baselines such as Naive RAG and LightMem use relatively low or moderate token budgets, but obtain lower answer quality. Structured memory baselines improve over flat retrieval in some cases, but usually incur higher construction and inference costs. In contrast, xMemory attains the highest average BLEU while using a lower total token cost than Nemori, MemoryOS, and A-Mem. This suggests that the denser evidence retrieved by xMemory not only improves local coverage efficiency, but also translates into a better end-to-end efficiency--quality balance after amortising construction cost.

图6所示,xMemory 取得了最有利的权衡。 Naive RAG 和 LightMem 等扁平基线使用相对较低或适中的 token 预算,但回答质量较低。 结构化记忆基线在某些情况下优于扁平检索,但通常会产生更高的构建与推理成本。 相比之下,xMemory 获得最高的平均 BLEU,同时总 token 成本低于 Nemori、MemoryOS 和 A-Mem。 这说明,xMemory 检索到的更密集证据不仅改善了局部覆盖效率,而且在摊销构建成本后,也转化为更好的端到端效率--质量平衡。

6. Conclusion

We presented xMemory, a retrieval framework that uses hierarchical organisation to address the mismatch between agent memory and standard RAG assumptions. By disentangling highly correlated memories into semantic components and retrieving top-down over the resulting hierarchy, xMemory reduces redundancy while preserving temporally linked evidence. Across LoCoMo and PerLTQA, xMemory improves answer quality with lower token cost and retrieves more evidence-dense contexts than RAG baselines. These results suggest that effective agent memory should not only retrieve or compress past interactions, but also reorganise them into evidence-oriented structures that make subtle distinctions easier to access. We hope xMemory provides a useful step toward more adaptive and efficient memory systems for long-horizon LLM agents.

我们提出了 xMemory,这是一种利用层级组织解决智能体记忆与标准 RAG 假设之间不匹配问题的检索框架。 xMemory 将高度相关的记忆解耦为语义组件,并在所得层级结构上自顶向下检索,从而在保留时间关联证据的同时减少冗余。 在 LoCoMo 和 PerLTQA 上,xMemory 以更低的 token 成本提高了回答质量,并且比 RAG 基线检索到证据密度更高的上下文。 这些结果表明,有效的智能体记忆不仅应检索或压缩过去的交互,还应将它们重新组织为面向证据的结构,使细微差异更易访问。 我们希望 xMemory 能够为面向长程 LLM 智能体构建更具适应性和效率的记忆系统迈出有益一步。