共享记忆存储服务

memory-mesh是一个本地优先的MCP服务器和REST API,允许多个AI助手在同一台机器上读写相同的记忆存储,并自动检测冲突。

  • by Das-Chinmay
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Das-Chinmay/memory-mesh

使用说明

🧠 内存网格

给克劳德、ChatGPT和双子座共享内存。

memory-mesh是一个本地第一个MCP服务器和REST API,它可以让机器上的每个人工智能助手读取和写入同一个内存存储-当两个代理不一致时,可以自动检测冲突。


神奇的时刻

没有共享密钥。没有协调。只需两个代理写下他们所知道的内容,并在它们相互矛盾时进行记忆网格捕捉。

# Claude saves a fact
curl -s -X POST http://localhost:8765/v1/memories \
  -H "Content-Type: application/json" \
  -d '{"content": "The Eiffel Tower is 300 metres tall", "agent_id": "claude"}'

# Gemini saves a contradicting fact
curl -s -X POST http://localhost:8765/v1/memories \
  -H "Content-Type: application/json" \
  -d '{"content": "The Eiffel Tower is 330 metres tall", "agent_id": "gemini"}'

第二个回应包括:

{
  "memory": { "...": "..." },
  "conflicts": [{
    "id": "abc-123",
    "trigger": "similarity",
    "memory_a_id": "...",
    "memory_b_id": "..."
  }]
}

以交互方式解决:

$ memory-mesh conflicts

============================================================
Conflict ID: abc-123  [similarity]

  A [...] (claude):
    The Eiffel Tower is 300 metres tall

  B [...] (gemini):
    The Eiffel Tower is 330 metres tall

  Which is correct? [a/b/skip]: a
  Resolved: claude's memory wins.

安装

pip install memory-mesh

快速入门--克劳德桌面(MCP)

添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "memory-mesh": {
      "command": "memory-mesh",
      "args": ["mcp"]
    }
  }
}

克劳德现在可以打电话了 save_context, search_context, list_conflicts, resolve_conflict,以及 delete_context 作为工具。


快速入门--ChatGPT/Gemini(REST)

启动REST服务器:

memory-mesh serve
# memory-mesh REST server starting on http://127.0.0.1:8765

然后将您的代理人指向 http://127.0.0.1:8765/v1/。可用端点:

方法 路径 描述
POST /v1/memories 保存内存条目
GET /v1/memories/search?q=... 语义搜索
GET /v1/memories/{id} 按ID提取
DELETE /v1/memories/{id} 删除内存
GET /v1/conflicts 列出冲突
POST /v1/conflicts/{id}/resolve 解决冲突

建筑

┌─────────────┐   ┌─────────────┐   ┌─────────────┐
│   Claude    │   │   ChatGPT   │   │   Gemini    │
│  (MCP/stdio)│   │  (REST API) │   │  (REST API) │
└──────┬──────┘   └──────┬──────┘   └──────┬──────┘
       │                 │                  │
       └─────────────────┼──────────────────┘
                         │
                ┌────────▼────────┐
                │   MemoryStore   │
                └────────┬────────┘
                         │
             ┌───────────┴────────────┐
             │                        │
     ┌───────▼──────┐       ┌────────▼───────┐
     │    SQLite    │       │    ChromaDB    │
     │ source of    │       │ vector search  │
     │   truth      │       │ (embeddings)   │
     └──────────────┘       └────────────────┘
                         │
                ┌────────▼────────┐
                │ ConflictDetector│
                │  L1: key match  │
                │  L2: similarity │
                │  L3: NLI (opt) │
                └─────────────────┘

每次写入都会通过ConflictDetector。冲突存储在SQLite中,并在保存响应中实时显示。


配置

Config住在 ~/.memory-mesh/config.json (在首次运行时使用默认值创建)。

字段 类型 默认值 描述
data_dir 路径 ~/.memory-mesh SQLite+ChromaDB的存储目录
similarity_threshold 浮子 0.85 余弦相似性,高于该相似度的条目会发生冲突
nli_enabled bool的。 false 启用第3层NLI矛盾检测
nli_model 字符串 cross-encoder/nli-deberta-v3-small NLI的HuggingFace模型
host 字符串 127.0.0.1 REST服务器绑定主机
port int 8765 REST服务器端口
auth_enabled bool的。 false 在REST服务器上启用承载令牌身份验证
auth_token 字符串 null 需要令牌时 auth_enabled 是真的

示例 config.json:

{
  "similarity_threshold": 0.90,
  "nli_enabled": true,
  "port": 9000
}

贡献

  1. 分叉并克隆仓库
  2. 安装开发依赖项: pip install -e ".[dev]"
  3. 运行测试: pytest
  4. 打开PR——所有测试都必须通过

请将错误和功能请求归档为 GitHub问题.


许可证

麻省 理工© Chinmay 酒店