Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

RAG Assistant

本地知识库问答智能体 — LLM 驱动的组合式语义检索与多库路由。 版本:2.0.0b1 | 作者:wUwproject | 许可证:Apache 2.0

⚠️ 从 1.x 升级到 2.x 必须重建 HNSW 索引

2.x 将向量搜索引擎从 ChromaDB 内置 HNSW 替换为独立 hnswlib 索引,以解决 ChromaDB Rust 后端在 Windows 上的 HNSW 持久化 bug。

升级后首次搜索会自动触发懒重建(每个 KB 约 1-2 分钟),也可手动点击 🔨 HNSW 按钮,或通过 POST /api/kb/rebuild-hnsw API 触发。

  • 重建不可跳过:ChromaDB HNSW 和 hnswlib 索引格式不兼容
  • 旧索引自动清理:重建后 ChromaDB 的 HNSW 段文件会自动废弃
  • 数据不丢失:文档文本和 metadata 全部保留,仅重新计算向量索引

基于 local-rag-builder 技能构建的独立 RAG 智能体,支持 LM Studio / Ollama 双后端。


快速开始

# 1. 安装依赖
pip install -r requirements.txt

# 2. 启动(需要 LM Studio 或 Ollama 运行中)
python main.py

# 3. 打开浏览器访问 http://localhost:8765

# 同时启动外部 API(可选)
python main.py --api-port 8767

核心特性

特性 说明
组合式查询 LLM 自动做 entities/attrs 分词,穷举组合后独立检索,SM3 去重合并,LLM 综合回答
多库路由 硬编码关键词 + 嵌入模型×KB签名语义回退两级路由
三层推理流水线 检索 → Reranker 精排 → NLI 三向分类(entailment/neutral/contradiction)
自修正决策 LLM 格式错误时自动反馈重试(最多 5 次),重试耗尽时清上下文重来
功能运行态切换 路由/重排序/NLI/搜索开关无需改配置重启
联网搜索 5 种后端:DuckDuckGo/Tavily/Google/Bing/自定义

文件结构

rag-assistant/
├── main.py                           # 入口(CLI/Web/Batch/External API 四模式)
├── setup.bat                         # Windows 一键启动
├── requirements.txt                  # 依赖清单
├── CHANGELOG.md                      # 版本更新日志
│
├── rag_assistant/                    # 智能体核心
│   ├── agent.py                      # LLM 决策循环
│   ├── web_ui.py                     # Web 界面(port 8765)
│   ├── external_api.py               # 外部接入 API(port 8767)← 新增
│   ├── llm_client.py                 # LLM 统一客户端(LM Studio / Ollama)
│   ├── rag_wrapper.py                # 技能封装层
│   ├── search.py                     # 联网搜索(5 种后端)
│   ├── memory.py                     # 三层记忆系统
│   └── _fix_rag.py                   # 破损数据修复工具
│
├── engine/                           # 技能引擎(独立副本)
│   ├── rag_core.py                   # 检索/路由/rerank/NLI 编排
│   ├── router.py                     # 两级路由 + KB 签名生成
│   ├── reranker.py                   # 重排序(model/rule/hybrid)
│   ├── nli_classifier.py             # NLI 三向分类器
│   ├── knowledge_base_manager.py     # KB CRUD + 备份/恢复/移动
│   ├── text_splitter.py              # 5 种切分策略 + 5 种守卫
│   ├── prompt_manager.py             # 提示词管理(模板/插槽/预设)
│   └── ...
│
├── vendor/                           # 内嵌第三方库(bs4/pypdf/markdownify)
└── data/                             # 运行时数据
    ├── config/rag_config.json        # 全量配置
    ├── kb/                           # ChromaDB 知识库
    ├── models/                       # 嵌入/reranker/NLI 模型
    ├── sessions/                     # 会话历史
    ├── memory/                       # 压缩摘要/知识缺口/习惯
    └── prompts/                      # 自定义模板/预设

启动模式

python main.py                              # Web UI(port 8765)
python main.py --api-port 8767              # Web UI + 外部 API
python main.py --no-web --api-port 8767     # 仅外部 API
python main.py --no-web                     # CLI 交互模式
python main.py --batch --input q.json --output r.json   # 批量处理
cat queries.jsonl | python main.py --jsonl              # 管道模式
python main.py migrate                      # 从 local-rag-builder 迁移

架构概览

用户输入
  → [LLM 决策层]
       ├─ 闲聊 → 直接回答
       └─ 知识库查询 → entities/attrs 分词
           → [组合展开器] 穷举 entities × attrs
           → [多切片检索] 每片独立走完整 RAG 流程
              1. 路由(嵌入模型 × KB签名/关键词)
              2. 检索(Chroma 相似度)
              3. (可选) 重排序(reranker)
              4. (可选) NLI 三向分类(entailment/neutral/contradiction)
           → [SM3 去重合并](保留 NLI 标签)
           → [LLM 综合回答](带 NLI 标签辅助判断)

文档导航

文档 用途
PROTOCOL.md Web UI API 契约(port 8765)— 聊天/配置/文件交互
EXTERNAL_API.md 外部接入 API 契约(port 8767)— 功能开关/模型调用/KB管理/提示词/切分
rag_assistant/engine/rag-assistant-architecture.md 内部架构设计文档
CHANGELOG.md 完整版本更新日志
llms.txt AI 可读项目描述(llmstxt.org 规范)

三端口架构

端口 模块 定位 文档
8765 web_ui.py 人机交互(聊天+配置面板) PROTOCOL.md
8766 rag_web_ui.py(subprocess) KB/模型配置 GUI 架构文档
8767 external_api.py 系统间集成(组件级调用) EXTERNAL_API.md

技术栈

  • LLM 后端:LM Studio(OpenAI 兼容) / Ollama
  • 向量存储:ChromaDB(langchain-chroma)
  • 嵌入模型:BCE-embedding-base_v1(本地加载)
  • Reranker:BAAI/bge-reranker-base(本地加载)
  • NLI 分类:MoritzLaurer/mDeBERTa-v3-base-mnli-xnli(本地加载)
  • 文本切分:5 种策略 + GuardStack 守卫栈
  • 哈希去重:SM3 国密哈希

依赖

  • LM Studio 或 Ollama(本地 LLM 推理服务)
  • Python 3.9+
  • 嵌入模型(推荐 maidalun1020/bce-embedding-base_v1)
  • ChromaDB(向量存储,自动安装)

协议

Apache 2.0


更新说明

[2.1.0b2] - 2026-07-24

新增

  • web_llm 插件多配置(profile)系统:插件配置从单组改为多条目管理。Tkinter 配置界面支持添加/编辑/删除多个 API 配置条目,每条包含名称、服务商、API 地址、Key、模型名、温度、Top P、最大 Token。数据存为 {"profiles": [...]},兼容旧格式自动包装
  • LLMClient 按模型名匹配配置_get_web_llm_config(model_name) 查找对应 profile 的 base_url/api_key/参数,list_models() 返回所有已配置模型名,Web UI 模型下拉自动显示全部可选模型
  • AI 插件生成器web_ui.py 插件 Tab):左侧新增 AI 对话面板���支持自然语言描述需求 → LLM 二阶段评估可行性 → 确认后生成完整插件代码
    • 评估阶段:LLM 根据 RAG Assistant 上下文(智能体生命周期、正面示例、硬拒绝清单)判断可行性,返回 plugin_name/type/input_fields/依赖等信息
    • 生成阶段:LLM 生成 plugin.json + plugin_xxx.py → 6 阶段校验管道(JSON 合法性 → Python 语法 ast.parse → 目录规划 builtin/user → tempfile 原子写入 → SM3 签名 → discover_and_register 刷新注册)
    • LLM 调用方式:temperature=0.3(确定性代码生成),其余参数(model/max_tokens/timeout)走主配置 llm_config.json
    • 新增端点 POST /api/plugins/generate,新增 _PLUGIN_SPEC 规范常量(RAG Assistant 上下文 + PluginBase 接口 + 字段池 + 硬拒绝规则 + 约束)

修复

  • setup.bat HNSW 提示顺序:将 estimate_rebuild_time.py(模型加载测速)从版本检测提示后移到 Y 确认后的 DO_REBUILD 内,避免未确认就加载模型
  • setup.bat 加提示从 1.x 升级到此版本需要重建全部知识库的 HNSW 索引。 末尾追加 初次使用的非升级用户建议直接跳过(N)。(单行 echo,不引入新行,避免 chcp 65001 多行中文 CRLF 解析 bug)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rag_assistant_ldxs-2.1.0b2-py3-none-any.whl (205.4 kB view details)

Uploaded Python 3

File details

Details for the file rag_assistant_ldxs-2.1.0b2-py3-none-any.whl.

File metadata

File hashes

Hashes for rag_assistant_ldxs-2.1.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 82b0de261c9a359084d9ea839158271c49e1a389d41f888d5f51154281c93195
MD5 a06e21f8395f47c4e18777749b026501
BLAKE2b-256 a9061a67458528c860843cffdeeecddc07108d3f004fd2d0785eb4077180dafe

See more details on using hashes here.

Provenance

The following attestation bundles were made for rag_assistant_ldxs-2.1.0b2-py3-none-any.whl:

Publisher: publish-pypi.yml on Ldxs001/workbuddy-skills

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

2.4.1

1 file

2.3.0

1 file

2.2.14

1 file

2.2.12

1 file

2.2.11

1 file

2.2.10

1 file

2.2.8

1 file

This release

2.1.0b2 This release

1 file

1.7.0

1 file

1.2.0

1 file

1.1.2

1 file

1.1.1

1 file

1.0.3

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

0.10.0

1 file

0.9.6

1 file

0.9.5

1 file

0.9.4

1 file

0.9.3

1 file

0.9.0

1 file

0.8.6

1 file

0.8.5

1 file

0.8.4

1 file

0.8.3

1 file

0.8.1

1 file

0.8.0

1 file

0.6.4

1 file

0.6.3

1 file

0.6.2

1 file

0.5.3

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page