[论文解读] MemGPT: Towards LLMs as Operating Systems
MemGPT 引入了一个受操作系统启发的内存层级,通过在主上下文和外部存储之间分页数据来扩展固定上下文大语言模型的有效上下文,从而提升对长文档的分析以及多会话对话的能力。
Large language models (LLMs) have revolutionized AI, but are constrained by limited context windows, hindering their utility in tasks like extended conversations and document analysis. To enable using context beyond limited context windows, we propose virtual context management, a technique drawing inspiration from hierarchical memory systems in traditional operating systems that provide the appearance of large memory resources through data movement between fast and slow memory. Using this technique, we introduce MemGPT (Memory-GPT), a system that intelligently manages different memory tiers in order to effectively provide extended context within the LLM's limited context window, and utilizes interrupts to manage control flow between itself and the user. We evaluate our OS-inspired design in two domains where the limited context windows of modern LLMs severely handicaps their performance: document analysis, where MemGPT is able to analyze large documents that far exceed the underlying LLM's context window, and multi-session chat, where MemGPT can create conversational agents that remember, reflect, and evolve dynamically through long-term interactions with their users. We release MemGPT code and data for our experiments at https://memgpt.ai.
研究动机与目标
- 解决固定上下文大模型在长对话和长文档中的上下文窗口限制。
- 提出一种受操作系统内存层级启发的虚拟上下文管理系统。
- 通过 LLM 函数调用实现对外部数据源的读/写以管理内存。
- 展示在文档分析和对话代理方面相较基线的性能提升。
- 发布代码和数据集以促进未来的长上下文研究。
提出的方法
- 定义两级内存层次结构:主上下文(提示令牌)和外部上下文(存档存储)。
- 引入带有函数调用的 LLM 操作系统,在内存层之间移动数据并自动管理内存。
- 实现一个队列管理器,处理内存压力、驱逐以及用于溢出控制的递归摘要。
- 实现函数串联,以在推理循环中进行多步骤检索和迭代内存更新。
- 使用带有内存层次指令和函数结构的系统提示,指导 LLM 的内存访问。
- 在長文档问答和多会话对话任务上使用 MSC 的扩展以及文档问答基准进行评估 MemGPT。

实验结果
研究问题
- RQ1MemGPT 是否能够通过利用外部存储超出 LLM 的上下文窗口来在长时间对话中维持连贯性和参与度?
- RQ2与固定上下文基线相比,受操作系统启发的内存层次结构是否提升了在长文档问答和多跳检索任务上的性能?
- RQ3分页回忆和内存驱逐在维护推理相关上下文方面有多有效?
- RQ4MemGPT 是否能够在多数据源之间进行多跳信息检索(嵌套 KV 检索),超越原生上下文大小?
主要发现
- MemGPT 在多会话聊天的深层内存检索方面优于固定上下文基线,基于底层模型(例如,GPT-4 Turbo: MemGPT 93.4% vs 基线 35.3%)。
- 在对话开场任务中,基于 MemGPT 的开场在若干模型上与人类开场相当或超出,显示出增强的参与度。
- 使用 MemGPT 的文档问答在超出固定上下文窗口的情况下扩展,并且在 GPT-4 变体中明显优于截断基线。
- MemGPT 实现了多跳、嵌套的键值检索,当固定上下文模型的嵌套增加时性能下降,而 MemGPT 展现出稳健的基于记忆的推理能力。
- 该方法通过利用持久化的记忆积压而非历史的有损摘要,保持长会话中的一致性和连贯性。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。