NeuralMemory — Associative Memory for AI Agents
A biologically-inspired memory system that uses spreading activation instead of keyword/vector search. Memories form a neural graph where neurons connect via 20 typed synapses. Frequently co-accessed memories strengthen their connections (Hebbian learning). Stale memories decay naturally. Contradictions are auto-detected.
Why not just vector search? Vector search finds documents similar to your query. NeuralMemory finds conceptually related memories through graph traversal — even when there's no keyword or embedding overlap. "What decision did we make about auth?" activates time + entity + concept neurons simultaneously and finds the intersection.
Setup
1. Install NeuralMemory
CODEBLOCK0
This creates ~/.neuralmemory/ with a default brain and configures MCP automatically.
2. Configure MCP for OpenClaw
Add to your OpenClaw MCP configuration (~/.openclaw/mcp.json or project openclaw.json):
CODEBLOCK1
3. Verify
CODEBLOCK2
You should see brain statistics (neurons, synapses, fibers).
Tools Reference
Core Memory Tools
| Tool | Purpose | When to Use |
|---|
| INLINECODE3 | Store a memory | After decisions, errors, facts, insights, user preferences |
| INLINECODE4 |
Query memories | Before tasks, when user references past context, "do you remember..." |
|
nmem_context | Get recent memories | At session start, inject fresh context |
|
nmem_todo | Quick TODO with 30-day expiry | Task tracking |
Intelligence Tools
| Tool | Purpose | When to Use |
|---|
| INLINECODE7 | Auto-extract memories from text | After important conversations — captures decisions, errors, TODOs automatically |
| INLINECODE8 (depth=3) |
Deep associative recall | Complex questions requiring cross-domain connections |
|
nmem_habits | Workflow pattern suggestions | When user repeats similar action sequences |
Management Tools
| Tool | Purpose | When to Use |
|---|
| INLINECODE10 | Brain health diagnostics | Periodic checkup, before sharing brain |
| INLINECODE11 |
Brain statistics | Quick overview of memory counts |
|
nmem_version | Brain snapshots and rollback | Before risky operations, version checkpoints |
|
nmem_transplant | Transfer memories between brains | Cross-project knowledge sharing |
Workflow
At Session Start
- 1. Call
nmem_context to inject recent memories into your awareness - If user mentions a specific topic, call
nmem_recall with that topic
During Conversation
- 3. When a decision is made:
nmem_remember with type="decision" - When an error occurs:
nmem_remember with type="error" - When user states a preference:
nmem_remember with type="preference" - When asked about past events:
nmem_recall with appropriate depth
At Session End
- 7. Call
nmem_auto with action="process" on important conversation segments - This auto-extracts facts, decisions, errors, and TODOs
Examples
Remember a decision
CODEBLOCK3
Recall with spreading activation
nmem_recall(
query="database configuration for production",
depth=1,
max_tokens=500
)
Returns memories found via graph traversal, not keyword matching. Related memories (e.g., "deploy uses Docker with pg_dump backups") surface even without shared keywords.
Trace causal chains
nmem_recall(
query="why did the deployment fail last week?",
depth=2
)
Follows CAUSED
BY and LEADSTO synapses to trace cause-and-effect chains.
Auto-capture from conversation
nmem_auto(
action="process",
text="We decided to switch from REST to GraphQL because the frontend needs flexible queries. The migration will take 2 sprints. TODO: update API docs."
)
Automatically extracts: 1 decision, 1 fact, 1 TODO.
Key Features
- - Zero LLM dependency — Pure algorithmic: regex, graph traversal, Hebbian learning
- Spreading activation — Associative recall through neural graph, not keyword/vector search
- 20 synapse types — Temporal (BEFORE/AFTER), causal (CAUSEDBY/LEADSTO), semantic (ISA/HASPROPERTY), emotional (FELT/EVOKES), conflict (CONTRADICTS)
- Memory lifecycle — Short-term → Working → Episodic → Semantic with Ebbinghaus decay
- Contradiction detection — Auto-detects conflicting memories, deprioritizes outdated ones
- Hebbian learning — "Neurons that fire together wire together" — memory improves with use
- Temporal reasoning — Causal chain traversal, event sequences, temporal range queries
- Brain versioning — Snapshot, rollback, diff brain state
- Brain transplant — Transfer filtered knowledge between brains
- Vietnamese + English — Full bilingual support for extraction and sentiment
Depth Levels
| Depth | Name | Speed | Use Case |
|---|
| 0 | Instant | <10ms | Quick facts, recent context |
| 1 |
Context | ~50ms | Standard recall (default) |
| 2 | Habit | ~200ms | Pattern matching, workflow suggestions |
| 3 | Deep | ~500ms | Cross-domain associations, causal chains |
Notes
- - Memories are stored locally in SQLite at INLINECODE21
- No data is sent to external services (unless optional embedding provider is configured)
- Brain isolation: each brain is independent, no cross-contamination
- INLINECODE22 returns fiber_id for reference tracking
- Priority scale: 0 (trivial) to 10 (critical), default 5
- Memory types: fact, decision, preference, todo, insight, context, instruction, error, workflow, reference
技能名称: neural-memory
详细描述:
NeuralMemory — AI代理的联想记忆系统
一种受生物学启发的记忆系统,使用扩散激活而非关键词/向量搜索。记忆形成一个神经图,其中神经元通过20种类型化的突触连接。频繁共同访问的记忆会加强其连接(赫布学习)。过时的记忆自然衰减。矛盾会被自动检测。
为什么不用向量搜索? 向量搜索找到与查询相似的文档。NeuralMemory通过图遍历找到概念相关的记忆——即使没有关键词或嵌入重叠。我们关于认证做了什么决定?会同时激活时间+实体+概念神经元,并找到交集。
设置
1. 安装NeuralMemory
bash
pip install neural-memory
nmem init
这会在~/.neuralmemory/下创建一个默认大脑,并自动配置MCP。
2. 为OpenClaw配置MCP
添加到你的OpenClaw MCP配置(~/.openclaw/mcp.json或项目openclaw.json):
json
{
mcpServers: {
neural-memory: {
command: python3,
args: [-m, neural_memory.mcp],
env: {
NEURALMEMORY_BRAIN: default
}
}
}
}
3. 验证
bash
nmem stats
你应该会看到大脑统计信息(神经元、突触、纤维)。
工具参考
核心记忆工具
| 工具 | 用途 | 使用时机 |
|---|
| nmemremember | 存储记忆 | 在决策、错误、事实、见解、用户偏好之后 |
| nmemrecall |
查询记忆 | 在任务前、用户提及过往上下文时、你还记得吗... |
| nmem_context | 获取近期记忆 | 在会话开始时,注入新鲜上下文 |
| nmem_todo | 快速待办事项(30天过期) | 任务跟踪 |
智能工具
| 工具 | 用途 | 使用时机 |
|---|
| nmemauto | 从文本自动提取记忆 | 在重要对话后——自动捕获决策、错误、待办事项 |
| nmemrecall (depth=3) |
深度联想回忆 | 需要跨领域连接的复杂问题 |
| nmem_habits | 工作流模式建议 | 当用户重复类似操作序列时 |
管理工具
| 工具 | 用途 | 使用时机 |
|---|
| nmemhealth | 大脑健康诊断 | 定期检查,分享大脑前 |
| nmemstats |
大脑统计 | 快速查看记忆数量概览 |
| nmem_version | 大脑快照和回滚 | 在风险操作前,版本检查点 |
| nmem_transplant | 在大脑间转移记忆 | 跨项目知识共享 |
工作流
会话开始时
- 1. 调用nmemcontext将近期记忆注入你的意识
- 如果用户提到特定主题,用该主题调用nmemrecall
对话期间
- 3. 当做出决策时:使用type=decision调用nmemremember
- 当发生错误时:使用type=error调用nmemremember
- 当用户陈述偏好时:使用type=preference调用nmemremember
- 当被问及过去事件时:使用适当深度调用nmemrecall
会话结束时
- 7. 在重要对话片段上使用action=process调用nmem_auto
- 这会自动提取事实、决策、错误和待办事项
示例
记住一个决策
nmem_remember(
content=生产环境使用PostgreSQL,开发环境使用SQLite,
type=decision,
tags=[数据库, 基础设施],
priority=8
)
使用扩散激活回忆
nmem_recall(
query=生产环境的数据库配置,
depth=1,
max_tokens=500
)
返回通过图遍历找到的记忆,而非关键词匹配。相关记忆(例如部署使用Docker配合pg_dump备份)即使没有共享关键词也会浮现。
追踪因果链
nmem_recall(
query=为什么上周部署失败了?,
depth=2
)
沿着CAUSEDBY和LEADSTO突触追踪因果链。
从对话自动捕获
nmem_auto(
action=process,
text=我们决定从REST切换到GraphQL,因为前端需要灵活的查询。迁移需要2个冲刺。待办事项:更新API文档。
)
自动提取:1个决策,1个事实,1个待办事项。
关键特性
- - 零LLM依赖 — 纯算法:正则表达式、图遍历、赫布学习
- 扩散激活 — 通过神经图进行联想回忆,而非关键词/向量搜索
- 20种突触类型 — 时间(之前/之后)、因果(由...引起/导致)、语义(是一种/具有属性)、情感(感受到/唤起)、冲突(矛盾)
- 记忆生命周期 — 短期→工作→情景→语义,带艾宾浩斯衰减
- 矛盾检测 — 自动检测冲突记忆,降低过时记忆的优先级
- 赫布学习 — 一起放电的神经元连接在一起——记忆随使用而增强
- 时间推理 — 因果链遍历、事件序列、时间范围查询
- 大脑版本控制 — 快照、回滚、比较大脑状态
- 大脑移植 — 在大脑间转移过滤后的知识
- 越南语+英语 — 提取和情感分析的完全双语支持
深度级别
| 深度 | 名称 | 速度 | 使用场景 |
|---|
| 0 | 即时 | <10ms | 快速事实、近期上下文 |
| 1 |
上下文 | ~50ms | 标准回忆(默认) |
| 2 | 习惯 | ~200ms | 模式匹配、工作流建议 |
| 3 | 深度 | ~500ms | 跨领域关联、因果链 |
说明
- - 记忆本地存储在SQLite中,路径为~/.neuralmemory/brains/.db
- 不会向外部服务发送任何数据(除非配置了可选的嵌入提供者)
- 大脑隔离:每个大脑独立,无交叉污染
- nmem_remember返回纤维ID用于引用跟踪
- 优先级范围:0(琐碎)到10(关键),默认5
- 记忆类型:事实、决策、偏好、待办事项、见解、上下文、指令、错误、工作流、参考