MCP Brain 知识图谱记忆库
为模型上下文协议(Model Context Protocol)提供了一个可扩展的知识图谱实现,使用 Elasticsearch,使人工智能模型能够存储和查询信息,具备高级搜索功能、类似记忆的行为和多区域架构。
服务介绍
MCP Memory: 为 AI 对话提供持久记忆 🧠
赋予你的 AI 跨对话持久的记忆。 再也不用担心丢失重要的上下文。
MCP Memory 是一个基于 Elasticsearch 的强大知识图谱系统,它让 AI 模型能够在其上下文窗口之外拥有持久的记忆。该系统专为 Model Context Protocol (MCP) 设计,确保你的大型语言模型能够永远记住重要信息,从而创建更加连贯、个性化和有效的 AI 对话。
🌟 为什么 AI 模型需要持久记忆
你是否曾经历过这些与 AI 助手相关的困扰?
- AI 忘记了之前对话中的关键细节
- 每次开始新聊天时都需要重复相同的上下文
- 一旦对话历史填满,有价值的信息就会丢失
- 无法引用过去的工作或决策
MCP Memory 通过创建一个结构化的、可搜索的记忆存储来解决这些问题,它可以无限期地保存上下文。现在,你的 AI 可以与用户建立有意义的长期关系,并在几天、几周甚至几个月的互动中保持一致性。
✨ 主要功能
- 📊 持久记忆: 在多个会话中存储和检索信息
- 🔍 智能搜索: 使用强大的 Elasticsearch 查询找到你需要的确切信息
- 📓 上下文回忆: AI 根据对话自动优先处理相关信息
- 🧩 关系理解: 通过模仿人类联想记忆的方式连接概念
- 🔄 长期/短期记忆: 区分临时细节和重要知识
- 🗂️ 记忆区域: 将信息组织成不同的领域(项目、客户、主题)
- 🔒 可靠且可扩展: 基于 Elasticsearch 构建,具有企业级性能
🚀 5 分钟快速设置
开始使用非常简单:
先决条件
- Docker: 用于运行 Elasticsearch(或者本地安装 Elasticsearch)
- Node.js: 版本 18 或更高
- npm: 用于包管理
# 1. Clone the repository
git clone https://github.com/mcp-servers/mcp-servers.git
cd mcp-servers/memory
# 2. Install dependencies
npm install
# 3. Start Elasticsearch (uses Docker)
npm run es:start
# Note: If you prefer to use your own Elasticsearch installation,
# set the ES_NODE environment variable to point to your Elasticsearch instance
# 4. Build the project
npm run build
🔌 连接到 Claude Desktop
MCP Memory 旨在与 Claude Desktop 无缝协作,使 Claude 在所有对话中都具备持久记忆:
-
复制并配置启动脚本:
仓库中包含一个
launch.example文件,你可以直接复制:# 复制示例启动文件 cp launch.example launch.sh # 编辑 launch.sh 文件以添加你的 Groq API 密钥 # 这是智能内存检索所必需的 nano launch.sh # 或使用你偏好的编辑器使脚本可执行:
chmod +x launch.sh -
在 Claude Desktop 中添加命令:
- 打开 Claude Desktop 设置
- 导航到“命令”部分
- 点击“添加新命令”
- 按以下方式配置:
- 名称: MCP Memory
- 命令: /path/to/mcp-servers/memory/launch.sh
- 参数: 留空
- 后台运行: 是
- 显示在菜单中: 是
-
验证连接:
- 从 Claude Desktop 启动命令
- 你应该会看到一个通知,表明 Claude 已连接到 MCP Memory
- 尝试询问 Claude 一些你在之前的对话中讨论过的内容!
有关完整的示例和可视化指南,请参阅在线的 Claude Desktop MCP Server 设置指南。
💡 工作原理
MCP Memory 创建了一个结构化的知识图谱,其中:
- 实体 代表人、概念、项目或任何值得记住的事物
- 关系 连接实体,创建关联网络
- 观察 捕捉关于实体的具体细节
- 相关性评分 决定优先考虑哪些信息
当与 LLM 集成时,系统会自动:
- 存储在对话中学到的新信息
- 在需要时检索相关上下文
- 在相关概念之间建立联系
- 忘记不重要的细节,同时保留关键知识
🛠️ 示例:代理如何使用记忆
从用户的角度来看
对话 1:初始信息
User: My daughter's name is Emma and she's turning 8 next month.
Claude: That's wonderful! Emma will be turning 8 next month. Is there anything special you're planning for her birthday?
(Behind the scenes: Claude stores "Emma" as an entity of type "Person" with observations about her age and birthday timing)
对话 2:几天或几周后
User: I'm thinking about what to get for a gift.
Claude: If you're looking for gift ideas for Emma's 8th birthday coming up, have you considered what her current interests are? At that age, many children enjoy creative items, books, or educational games.
(Behind the scenes: Claude retrieved the entity "Emma", her age, and the fact that her birthday is approaching)
对话 3:生日之后
User: The party went really well on Saturday!
Claude: I'm glad Emma's 8th birthday party was a success on Saturday! Did she enjoy the gifts she received?
(Behind the scenes: Claude updates the observations about Emma, noting that her birthday party occurred on a Saturday and went well)
代理如何使用记忆
当用户提到重要信息时,代理会:
- 识别值得记住的重要信息
- 通过创建实体、关系和观察来将其存储在内存中
- 当出现新的细节时更新现有信息
当用户提到与存储信息相关的内容时,代理会:
- 基于当前对话搜索相关上下文
- 检索可能有用的重要细节
- 自然地将这些信息融入其回应中
这一切都是自动发生的——用户只需与助手进行正常的对话,而记忆系统则在幕后工作,以跨会话维护上下文。
智能实体管理
MCP Memory 包括对实体创建和更新的智能处理:
- 当尝试创建一个已存在的实体时,系统会返回现有的实体数据,并提供如何用新信息扩展它的指导
- 系统智能地区分创建新实体和更新现有实体
- 即使在信息更新时,实体关系也会自动维护
🧰 管理工具
MCP Memory 包含了一个全面的管理 CLI 用于维护你的知识图谱:
# Search the memory
node dist/admin-cli.js search "Emma birthday"
# View details about a specific entity
node dist/admin-cli.js entity "Emma"
# Back up your entire memory system
node dist/admin-cli.js backup memory-backup.json
📚 高级功能
记忆区域
将知识组织成独立的领域:
# Create a project-specific memory zone
node dist/admin-cli.js zones add client-acme "ACME Corp Project Knowledge"
# Import data into that zone
node dist/admin-cli.js import acme-data.json client-acme
对话记忆管理
您还可以通过自然对话指示助手在不同的区域内组织记忆:
创建和使用记忆区域
User: Claude, can you create a new memory zone called "work-project" for storing information about my current work project?
Claude: I've created a new memory zone called "work-project". I'll store information related to your work project in this zone. What would you like me to remember about your project?
User: The project deadline is March 15th, and we're building a new inventory management system.
Claude: I've stored information about your work project in the "work-project" zone, including the March 15th deadline and that you're building an inventory management system. I'll keep future information about this project organized in this zone.
(Behind the scenes: Claude creates a new memory zone and stores project information specifically in that zone)
检索特定区域的信息
User: What do you remember about my work project?
Claude: Based on what we've discussed about your work project, I recall that you're building an inventory management system with a deadline of March 15th.
(Behind the scenes: Claude specifically searches the "work-project" zone for relevant information)
在记忆区域之间切换
User: Claude, let's switch to my "cooking" memory zone now. I want to discuss a recipe.
Claude: I've switched to your "cooking" memory zone. What recipe would you like to discuss today?
(Behind the scenes: Claude updates its memory context to prioritize searching in the "cooking" zone)
User: What was that pasta dish I told you about last month?
Claude: From our previous conversations in your cooking zone, you shared a carbonara recipe that used pancetta, eggs, pecorino cheese, and black pepper. You mentioned it was a family favorite that you learned during your trip to Rome.
(Behind the scenes: Claude searches specifically in the "cooking" zone to find this information)
通过将记忆组织到不同的区域中,对话变得更加相关且聚焦于当前主题或项目。
搜索能力
利用 Elasticsearch 强大的搜索特性:
# Fuzzy search (finds "meeting" even with typo)
node dist/admin-cli.js search "meteing notes"
# Zone-specific search
node dist/admin-cli.js search "budget" client-acme
🤝 贡献
欢迎贡献!详情请见 CONTRIBUTING.md。
📝 许可证
MIT