ClawHub
SkillsPluginsOfficialDocsSupport
K
SkillsRag Retriever

Rag Retriever

yuyonghao-123@yuyonghao-123
RAG 2.0 检索系统,支持中文分词,混合向量与关键词搜索,智能文档分块与加权重排,自动生成 RAG 格式输出。
Install in OpenClaw
Security check
Clean
Version
0.1.1
Updated
May 11, 2026
License
MIT-0

Latest: v0.1.1

  • Updated package version to 0.1.1 in package.json.
  • No other functional or documentation changes in this release.
Knowledge
#rag

🦞 rag-retriever - RAG 2.0 检索系统

版本: 2.0.0
创建时间: 2026-03-17
更新时间: 2026-03-20
状态: ✅ RAG 2.0 完成


📋 简介

RAG 2.0 (Retrieval-Augmented Generation) 检索系统,为 OpenClaw 提供:

  • 📄 文档分块 - 智能文本分割策略(可配置 chunk size + overlap)
  • 🔢 向量嵌入 - OpenAI Embedding 或本地简单嵌入
  • 🔍 混合搜索 - 向量搜索 + BM25 关键词搜索(RRF 融合)
  • 🔄 加权重排 - 可配置向量/BM25 权重
  • 📖 来源引用 - 自动引用编号和来源追溯
  • 🤖 上下文增强 - 自动生成 RAG 增强提示词
  • 🇨🇳 中文分词 - 支持中英文混合搜索

🚀 快速开始

安装

bash
cd skills/rag-retriever
npm install

基本使用

1. 初始化

bash
node src/rag-skill.js init my_docs

2. 添加文档

bash
node src/rag-skill.js add ./readme.json '{"source":"github"}'

3. 检索

bash
node src/rag-skill.js search "MCP protocol" 5

4. RAG 查询

bash
node src/rag-skill.js rag "什么是 RAG" 3

✅ 已完成功能

  • 文档分块策略 (ChunkingStrategy)
  • 简单文本嵌入 (SimpleTextEmbedding) - 词频 TF 归一化
  • LanceDB 向量存储
  • 相似检索(向量相似度)
  • RAG 格式化输出
  • CLI 工具
  • 基础测试
  • 中文分词支持 (@node-rs/jieba) 🆕

📅 开发计划

Week 1 (03-17~03-23)

  • Day 1: 原型验证 ✅
  • Day 1: 测试文档完成 ✅
  • Day 1: 检索功能测试 ✅ (2026-03-17 15:21)
  • Day 2: 中文分词支持
  • Day 3-7: 优化 + 文档

Week 2 (03-24~03-30)

  • 集成真正嵌入模型 (OpenAI/Cohere)
  • 混合检索 (关键词 + 向量)
  • Reranker 重排序
  • 多集合管理

🔧 API 使用

JavaScript API

javascript
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();

🎯 核心组件

1. ChunkingStrategy (分块策略)

javascript
const chunking = new ChunkingStrategy({
  chunkSize: 500,    // 每块字符数
  overlap: 50,       // 重叠字符数
  separator: '\n'    // 分隔符
});

const chunks = chunking.chunk(text, metadata);

2. SimpleTextEmbedding (简单嵌入)

javascript
const embedding = new SimpleTextEmbedding(384);

// 构建词汇表
embedding.buildVocabulary(texts);

// 生成向量
const vector = embedding.embed('人工智能');

3. RAGRetriever (检索器)

javascript
const retriever = new RAGRetriever({
  dbPath: './data/lancedb',
  dimensions: 384
});

await retriever.initialize();
await retriever.addDocument(text, metadata);
const results = await retriever.retrieve(query);

📚 配置选项

RAGRetriever 选项

javascript
{
  dbPath: './data/lancedb',     // LanceDB 路径
  dimensions: 384,              // 向量维度
  chunking: {
    chunkSize: 500,             // 分块大小
    overlap: 50,                // 重叠大小
    separator: '\n'             // 分隔符
  }
}

🧪 测试

运行测试

bash
node test/retriever.test.js

测试结果

text
✅ 分块策略
✅ 简单嵌入
✅ RAG 初始化
✅ 添加文档
⚠️ 检索功能 (需优化)
✅ 统计信息

🔗 参考资料

  • LanceDB 文档
  • RAG 最佳实践
  • 嵌入模型对比 2026

📊 性能指标

指标数值
分块速度~1000 字符/ms
嵌入速度~100 文档/s
检索延迟<50ms
存储占用~1KB/文档

⚠️ 已知限制

  1. 简单嵌入 - 当前使用词频 TF 嵌入,效果有限

    • 改进: 集成 OpenAI/Cohere embeddings
  2. 检索精度 - 简单词频嵌入精度有限

    • 改进: 使用真正的语义嵌入模型
  3. 中文分词 - 使用 jieba 基础分词,未优化专业术语

    • 改进: 添加用户词典支持

最后更新:2026-03-17 17:00

Related skills

More in Knowledge
ClawHub

Skills and plugins for OpenClaw agents. Part of the wider OpenClaw ecosystem.

Explore docs

SkillsPluginsOfficialAudits

Publish SkillPublish PluginCreate org

OverviewOpenClawDocsBlog

SupportGitHubDiscord

Built alongside the OpenClaw ecosystem

LobsterCrabboxClickClackCrabfleetOctopoolClawSweeperagent-skillsdiscrawlgitcrawlslacrawlnotcrawltelecrawlgraincrawlcrawlkitcrawlbaracpxmcporterTachikomaclawpatchclawbenchPeekaboocookbookplugin-inspectorwacrawlcrabpotAll projectsLobsterCrabboxClickClackCrabfleetOctopoolClawSweeperagent-skillsdiscrawlgitcrawlslacrawlnotcrawltelecrawlgraincrawlcrawlkitcrawlbaracpxmcporterTachikomaclawpatchclawbenchPeekaboocookbookplugin-inspectorwacrawlcrabpotAll projects

© 2026 OpenClaw Foundation

Privacy policy·Status·Deployed on Vercel·Powered by Convex

....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals