概述
memory_search 通过将记忆文件索引为小块并使用 Embedding、关键词或两者结合进行搜索,即使措辞与原文不同也能找到相关笔记。
核心要点
双路检索并行执行:
Query → Embedding → 向量搜索 ─┐
Query → 分词 → BM25 搜索 ─┤→ 加权合并 → Top 结果
- 向量搜索:找语义相似的笔记(“gateway host” 匹配 “运行 OpenClaw 的机器”)
- BM25 关键词搜索:精确匹配(ID、错误字符串、配置键)
- 无 Embedding 时降级为词法排序(仍比纯精确匹配好)
支持的 Embedding 提供商:
| 提供商 | ID | 需要 API Key | 备注 |
|---|---|---|---|
| Bedrock | bedrock | 否 | AWS 凭证链自动检测 |
| Gemini | gemini | 是 | 支持图片/音频索引 |
| GitHub Copilot | github-copilot | 否 | 自动检测 |
| Local | local | 否 | GGUF 模型,约 0.6GB |
| Mistral | mistral | 是 | 自动检测 |
| Ollama | ollama | 否 | 本地,需显式配置 |
| OpenAI | openai | 是 | 自动检测,速度快 |
| Voyage | voyage | 是 | 自动检测 |
搜索质量优化:
- 时间衰减(Temporal Decay):旧笔记逐渐降权,默认半衰期 30 天,
MEMORY.md永不衰减 - MMR 多样性:减少重复结果,避免同一话题的多条笔记占据 Top 位置
多模态记忆:使用 Gemini Embedding 2 可索引图片和音频文件(查询仍为文本)
Session 记忆搜索(实验性):可选索引 Session 记录,通过 memorySearch.experimental.sessionMemory 开启
配置/使用
{
agents: {
defaults: {
memorySearch: {
provider: "openai",
query: {
hybrid: {
mmr: { enabled: true },
temporalDecay: { enabled: true }
}
}
}
}
}
}故障排查:
openclaw memory status # 检查索引和提供商
openclaw memory index --force # 重建索引相关页面
- memory — 记忆机制概述
- memory-builtin — 内置 SQLite 后端
- context — 记忆与上下文的关系