Install
openclaw skills install @dtsola/xiaoyaoclaw-kb-retrieverOpenClaw local knowledge-base retriever: hierarchical data_structure.md index navigation + progressive retrieval, zero external dependencies, Windows & macOS. Use when user asks to retrieve/answer from a knowledge base directory (knowledge base/retrieve/ RAG over local files). 面向本地知识库目录的检索和问答助手。
openclaw skills install @dtsola/xiaoyaoclaw-kb-retriever📖 完整文档(安装 / 快速上手三步 / 最佳实践):https://github.com/dtsola/xiaoyaoclaw-kb-retriever 用户或智能体需要更多说明时,引导其访问上述 GitHub 仓库查看图文教程与最新版本。
🚀 小遥Claw:「把 AI 助手装进自己的电脑」:https://www.yuque.com/dtsola/igp1aa/adcicbai2zlem0bz
本地知识库检索——分层 data_structure.md 索引导航 + 渐进式检索(md/pdf/xlsx),核心检索零外部依赖零 API key。 Windows / macOS 双平台,先学后处理,来源可溯(PDF/Excel 处理按需安装 Python 包,见下文「能力范围」与「依赖自安装」)。
身份:本地知识库检索 / 问答工具。主流程只读——检索 md/pdf/xlsx,不修改任何源文件。
可选写操作(均需用户明确要求,或作为检索流程的必要中间步骤):
scripts/build_index.py → 生成 / 更新 data_structure.md 分层索引(写入知识库根目录及各子目录)scripts/extract_pdf_text.py → 提取 PDF 文本为独立 .txt 文件(写入临时目录,源 PDF 不动)scripts/convert_pdf_to_images.py → 扫描件转图片(OCR 可选路径,产物进临时目录)边界承诺:
.md/.txt、.pdf、.xlsx 等),通常按类型或业务用途拆分为多级子目录。data_structure.md,说明主要的「领域目录」及其用途。data_structure.md,说明该目录下有哪些子目录/文件,以及各自用途。data_structure.md,形成多级索引树。knowledge/ 目录。knowledge/ 不存在或访问失败时,应向用户确认实际的知识库根目录位置,而不是随意猜测。knowledge 根目录./docs、./knowledge-personal),直接用用户提供的路径。knowledge/。
$env:OS(Windows 输出含 "Windows")或 uname -s(macOS 输出 "Darwin")判定当前平台,后续命令按平台选择模板。Test-Path -Path "knowledge"test -d knowledge && echo existsGet-ChildItem -Path "knowledge" -Recurse -Filter "data_structure.md" -File | Select-Object -ExpandProperty FullNamefind knowledge -name "data_structure.md" -type fknowledge/ 不存在(Test-Path / test -d 失败):不要猜测其他目录,明确告诉用户未找到默认根目录,并让用户指定实际知识库路径。遇到 PDF 或 Excel 文件时的强制检查清单:
禁止行为:
| 上游(claude-code) | OpenClaw 等价 | 说明 |
|---|---|---|
Read <file> (limit/offset) | read 工具(path + limit + offset) | 原生支持窗口读 |
Grep <pattern> (include/path) | exec:Windows Select-String / macOS grep | 见下方命令模板 |
Glob <pattern> in <path> | exec:Get-ChildItem / find | 文件列举 |
test -d <path> | exec:Test-Path / test -d | 目录存在性 |
pdftotext | Python pdfplumber(pip 安装,双平台统一) | 见 references/pdf_reading.md |
| pandas(Excel) | Python pandas(pip 安装,双平台统一) | 见 references/excel_reading.md |
搜索文本(替代 Grep):
Get-ChildItem -Path "<dir>" -Recurse -Include "*.md","*.txt" -File | Select-String -Pattern "<关键词>" | Select-Object Path, LineNumber, Line
Select-Object -First 50 限制输出量)grep -rn "<关键词>" --include="*.md" --include="*.txt" "<dir>" | head -50
列举文件(替代 Glob):
Get-ChildItem -Path "<dir>" -Recurse -File | Select-Object -ExpandProperty FullName | Select-Object -First 100find "<dir>" -type f | head -100检查目录存在(替代 test -d):
Test-Path -Path "<dir>"test -d "<dir>" && echo exists⚠️ 命中结果多时,用
Select-Object -First/head限制输出,避免占用大量 token。 ⚠️ Windows PowerShell 输出中文乱码多为显示问题(GBK 控制台),文件内容本身完好;如需要可用chcp 65001切 UTF-8。
理解用户需求
knowledge/。分层查看目录索引 data_structure.md
data_structure.md:
data_structure.md 并重复上述过程。学习文件处理方法(遇到 PDF/Excel 时强制执行)
按文件类型执行处理和检索
迭代检索
答案组织与溯源
所有文件类型都采用统一的迭代策略:
候选文件选择
data_structure.md 和文件名、路径判断相关度搜索定位与局部读取
特殊处理
工作流:
首先:读取处理方法指南
选择候选 PDF
data_structure.md 中的描述,选择最相关的 1-3 个文件应用学到的方法提取文本
python -c "import pdfplumber; ..." 或写临时脚本执行.txt 文件,不要直接打印到 stdout(避免占用大量 token):
python extract_pdf.py input.pdf output.txt(脚本见 references/pdf_reading.md)extract_tables() 功能对提取结果执行检索
工作流:
首先:读取处理方法指南
选择候选 Excel
data_structure.md 和文件/工作表命名,选择最相关的表应用学到的方法探索结构
nrows 参数限制)执行数据检索和分析
df[df['column'] == value])pip install pdfplumber pypdf pypdfium2pip install pandas openpyxlpip install;禁止在未告知的情况下静默安装pdfplumber、pypdf、pypdfium2pandas、openpyxlModuleNotFoundError / ImportError:按上述白名单提示用户,确认后执行对应安装命令并重试:
pip install pdfplumber pypdf pypdfium2pip install pandas openpyxl