Install
openclaw skills install yuyonghao-rag-retrieverRAG 2.0 检索系统,支持中文分词,混合向量与关键词搜索,智能文档分块与加权重排,自动生成 RAG 格式输出。
openclaw skills install yuyonghao-rag-retriever版本: 2.0.0
创建时间: 2026-03-17
更新时间: 2026-03-20
状态: ✅ RAG 2.0 完成
RAG 2.0 (Retrieval-Augmented Generation) 检索系统,为 OpenClaw 提供:
cd skills/rag-retriever
npm install
node src/rag-skill.js init my_docs
node src/rag-skill.js add ./readme.json '{"source":"github"}'
node src/rag-skill.js search "MCP protocol" 5
node src/rag-skill.js rag "什么是 RAG" 3
import { RAGRetriever } from './src/retriever.js';
const rag = new RAGRetriever({
dbPath: './data/lancedb',
dimensions: 384
});
// 初始化
await rag.initialize('my_docs');
// 添加文档
const result = await rag.addDocument(text, {
source: 'github',
timestamp: new Date().toISOString()
});
// 检索
const results = await rag.retrieve('MCP protocol', {
limit: 5
});
// RAG 格式化
const ragResult = await rag.retrieveForRAG('什么是 MCP', {
limit: 3
});
console.log(ragResult.context); // 格式化的上下文
// 统计
const stats = await rag.getStats();
const chunking = new ChunkingStrategy({
chunkSize: 500, // 每块字符数
overlap: 50, // 重叠字符数
separator: '\n' // 分隔符
});
const chunks = chunking.chunk(text, metadata);
const embedding = new SimpleTextEmbedding(384);
// 构建词汇表
embedding.buildVocabulary(texts);
// 生成向量
const vector = embedding.embed('人工智能');
const retriever = new RAGRetriever({
dbPath: './data/lancedb',
dimensions: 384
});
await retriever.initialize();
await retriever.addDocument(text, metadata);
const results = await retriever.retrieve(query);
{
dbPath: './data/lancedb', // LanceDB 路径
dimensions: 384, // 向量维度
chunking: {
chunkSize: 500, // 分块大小
overlap: 50, // 重叠大小
separator: '\n' // 分隔符
}
}
node test/retriever.test.js
✅ 分块策略
✅ 简单嵌入
✅ RAG 初始化
✅ 添加文档
⚠️ 检索功能 (需优化)
✅ 统计信息
| 指标 | 数值 |
|---|---|
| 分块速度 | ~1000 字符/ms |
| 嵌入速度 | ~100 文档/s |
| 检索延迟 | <50ms |
| 存储占用 | ~1KB/文档 |
简单嵌入 - 当前使用词频 TF 嵌入,效果有限
检索精度 - 简单词频嵌入精度有限
中文分词 - 使用 jieba 基础分词,未优化专业术语
最后更新:2026-03-17 17:00