Tools
Memory Neo4j For Openclaw
OpenClaw Neo4j graph database-backed memory plugin
Install
openclaw plugins install .
Configuration Example
{
"plugins": {
"slots": {
"memory": "memory-neo4j"
},
"entries": {
"memory-neo4j": {
"enabled": true,
"config": {
"connection": {
"uri": "bolt://localhost:7687",
"username": "neo4j",
"password": "your-password"
}
}
}
}
}
}
README
# Neo4j 图谱记忆插件
基于 Neo4j 图数据库的长期记忆系统,支持实体关系存储和多跳检索。
## 功能特性
- **实体存储**: 存储用户、任务、项目等实体节点
- **关系管理**: 建立实体间的语义关系
- **多跳检索**: 支持图遍历和关系推理
- **自动捕获**: AI 主动调用工具存储对话中的重要信息
- **智能搜索**: LLM 自主判断是否需要搜索历史记忆
## 快速开始
### 1. 安装插件
```bash
# 进入插件目录(或指定插件路径)
cd /path/to/memory-neo4j
# 方式一:从当前目录安装(推荐)
openclaw plugins install .
# 方式二:指定完整路径
openclaw plugins install /path/to/memory-neo4j
# 方式三:从压缩包安装
openclaw plugins install ./memory-neo4j.tgz
# 方式四:开发模式(符号链接,修改源码立即生效)
openclaw plugins install -l .
```
### 2. 启动 Neo4j
```bash
# Docker 方式
docker run -d \
--name neo4j \
-p 7474:7474 -p 7687:7687 \
-e NEO4J_AUTH=neo4j/password \
neo4j:latest
# 或使用 Neo4j Desktop / Aura 云服务
```
### 3. 配置并启用
**方式一:CLI 命令(推荐)**
```bash
# 启用插件
openclaw plugins enable memory-neo4j
# 配置连接信息
openclaw config set plugins.entries.memory-neo4j.config.connection.uri "bolt://localhost:7687"
openclaw config set plugins.entries.memory-neo4j.config.connection.username "neo4j"
openclaw config set plugins.entries.memory-neo4j.config.connection.password "your-password"
# 切换到图谱记忆(设为默认记忆后端)
openclaw config set plugins.slots.memory "memory-neo4j"
```
**方式二:编辑 openclaw.json**
```json
{
"plugins": {
"slots": {
"memory": "memory-neo4j"
},
"entries": {
"memory-neo4j": {
"enabled": true,
"config": {
"connection": {
"uri": "bolt://localhost:7687",
"username": "neo4j",
"password": "your-password"
}
}
}
}
}
}
```
### 4. 配置系统提示词
将 `graph-memory.md` 复制到工作区:
```bash
cp extensions/memory-neo4j/graph-memory.md ~/your-workspace/MEMORY.md
```
OpenClaw 会在每次会话时自动注入 `MEMORY.md` 的内容。
## 移植和分发
### 导出插件
```bash
# 直接复制整个文件夹
cp -r /path/to/openclaw/extensions/memory-neo4j ./
# 或打包为压缩包
tar -czvf memory-neo4j.tgz -C /path/to/openclaw/extensions memory-neo4j
```
### 导入插件
```bash
# 从文件夹安装
openclaw plugins install ./memory-neo4j
# 或从压缩包安装
openclaw plugins install ./memory-neo4j.tgz
```
### 依赖说明
插件 `package.json` 声明了以下依赖,OpenClaw 安装时会自动处理:
| 依赖 | 版本 | 用途 |
| ------------------- | ------- | ------------------------- |
| `neo4j-driver` | ^6.0.0 | Neo4j 数据库连接 |
| `@sinclair/typebox` | 0.34.48 | 类型验证(OpenClaw 内置) |
> **注意**:无需手动执行 `npm install`,OpenClaw 会自动安装依赖。
## 安装方式详解
### 从文件夹安装
```bash
# 复制到 OpenClaw 的 extensions 目录
cp -r memory-neo4j /path/to/openclaw/extensions/
# 或使用 CLI 安装命令(自动复制到 ~/.openclaw/extensions/)
openclaw plugins install ./memory-neo4j
```
### 从压缩包安装
```bash
# 打包插件
tar -czvf memory-neo4j.tgz memory-neo4j/
# 或
zip -r memory-neo4j.zip memory-neo4j/
# 安装
openclaw plugins install ./memory-neo4j.tgz
openclaw plugins install ./memory-neo4j.zip
```
### 开发模式
```bash
# 创建符号链接,修改源码后无需重新安装
openclaw plugins install -l ./memory-neo4j
```
### 插件目录结构
```
memory-neo4j/
├── openclaw.plugin.json # 插件元数据(必需)
├── package.json # 依赖声明
├── index.ts # 插件入口
├── src/
│ ├── db.ts # Neo4j 连接
│ ├── entity-extractor.ts # 实体提取
│ ├── tools/ # 工具定义
│ └── types.ts # 类型定义
├── config.ts # 配置 schema
└── README.md
```
## 记忆系统选择
OpenClaw 支持多种记忆后端,**建议只选择一种**:
| 记忆类型 | 插件 | 用途 | 特点 |
| -------- | -------------- | ---------------------- | ---------------------- |
| 文件记忆 | `memory-core` | 日志、笔记、自由文本 | 简单、灵活、人类可读 |
| 图谱记忆 | `memory-neo4j` | 实体、关系、结构化知识 | 可推理、可关联、可查询 |
**注意**:切换记忆后端不会自动迁移数据。
## 工具说明
### 搜索工具
| 工具 | 说明 |
| ----------------------- | ---------------------- |
| `memory_graph_search` | 搜索图谱中的实体和关系 |
| `memory_relation_query` | 查询特定实体之间的关系 |
### 写入工具
| 工具 | 说明 |
| ----------------------- | -------------------------------------- |
| `memory_entity_capture` | **自动捕获对话中的实体和关系(推荐)** |
| `memory_entity_add` | 手动添加单个实体 |
| `memory_relation_add` | 手动添加单个关系 |
## 使用示例
```
用户: 给你发布一个新任务,拉取 GitHub 中 XX 仓库的内容,合并到 XXX 本地项目中。
AI: 收到任务,建议命名为"自我进化"。
(调用 memory_entity_capture)
工具返回: 已存储实体: 自我进化; 已建立关系: USER → 自我进化, AI → 自我进化
AI: 已在知识图谱中创建"自我进化"任务,建立了与您的关系。
```
## 配置说明
### connection 连接配置
| 参数 | 说明 | 默认值 |
| ---------- | --------- | ----------------------- |
| `uri` | Neo4j URI | `bolt://localhost:7687` |
| `username` | 用户名 | `neo4j` |
| `password` | 密码 | - |
| `database` | 数据库名 | `neo4j` |
> **URI 协议**:
>
> - `bolt://127.0.0.1:7687` - 直接连接单实例
> - `neo4j://127.0.0.1:7687` - 支持路由/集群(Neo4j Desktop 默认)
>
> 本地单实例两种都可以,集群环境必须用 `neo4j://`
### extraction 提取配置
| 参数 | 说明 | 默认值 |
| -------------------- | ---------------------------------- | ------ |
| `mode` | 提取模式: `auto`/`manual`/`hybrid` | `auto` |
| `minConfidence` | 最小置信度阈值 | `0.6` |
| `maxChars` | 最大提取字符数 | `2000` |
| `maxRounds` | 最大提取对话轮数 | `3` |
| `model.useMainModel` | 使用主智能体模型 | `true` |
### lifecycle 生命周期配置
| 参数 | 说明 | 默认值 |
| ------------- | ---------------- | ------ |
| `autoCapture` | 自动捕获对话内容 | `true` |
### retrieval 检索配置
| 参数 | 说明 | 默认值 |
| ---------------- | -------------- | ------ |
| `maxHops` | 图遍历最大跳数 | `3` |
| `maxResults` | 最大返回结果数 | `20` |
| `minConfidence` | 最小匹配置信度 | `0.5` |
| `includeContext` | 包含关联上下文 | `true` |
## CLI 命令
```bash
# 查看记忆统计
openclaw neo4j-memory stats
# 初始化图谱(创建 USER/AI 节点)
openclaw neo4j-memory init
# 清空图谱
openclaw neo4j-memory clear
```
## 故障排除
### 连接失败
```bash
# 检查 Neo4j 是否运行
docker ps | grep neo4j
# 测试连接
curl http://localhost:7474
```
### 查看日志
```bash
openclaw logs --tail 100 | grep memory-neo4j
```
tools
Comments
Sign in to leave a comment