D

DuckDB记忆服务器

@IzumiSy/mcp-duckdb-memory-server
0 Stars 475 次浏览 IzumiSy 更新于 2026-08-23

用于 Claude 的记忆服务器,它在 DuckDB 中存储和检索知识图谱数据,通过持久化的用户信息增强对话的性能和查询能力。

该服务暂未提供标准配置,请参考 README 手动接入

可用工具 (8 个)

该服务在 MCP 协议中暴露的工具,AI 可按需调用

create_entities 1 个参数 需填 1 项

Create multiple new entities in the knowledge graph

必填参数:entities

create_relations 1 个参数 需填 1 项

Create multiple new relations between entities in the knowledge graph. Relations should be in active voice

必填参数:relations

add_observations 1 个参数 需填 1 项

Add new observations to existing entities in the knowledge graph

必填参数:observations

delete_entities 1 个参数 需填 1 项

Delete multiple entities and their associated relations from the knowledge graph

必填参数:entityNames

delete_observations 1 个参数 需填 1 项

Delete specific observations from entities in the knowledge graph

必填参数:deletions

delete_relations 1 个参数 需填 1 项

Delete multiple relations from the knowledge graph

必填参数:relations

search_nodes 1 个参数 需填 1 项

Search for nodes in the knowledge graph based on a query

必填参数:query

open_nodes 1 个参数 需填 1 项

Open specific nodes in the knowledge graph by their names

必填参数:names

服务介绍

MCP DuckDB 知识图谱内存服务器

Test
smithery badge
NPM Version
NPM License

这是 官方知识图谱内存服务器 的一个分支版本。

安装

通过 Smithery 安装

要通过 Smithery 自动安装适用于 Claude 桌面版的 DuckDB 知识图谱内存服务器:

npx -y @smithery/cli install @IzumiSy/mcp-duckdb-memory-server --client claude

手动安装

否则,请在 claude_desktop_config.json 中手动添加 @IzumiSy/mcp-duckdb-memory-serverMEMORY_FILE_PATH 是可选的)

{
  "mcpServers": {
    "graph-memory": {
      "command": "npx",
      "args": [
        "-y",
        "@izumisy/mcp-duckdb-memory-server"
      ],
      "env": {
        "MEMORY_FILE_PATH": "/path/to/your/memory.data"
      }
    }
  }
}

存储在该路径上的数据是一个 DuckDB 数据库文件。

Docker

构建

docker build -t mcp-duckdb-graph-memory .

运行

docker run -dit mcp-duckdb-graph-memory

使用

使用下面的示例指令

Follow these steps for each interaction:

1. User Identification:
   - You should assume that you are interacting with default_user
   - If you have not identified default_user, proactively try to do so.

2. Memory Retrieval:
   - Always begin your chat by saying only "Remembering..." and search relevant information from your knowledge graph
   - Create a search query from user words, and search things from "memory". If nothing matches, try to break down words in the query at first ("A B" to "A" and "B" for example).
   - Always refer to your knowledge graph as your "memory"

3. Memory
   - While conversing with the user, be attentive to any new information that falls into these categories:
     a) Basic Identity (age, gender, location, job title, education level, etc.)
     b) Behaviors (interests, habits, etc.)
     c) Preferences (communication style, preferred language, etc.)
     d) Goals (goals, targets, aspirations, etc.)
     e) Relationships (personal and professional relationships up to 3 degrees of separation)

4. Memory Update:
   - If any new information was gathered during the interaction, update your memory as follows:
     a) Create entities for recurring organizations, people, and significant events
     b) Connect them to the current entities using relations
     b) Store facts about them as observations

动机

该项目通过将后端替换为 DuckDB 来增强原始的 MCP 知识图谱内存服务器。

为什么选择 DuckDB?

原始的 MCP 知识图谱内存服务器使用 JSON 文件作为其数据存储,并执行内存搜索。虽然这种方法对于小数据集效果很好,但它存在几个挑战:

  1. 性能:随着数据集的增长,内存搜索性能会下降。
  2. 可扩展性:处理大量实体和关系时,内存使用量显著增加。
  3. 查询灵活性:实现复杂查询和条件搜索很困难。
  4. 数据完整性:确保事务和 CRUD 操作的原子性具有挑战性。

选择 DuckDB 是为了应对这些挑战:

  • 快速查询处理:DuckDB 针对分析查询进行了优化,即使在大数据集下也能表现良好。
  • SQL 接口:可以使用标准 SQL 轻松执行复杂查询。
  • 事务支持:支持事务处理以维护数据完整性。
  • 索引功能:允许创建索引来提高搜索性能。
  • 嵌入式数据库:无需外部数据库服务器即可在应用程序内工作。

实现细节

此实现使用 DuckDB 作为后端存储系统,重点关注两个关键方面:

数据库结构

知识图谱存储在如下所示的关系数据库结构中:

erDiagram
    ENTITIES {
        string name PK
        string entityType
    }
    OBSERVATIONS {
        string entityName FK
        string content
    }
    RELATIONS {
        string from_entity FK
        string to_entity FK
        string relationType
    }

    ENTITIES ||--o{ OBSERVATIONS : "has"
    ENTITIES ||--o{ RELATIONS : "from"
    ENTITIES ||--o{ RELATIONS : "to"

这种模式设计允许高效地存储和检索知识图谱组件,同时保持实体、观察和关系之间的关系。

模糊搜索实现

实现结合了 SQL 查询和 Fuse.js 进行灵活的实体搜索:

  • DuckDB SQL 查询从数据库中检索基础数据
  • Fuse.js 在检索到的数据上提供模糊匹配功能
  • 这种混合方法既支持结构化查询,也支持灵活的文本匹配
  • 搜索结果包括精确匹配和部分匹配,并按相关性排序

开发

设置

pnpm install

测试

pnpm test

许可证

本项目根据 MIT 许可证授权 - 详情请参阅 LICENSE 文件。

相关 MCP 服务