-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: 为 AstrBot 添加知识库功能 #3143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: 为 AstrBot 添加知识库功能 #3143
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 添加 pypdf、aiofiles、rank-bm25 依赖包支持文档解析和检索 - 在 default.py 中添加知识库完整配置项 - 配置包括嵌入模型、重排序、存储路径、分块策略、检索参数等 - 默认禁用知识库功能,需用户主动启用
- 实现完整的知识库数据模型(知识库、文档、文档块、会话配置) - 实现基于 SQLite 的向量数据库存储和检索 - 实现文档解析器(PDF、TXT)和固定大小分块器 - 实现混合检索系统(密集向量检索 + BM25 稀疏检索 + RRF 融合) - 实现知识库生命周期管理和消息注入器 - 支持会话级别的知识库配置和关联
- 在 AstrBotCoreLifecycle 中初始化知识库管理器 - 将知识库注入器添加到消息处理上下文 - 在消息流水线中添加 KBEnhanceStage(知识库增强阶段) - 实现会话删除时的知识库配置级联清理机制 - 添加会话管理器的回调注册机制,支持零侵入扩展
- 实现知识库管理 API(创建、删除、列表、更新) - 实现文档管理 API(上传、删除、列表、分块信息) - 实现知识库检索测试 API(支持调试和验证) - 实现会话配置 API(绑定/解绑知识库、配置检索参数) - 实现全局配置 API(启用/禁用、模型选择、检索参数) - 在 Dashboard 服务器中注册知识库路由
- 添加知识库 V2 完整中文翻译文件 - 包括:主页、文档管理、检索测试、全局设置、会话配置 - 在 Alkaid 导航中添加"原生知识库"入口 - 区分"原生知识库"和"知识库(插件)"两个入口
- 添加知识库 V2 完整英文翻译文件 - 包括:主页、文档管理、检索测试、全局设置、会话配置 - 在 Alkaid 导航中添加 "Native Knowledge Base" 入口 - 区分 "Native Knowledge Base" 和 "Knowledge Base (Plugin)"
- 实现知识库 V2 主页面和 4 个子面板组件 - 文档管理面板:支持上传、删除、查看文档分块 - 检索测试面板:支持测试知识库检索效果 - 全局设置面板:配置嵌入模型、重排序、检索参数 - 会话配置面板:管理会话与知识库的绑定关系 - 重构 Alkaid 路由为嵌套结构,添加知识库 V2 路由 - 在翻译系统中注册知识库 V2 多语言支持 - 默认进入 Alkaid 时跳转到原生知识库页面
…tion support; remove unused chunk model
… in DocumentDetail
…update related components
…just top K results in sparse retriever
…ase retrieval with debug mode
…gin in KBList component
refactor: 知识库优化
…strBot into feature/knowledge-base
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @lxfight, your pull request is larger than the review limit of 150000 diff characters
…t hints for field modifications
…ance error handling
Soulter
approved these changes
Oct 25, 2025
LIghtJUNction
approved these changes
Oct 25, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / 动机
为了增强 AstrBot 的智能问答能力和知识管理功能,本次变更引入了全新的知识库模块。该功能允许用户创建、管理和应用知识库,使 AstrBot 能够基于特定领域的知识进行精准问答,解决了原先模型仅依赖通用知识导致回答不够专业和定制化的问题。
将知识库功能并入 AstrBot 主线项目,也便于社区进行后续的持续迭代和优化。
Modifications / 改动点
本次更新围绕知识库功能,对前后端代码进行了系统性添加和修改,核心改动如下:
后端 (Backend):
astrbot/core/knowledge_base目录下新增了知识库核心逻辑,实现了知识库及文档的 CRUD (创建、读取、更新、删除) 操作,以及文档切分、向量化和检索的完整流程。astrbot/dashboard/utils.py文件中,添加了将知识库检索内容嵌入对话上下文的逻辑,为问答提供背景知识。astrbot/dashboard/routes/knowledge_base.py文件,用于注册知识库相关的 API 路由。前端 (Frontend):
dashboard/src/views/knowledge-base目录下,添加了知识库管理的完整前端界面,包括:dashboard/src/views/SessionManagementPage.vue文件中,为每个会话添加了知识库配置选项,允许用户为不同对话场景绑定和切换知识库。其他 (Others):
requirements.txt和pyproject.toml以包含知识库功能所需的新依赖库。Verification Steps / 验证步骤
访问知识库管理页面:
创建和管理知识库:
测试知识检索:
在会话中应用知识库:
进行问答测试:
Screenshots or Test Results / 运行截图或测试结果
知识库界面

知识库详情页

文档管理页

知识检索测试页

会话管理中的知识库配置



问答测试

Compatibility & Breaking Changes / 兼容性与破坏性变更
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.