Elasticsearch Knowledge Graph for MCP

by j3k0

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Uses Elasticsearch as the backend for the knowledge graph, providing distributed, scalable storage for entities and relations with advanced search capabilities

  • Provides a TypeScript interface to Elasticsearch with all core operations for interacting with the knowledge graph

MCP 内存:用于 AI 对话的持久内存

**赋予你的 AI 一段在对话过程中持续存在的记忆。**这样就再也不会丢失重要的上下文了。

MCP Memory 是一个强大的、由 Elasticsearch 支持的知识图谱系统,它为 AI 模型提供超越其上下文窗口限制的持久内存。它专为模型上下文协议 (MCP) 构建,可确保您的 LLM 永久记住重要信息,从而创建更连贯、个性化且高效的 AI 对话。

🌟 为什么 AI 模型需要持久内存

在使用人工智能助手时,您曾经遇到过这些令人沮丧的情况吗?

  • 你的人工智能会忘记之前对话中的关键细节
  • 每次开始新的聊天时都必须重复相同的内容
  • 一旦对话历史记录写满,就会失去宝贵的见解
  • 无法参考过去的工作或决策

MCP Memory 通过创建结构化、可搜索的记忆存储来解决这些问题,该存储可以无限期地保存上下文。您的 AI 现在能够与用户建立有意义的长期关系,并在数天、数周甚至数月的交互中保持一致性。

✨ 主要特点

  • 📊 持久内存:跨多个会话存储和检索信息
  • 🔍 智能搜索:通过强大的 Elasticsearch 查询准确找到您所需的内容
  • 📓 上下文回忆:人工智能根据对话自动确定相关信息的优先级
  • 🧩 关系理解:将概念与模仿人类联想记忆的关系联系起来
  • 🔄 长期/短期记忆:区分暂时细节和重要知识
  • 🗂️ 记忆区域:将信息组织到不同的领域(项目、客户、主题)
  • 🔒 可靠且可扩展:基于 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 桌面

MCP Memory 旨在与 Claude Desktop 无缝协作,为 Claude 提供所有对话的持久内存:

  1. 复制并配置启动脚本该存储库包含一个launch.example文件,您可以简单复制它:
    # Copy the example launch file cp launch.example launch.sh # Edit launch.sh to add your Groq API key # This is required for smart memory retrieval nano launch.sh # or use your preferred editor
    使脚本可执行:
    chmod +x launch.sh
  2. 将命令添加到 Claude Desktop
    • 打开 Claude 桌面设置
    • 导航到“命令”部分
    • 点击“添加新命令”
    • 配置如下:
      • 名称:MCP内存
      • 命令:/path/to/mcp-servers/memory/launch.sh
      • 参数:留空
      • 在后台运行:是
      • 在菜单中显示:是
  3. 验证连接
    • 从 Claude Desktop 启动命令
    • 您应该会看到一条通知,提示 Claude 已连接到 MCP Memory
    • 尝试向克劳德询问你们在之前的谈话中讨论过的事情!

有关完整示例和可视化指南,请参阅在线Claude Desktop MCP 服务器设置指南

💡 工作原理

MCP Memory 创建结构化知识图谱,其中:

  1. 实体代表人、概念、项目或任何值得记住的事物
  2. 关系连接实体,创建关联网络
  3. 观察捕捉实体的具体细节
  4. 相关性评分决定优先考虑哪些信息

与 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)

Agent 如何使用内存

当用户提到一些重要的事情时,代理:

  1. 识别值得记住的重要信息
  2. 通过创建实体、关系和观察将其存储在内存中
  3. 当出现新细节时更新现有信息

当用户提及与存储信息相关的内容时,代理:

  1. 根据当前对话在记忆中搜索相关上下文
  2. 检索可能有用的重要细节
  3. 这些信息自然地融入到其响应中

这是自动发生的——用户只需与助手进行正常对话,记忆系统就会在后台工作以维护会话之间的上下文。

智能实体管理

MCP 内存包括实体创建和更新的智能处理:

  • 当尝试创建已存在的实体时,系统将返回现有实体数据以及如何使用新信息进行扩展的指导
  • 系统智能区分创建新实体和更新现有实体
  • 即使信息更新,实体关系也会自动维护

🧰 管理工具

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

📝 许可证

麻省理工学院


ID: h9w4cyfdqx