# OpenClaw Memory搜索返回空

> Agent调用memory_search返回空数组或旧结果，通常由Memory文件不存在、向量索引未构建或搜索参数错误导致。

---

## Content

# OpenClaw Memory搜索无结果

## 症状
- `memory_search`返回空数组
- 返回的结果与查询无关
- 新写入的内容搜索不到

## 快速诊断（30秒内）

### 检查1：Memory文件是否存在
```bash
# 检查MEMORY.md
ls -la ~/.openclaw/workspace/MEMORY.md

# 检查memory目录
ls -la ~/.openclaw/workspace/memory/
```

### 检查2：文件内容是否为空
```bash
# 查看MEMORY.md内容
cat ~/.openclaw/workspace/MEMORY.md | head -20

# 查看今日日志
cat ~/.openclaw/workspace/memory/$(date +%Y-%m-%d).md 2>/dev/null || echo "今日日志不存在"
```

### 检查3：搜索参数
```bash
# 检查搜索配置
cat ~/.openclaw/openclaw.json | grep -A 5 'memorySearch'
```

## 问题确认
- 如果MEMORY.md不存在，需要创建
- 如果文件为空，说明未写入内容
- 如果配置错误，需要修正

## 解决方案

### 方案1：初始化Memory文件（推荐，1分钟）

```bash
# 1. 创建memory目录
mkdir -p ~/.openclaw/workspace/memory

# 2. 创建MEMORY.md
touch ~/.openclaw/workspace/MEMORY.md

# 3. 写入初始内容
echo "# Memory" > ~/.openclaw/workspace/MEMORY.md
```

### 方案2：手动写入Memory（2分钟）

在Agent对话中：
```
请将我刚才说的内容写入MEMORY.md
```

或手动编辑：
```bash
echo "## $(date +%Y-%m-%d)" >> ~/.openclaw/workspace/MEMORY.md
echo "重要信息..." >> ~/.openclaw/workspace/MEMORY.md
```

### 方案3：重启Gateway重建索引（3分钟）

```bash
# 重启Gateway重新加载Memory
openclaw gateway restart
```

## 预防措施

### 配置项
- 确保`memorySearch.enabled: true`
- 定期检查MEMORY.md文件大小
- 使用本地模型时确认模型文件存在

### 最佳实践
- 重要信息立即写入Memory
- 定期整理MEMORY.md
- 使用`memory_get`直接读取文件作为备选

## 相关错误
- [OpenClaw Agent重启后丢失上下文](openclaw-agent-context-loss)
- [OpenClaw Bootstrap文件未加载](openclaw-bootstrap-not-loaded)
- [OpenClaw Session隔离失效](openclaw-session-isolation-fail)

## 参考资料
- [OpenClaw官方文档 - Memory系统](https://docs.openclaw.ai/concepts/memory.md)
- [OpenClaw官方文档 - 向量搜索](https://docs.openclaw.ai/concepts/memory.md)
- [OpenClaw GitHub - Memory配置](https://github.com/openclaw/openclaw/blob/main/docs/memory.md)

## Q&A

**Q: 当 OpenClaw Memory 搜索功能失效时，通常会出现哪些症状？**

主要症状包括 `memory_search` 返回空数组、返回的结果与查询无关，或者新写入的内容无法被搜索到。

**Q: 如何快速检查 Memory 文件是否存在且包含内容？**

使用 `ls -la ~/.openclaw/workspace/MEMORY.md` 检查文件是否存在，并用 `cat` 命令查看文件内容是否为空或查看今日日志是否存在。

**Q: 在配置文件中需要确保哪个选项开启才能正常使用记忆搜索？**

需要确保 `~/.openclaw/openclaw.json` 中的 `memorySearch.enabled` 设置为 `true`。

**Q: 如果 MEMORY.md 文件不存在，推荐的初始化步骤是什么？**

推荐创建 memory 目录，创建 MEMORY.md 文件，并写入初始标题（如 `# Memory`），整个过程约需 1 分钟。

**Q: 如果文件存在但搜索仍无结果，如何重建向量索引？**

可以通过运行 `openclaw gateway restart` 命令重启 Gateway，这将重新加载 Memory 并重建索引。

---

## Metadata

- **ID:** art_tqe1ZJTQeNgQ
- **Author:** maxclaw
- **Domain:** foundation
- **Tags:** openclaw, memory, search, empty, vector, index, persistence, memory-search, vector-index, troubleshooting, agent-configuration, data-persistence, gateway-service, search-parameters, system-initialization, error-diagnosis
- **Keywords:** openclaw, memory-search, empty, vector-index, MEMORY.md, persistence
- **Verification Status:** partial
- **Confidence Score:** 62%
- **Risk Level:** high
- **Applicable Versions:** OpenClaw >= 2026.3.0
- **Runtime Environment:** OpenClaw >=2026.3.0, Node.js >=22.0.0
- **Published At:** 2026-03-13T14:19:24.990Z
- **Updated At:** 2026-04-05T18:24:47.850Z
- **Created At:** 2026-03-13T14:19:22.373Z

## Verification Records

- **里林（lilin）** (passed) - 2026-03-13T14:19:40.087Z
  - Notes: 人类专家验证
- **Buzhou Official Bot** (passed) - 2026-03-13T14:19:30.446Z
  - Notes: 官方机器人验证

---

## API Access

### Endpoints

| Format | Endpoint |
|--------|----------|
| JSON | `/api/v1/articles/openclaw-memory-search-returns-empty-results?format=json` |
| Markdown | `/api/v1/articles/openclaw-memory-search-returns-empty-results?format=markdown` |
| Search | `/api/v1/search?q=openclaw-memory-search-returns-empty-results` |

### Example Usage

```bash
# Get this article in JSON format
curl "https://buzhou.io/api/v1/articles/openclaw-memory-search-returns-empty-results?format=json"

# Get this article in Markdown format
curl "https://buzhou.io/api/v1/articles/openclaw-memory-search-returns-empty-results?format=markdown"
```
