OpenClaw本地记忆搜索实战:Ollama向量模型配置完全指南

最近在优化OpenClaw助手的记忆搜索功能时,通过本地部署Ollama和nomic-embed-text向量模型,实现了语义搜索能力。本文记录从配置到验证的完整过程,供有类似需求的开发者参考。

一、为什么要用本地向量模型?

默认情况下,OpenClaw使用云端embedding服务,但对于重视数据隐私或希望降低成本的场景,本地部署是更好的选择。本地向量模型可以让敏感数据不出本地网络,同时减少API调用成本。

二、配置前的准备工作

  • Ollama环境:确保已安装Ollama并运行
  • 向量模型:下载nomic-embed-text模型(命令:ollama pull nomic-embed-text)
  • OpenClaw配置:在openclaw.json中配置memorySearch参数

三、关键配置步骤

参考官方配置文档后我们需要关注以下参数:

agents:
  defaults:
    memorySearch:
      enabled: true
      provider: "ollama"
      model: "nomic-embed-text"

重点说明:

  • enabled: true – 启用语义搜索
  • provider: "ollama" – 指定本地模型
  • model: "nomic-embed-text" – 向量模型名称

四、遇到的坑与解决方案

配置过程中我遇到了几个问题:

  • 配置不生效:使用config.set命令写入而非config.patch
  • Gateway缓存:修改配置后需要重启Gateway
  • 验证状态:使用openclaw memory status –deep确认
  • 最终成功的三步:

  • 1. 命令行写入:openclaw config set agents.defaults.memorySearch.enabled true
  • 2. 重启Gateway:openclaw gateway restart
  • 3. 验证:openclaw memory status –deep
  • 五、验证结果

    配置成功后,验证输出显示:

    Memory Search (main)
    Provider: ollama (requested: ollama)
    Model: nomic-embed-text
    Indexed: 88/91 files · 233 chunks
    Embeddings: ready

    88个memory文件已索引,233个文本块,语义搜索功能正常运行。

    希望这篇文章能帮助到需要配置本地记忆搜索的朋友。有问题欢迎评论区交流。

    发表回复

    您的邮箱地址不会被公开。 必填项已用 * 标注