向量记忆概述
OpenClaw 的 Memory 系统允许 AI 助手拥有长期记忆,超越单次对话的上下文窗口限制。它使用向量数据库存储和检索信息,支持语义搜索。
启用记忆系统
openclaw memory enable
配置向量存储:
{
"memory": {
"enabled": true,
"provider": "local",
"embeddingModel": "text-embedding-3-small",
"embeddingProvider": "openai",
"maxMemories": 10000,
"searchResults": 5
}
}
手动添加记忆
# 添加文本记忆
openclaw memory add "公司成立于2020年,总部位于北京"
openclaw memory add "张三是技术部负责人,擅长Python开发"
# 从文件导入
openclaw memory import knowledge.txt
openclaw memory import faq.md --format markdown
# 从目录批量导入
openclaw memory import ./docs/ --recursive
搜索记忆
openclaw memory search "公司什么时候成立的"
Search results (top 3):
1. [0.92] 公司成立于2020年,总部位于北京
Source: manual Added: 2026-03-15
2. [0.78] 公司2021年获得A轮融资
Source: docs/history.md Added: 2026-03-15
3. [0.65] 公司目前有200名员工
Source: docs/about.md Added: 2026-03-15
方括号中的数字是相似度分数(0-1)。
查看记忆统计
openclaw memory stats
Memory Statistics:
Total memories: 1,520
Storage size: 25MB
Embedding model: text-embedding-3-small
Index status: up-to-date
Last updated: 10 minutes ago
By source:
manual: 50
docs/: 1,200
conversations: 270
管理记忆
# 列出最近的记忆
openclaw memory list --last 20
# 删除特定记忆
openclaw memory delete mem_abc123
# 清空所有记忆
openclaw memory clear --confirm
# 按来源清理
openclaw memory clear --source "docs/"
自动记忆
配置 AI 自动从对话中提取和保存重要信息:
{
"memory": {
"autoCapture": {
"enabled": true,
"threshold": 0.8,
"categories": ["fact", "preference", "instruction"],
"maxPerSession": 10
}
}
}
在 AI 对话中使用
为频道启用记忆工具:
{
"channels": {
"telegram-main": {
"tools": ["memory_search", "memory_add"]
}
}
}
对话示例:
用户: 记住我喜欢喝咖啡
AI: 好的,我已经记住了你喜欢喝咖啡。
[几天后]
用户: 我适合喝什么饮料?
AI: 根据我的记忆,你喜欢喝咖啡,所以推荐你试试拿铁或美式。
自定义 Embedding 模型
使用本地 Embedding 模型:
{
"memory": {
"embeddingProvider": "ollama",
"embeddingModel": "nomic-embed-text",
"embeddingBaseUrl": "http://localhost:11434"
}
}
备份与恢复
# 备份记忆数据
openclaw memory export --output memory-backup.json
# 恢复记忆数据
openclaw memory import --input memory-backup.json
总结
向量记忆系统让 OpenClaw 的 AI 助手具备了长期记忆能力,可以记住用户偏好、公司知识和历史对话中的关键信息。通过合理配置自动记忆和手动知识导入,可以打造一个越用越懂你的 AI 助手。