openclaw-home-pc/openclaw/skills/vector-memory/SKILL.md
2026-03-24 04:00:48 +08:00

86 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: vector-memory
description: |
向量语义记忆系统 - 为 OpenClaw 添加语义搜索能力。当用户需要:
(1) 部署向量记忆系统
(2) 开启语义搜索功能
(3) 安装配置 Chroma + BGE-M3
(4) 搜索记忆时找不到内容
(5) 需要比关键词搜索更智能的记忆检索
---
# Vector Memory Skill
## 功能概述
为 OpenClaw 添加**向量语义搜索**能力,解决纯 Markdown 记忆的搜索痛点:
- 搜"股票"能找到"A股监控"、"铜陵有色"
- 支持同义词、近义词理解
- 记忆无限扩展,不受上下文窗口限制
## 技术架构
| 组件 | 选型 | 说明 |
|------|------|------|
| 向量模型 | BGE-M3 (硅基流动) | 中文优化好,向量免费 |
| 向量数据库 | Chroma | 轻量Python 原生 |
| 持久化 | SQLite | 并发安全 |
## 快速部署
### 1. 安装依赖
```bash
mkdir -p ~/openclaw-memory-vector
cd ~/openclaw-memory-vector
pip install chromadb openai sqlalchemy
```
### 2. 配置 API Key
```bash
export SILICONFLOW_API_KEY="sk-fpjdtxbxrhtekshircjhegstloxaodriekotjdyzzktyegcl"
```
### 3. 初始化系统
```python
import sys
sys.path.insert(0, '~/openclaw-memory-vector/scripts')
from vector_memory import VectorMemorySystem
vm = VectorMemorySystem(
persist_dir="./data/memory",
api_key="your_api_key"
)
```
## 核心脚本
### scripts/vector_memory.py
向量存储引擎,包含 `add_memory()``search()` 方法。详见 [references/core.md](references/core.md)。
### scripts/memory_tier_manager.py
记忆分层管理,自动将记忆分为 core/hot/cold 三层。
### scripts/openclaw_integration.py
OpenClaw 集成接口,提供 `get_memory_system()` 单例模式。
## 数据备份
备份 `~/openclaw-memory-vector/data/memory/` 整个目录:
- `memory.db` - SQLite 数据库(原始文本)
- `chroma/` - Chroma 向量索引
## 成本
- BGE-M3 向量:**免费无限**
- 硅基流动大模型2000万 Tokens/月
- **总成本:≈ ¥0**
## 触发词
- "部署向量记忆"
- "开启语义搜索"
- "向量备份"