nigo81/nigo-skills

local-rag

本地向量知识库,支持按项目管理文档(docx/doc/pdf/md),语义检索。默认用硅基流动免费 API,零模型安装即可使用。支持多项目隔离、中文制度文档专用切片、Embedding+Rerank 两阶段检索。触发词:知识库、向量检索、RAG、制度检索、文档入库、语义搜索、local rag、搜制度、查条款、文档检索、从文档中搜、语义匹配。即使用户只是说"帮我从这些文件里找到关于XX的规定"或"对比两份制度的差异",也应使用本 skill。

Ver código fuente

Cómo usar

  1. Copia el comando y revisa el paquete antes de instalarlo en tu entorno de agente.
  2. Consulta las herramientas, credenciales y entornos necesarios en el documento original.
  3. Describe las entradas y el resultado deseado; contrasta la salida con las fuentes.
npx skills add https://github.com/nigo81/nigo-skills --skill local-rag

Antes de empezar

  • La instalación no incluye suscripción al modelo, cuota API ni permisos sobre tus archivos.
  • Las estrellas e instalaciones reflejan actividad, no una prueba independiente de calidad o seguridad.
Documento original del Skill

Contenido del repositorio de origen con títulos, ejemplos, código, tablas, enlaces e imágenes preservados.

本地 RAG 知识库

轻量级本地向量知识库,支持按项目管理文档,语义检索制度条款。

作者: nigo(公众号「逆行的狗」) 面向财务/审计从业者的 AI 效率工具,有任何问题可关注公众号反馈。

技术栈

  • 切片:Chonkie RecursiveChunker + OverlapRefinery(15% overlap)
  • 向量库:ChromaDB(persistent,多项目隔离)
  • 默认 Embedding:硅基流动 BAAI/bge-m3(免费,1024维,8192 tokens)
  • 默认 Reranker:硅基流动 BAAI/bge-reranker-v2-m3(免费)
  • 文档解析:textutil(macOS .doc)+ python-docx(.docx)+ PyMuPDF(.pdf)+ MinerU(扫描件)
  • 可选本地模式:Ollama embedding + Ollama reranker(完全离线)

使用方式

CLI(推荐)

bin/local-rag 是独立的 CLI 入口脚本,自动定位 skill 目录,可在任意位置运行。

bash
# 设置快捷方式(一次性,加到 PATH)
export PATH="$HOME/.claude/skills/local-rag/bin:$PATH"
# 或创建别名:alias local-rag="$HOME/.claude/skills/local-rag/bin/local-rag"

# 首次配置(交互式向导)
local-rag setup

# 项目管理
local-rag create my-project
local-rag delete my-project
local-rag list

# 入库
local-rag ingest my-project /path/to/docs
local-rag ingest my-project /path/to/file.docx --label "财务制度"

# 检索
local-rag search my-project "消防安全管理"
local-rag search my-project "消防安全管理" --rerank --top-k 20

# 工具
local-rag chunk-test /path/to/file.doc
local-rag info

也可以直接用完整路径:~/.claude/skills/local-rag/bin/local-rag

Python API

python
import sys, os
# 添加 skill 目录(根据实际安装位置调整)
sys.path.insert(0, os.path.expanduser("~/.claude/skills/local-rag"))
from src.pipeline import Pipeline

pipeline = Pipeline()

# 项目管理
pipeline.create_project("my-project")
pipeline.list_projects()
pipeline.delete_project("my-project")

# 入库(文件或文件夹)
result = pipeline.ingest("my-project", "/path/to/docs")

# 检索
results = pipeline.search("my-project", "消防安全管理", top_k=15)

# 检索 + Rerank
results = pipeline.search_with_rerank("my-project", "消防安全管理", final_k=10)

# 测试切片
result = pipeline.chunk_test("/path/to/file.doc")

MCP Server

bash
pip install fastmcp
python3 ~/.claude/skills/local-rag/mcp_server.py

6 个 tool:create_project / delete_project / list_projects / ingest / search / rerank_search

Embedding Provider

Provider适用场景需要什么
siliconflow(默认)大多数场景,免费额度无限量API Key
ollama离线/内网环境Ollama + 模型(~2.5GB)
openai已有 OpenAI 账号API Key
⚠️ API Key 安全: 不要把 API Key 直接写在 config.yaml 里!请设置环境变量 SILICONFLOW_API_KEY,config.yaml 中用 ${SILICONFLOW_API_KEY} 引用。

环境变量 SILICONFLOW_API_KEY 设置硅基流动 Key 即可使用默认配置。如果没有 Key,请先到 硅基流动 免费注册并创建 API Key。

API Key 查找顺序

当用户没有设置 API Key 时,按以下顺序查找,不要 grep 搜索:

  1. 环境变量 SILICONFLOW_API_KEY(echo $SILICONFLOW_API_KEY / Windows: echo %SILICONFLOW_API_KEY%)
  2. 配置文件(按平台自动定位):
  • macOS: ~/Library/Application Support/local-rag/config.yaml
  • Windows: %LOCALAPPDATA%\local-rag\config.yaml
  • Linux: ~/.local/share/local-rag/config.yaml
  1. 如果都没有 → 直接引导用户设置,不要到处搜索:
   请先设置硅基流动 API Key(免费,注册地址:https://cloud.siliconflow.cn):
   
   macOS/Linux:
   echo 'export SILICONFLOW_API_KEY="sk-xxx"' >> ~/.zshrc && source ~/.zshrc
   
   Windows (PowerShell):
   [Environment]::SetEnvironmentVariable("SILICONFLOW_API_KEY", "sk-xxx", "User")
   
   或运行:local-rag setup

项目管理

  • 每个项目 = 一个 ChromaDB collection
  • 项目名只能用英文、数字、点、横线(ChromaDB 限制)
  • 不同项目的文档完全隔离
  • 删除项目会删除所有文档和向量

切片策略

中文制度文档(默认)

Chonkie RecursiveChunker 三级递归:

  1. Level 1: 按"第X章"分章节
  2. Level 2: 按双换行分大段落
  3. Level 3: 按单换行分条款/段落
  4. 目标 ~800 字符/chunk,最小 50 字符,15% overlap

通用 Markdown(可选)

  • 按标题层级(#、##、###)分割
  • config.yaml 中设 chunking.strategy: generic

配置

配置文件路径(跨平台自动选择):

  • macOS: ~/Library/Application Support/local-rag/config.yaml
  • Windows: %LOCALAPPDATA%\local-rag\config.yaml
  • Linux: ~/.local/share/local-rag/config.yaml

环境变量优先:SILICONFLOW_API_KEY / OPENAI_API_KEY / RAG_DATA_DIR / RAG_EMBEDDING_MODEL

数据存储

默认路径(跨平台自动选择):

  • macOS: ~/Library/Application Support/local-rag/
  • Windows: %LOCALAPPDATA%\local-rag\
  • Linux: ~/.local/share/local-rag/

可通过环境变量 RAG_DATA_DIR 或 config.yaml 的 storage.data_dir 修改。

前置条件

默认模式(零模型安装)

  • Python 3.10+
  • pip install -r requirements.txt
  • 硅基流动 API Key(注册:https://cloud.siliconflow.cn)

本地模式(可选)

  • Ollama 运行中,已拉取 qwen3-embedding:4b
  • 无需额外 Python 包

高级离线(极少数需求)

  • pip install torch transformers
  • bge-reranker-v2-m3 cross-encoder(~2.3GB)

Key Rules

  • 首次使用必须先运行 `local-rag setup` 或手动设置 SILICONFLOW_API_KEY 环境变量
  • 执行任何 CLI 命令前,先用 `local-rag info` 检查配置是否就绪
  • API Key 只能由用户提供,禁止 grep/搜索文件系统找 key。如果 local-rag info 报错"API Key 未设置",直接引导用户(见上方"API Key 查找顺序"),不要到处 grep
  • 不要在没有 API key 的情况下继续执行 ingest/search 等命令,必定失败
  • 首次使用还需安装依赖:pip install -r ~/.claude/skills/local-rag/requirements.txt,如果命令报 ImportError,引导用户安装
  • v3 默认用硅基流动 API,不需要 GPU 或 Ollama
  • 推荐用 searchwithrerank(top-20 检索 + rerank top-10),给 LLM 足够候选
  • LLM 必须阅读候选 chunk 的完整内容,不能只看前几行
  • 由 LLM 从候选文本中做深度语义匹配,精确定位条款
  • LLM 判断的关键:不是选"文字最相似的",而是选"管理同一件事的"
  • 向量检索无法判断"无对标",需要 LLM 二次判断
  • .doc 文件优先用 macOS textutil 转换,非 macOS 用 python-docx 回退
  • 扫描版 PDF(每页文字 < 50 字符)自动调 MinerU 处理
  • 环境变量 RAG_EMBEDDING_MODEL 可切换模型

踩坑记录

  1. ChromaDB 1.3.5 list_collections() 返回 Collection 对象,需要 .name
  2. Chonkie RecursiveLevel 不能同时设 delimiters 和 whitespace
  3. Ollama reranker(chat API)输出乱码,v3 改用 embedding-based cosine similarity
  4. Embedding 余弦相似度做 rerank 效果有限,但比没有好;cross-encoder 更精准
  5. Ollama /api/embed 返回 {"embeddings": [[...]]} 不是 {"embedding": [...]}
  6. 硅基流动 reranker 是 Cohere 风格 API,不是 OpenAI 格式

Relacionados por tarea

del mismo repositorio

Más Skills

Todos los Skills
nigo81
Comunidad

chen-yiwei-perspective

陈奕蔚(会计视野论坛版主,中审众环会计师事务所合伙人)的专业咨询思维框架。基于2003-2026年24年、约3000万字答疑文章提炼,涵盖5个核心心智模型、10条决策启发式、完整的表达DNA和回答工作流。用于会计准则实务解读、审计问题咨询、财务处理判断。触发词:陈版主、陈奕蔚、会计准则咨询、审计实务、合并报表、收入确认、权益性交易、会计处理、企业会计准则、CAS 14、CAS 21、CAS 33。

instalaciones
1
GitHub Stars
135
Actualizado
23 ago
nigo81
Comunidad

chenyiwei-bbs

陈版主实务问答检索 Skill。当用户想查询"陈版主"、"陈奕蔚"、"审计问答"、"视野论坛"、"会计准则"、"审计实务"、"CPA问答"、"注册会计师"、"会计处理"、"审计问题"、"收入确认"、"合并报表"、"商誉减值"等任何审计/会计实务问答时使用。Skill 会直接 curl 公开 REST API 拉取数据并整理成中文 markdown,不需要 API Key 或 MCP server。不要 undertrigger——用户问审计/会计实务问题而你不调本 Skill 就是把过时的训练数据当作最新实务解答,对用户有害。

instalaciones
1
GitHub Stars
135
Actualizado
23 ago
nigo81
Comunidad

opencode-session-visualizer

将 OpenCode 会话导出为可视化的 HTML 网页,复刻官方 share 页面的暗色主题样式。 从本地 SQLite 数据库提取完整对话数据(包括上下文压缩前的早期消息), 生成的 HTML 包含 Markdown 渲染、代码高亮、工具调用折叠卡片(含完整 input/output)、 思考过程折叠、左侧对话导航边栏、删除/截断对话功能。 触发词:可视化会话、导出会话、会话分享、session visualizer、share session、 导出完整对话、查看压缩前对话、生成会话网页、会话 HTML、conversation visualizer、 opencode 会话导出、完整对话记录、删除对话、清理会话。 当用户提到任何与会话导出、可视化、分享、完整记录查看相关的需求时都应使用此 skill。 即使用户只说"帮我看下之前那个对话"或"导出这个会话"也应触发。

instalaciones
1
GitHub Stars
135
Actualizado
23 ago
nigo81
Comunidad

related-party-identification

基于工商数据自动识别"隐形关联方"的审计核查工具。读取被审计单位及其客户、供应商的工商完整维度(52个Excel), 自动比对地址/电话/邮箱/网址/法定代表人/董监高/股权穿透/客商异常画像/无形资产共用/担保链/历史关联痕迹等八大维度, 输出多sheet Excel核查报告(汇总判断sheet + 各维度证据sheet),揪出未披露的关联方关系。 当用户提到 关联方、关联方核查、关联方识别、隐形关联方、隐性关联方、未披露关联方、关联交易非关联化、 关联关系、客户供应商关联关系、客户是不是关联方、供应商有没有猫腻、股权穿透、实际控制人核查、 关联方尽调、审计关联方、related party、关联方核查底稿 时使用。 即使用户只说"查一下这几家公司之间有没有关联""帮我看下这批客户供应商的工商数据""这公司是不是空壳" "审计要核查关联方"也应触发。配合 cicpa-company-query skill 取数,规则集对齐证监会/财政部近年处罚案例。

instalaciones
1
GitHub Stars
135
Actualizado
23 ago