feat(kb): support pluggable knowledge base retrieval backends - #9751
Draft
lxfight wants to merge 14 commits into
Draft
feat(kb): support pluggable knowledge base retrieval backends#9751lxfight wants to merge 14 commits into
lxfight wants to merge 14 commits into
Conversation
This was referenced Aug 20, 2026
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
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.
AstrBot plugins can already integrate external knowledge base systems through custom hooks, but there is no stable, shared contract for knowledge base discovery and retrieval.
This PR introduces a minimal public backend API so plugins can expose external knowledge bases through a consistent interface without depending on AstrBot's built-in storage implementation. The scope is intentionally limited to enabled knowledge base discovery and read-only retrieval.
Modifications / 改动点
Added public plugin contracts for knowledge base backends:
BaseKnowledgeBaseBackendKnowledgeBaseRefKnowledgeBaseInfoKnowledgeBaseQueryKnowledgeBaseHitKnowledgeBaseResponseAdded backend registration and unregistration through the plugin
Context.Added an adapter that exposes the built-in knowledge base through the same contract without replacing the existing built-in Agent flow.
Added concurrent multi-backend retrieval with:
top_ktruncationAdded first-class knowledge base identity to every retrieval hit.
Integrated enabled external backends into the existing Agent knowledge base flow.
Defined
list_knowledge_bases()as returning only knowledge bases that are enabled and accessible for the current session.Added explicit plugin reload lifecycle behavior. Plugins unregister their backends in
terminate()before releasing resources.Added Chinese and English plugin development documentation with a complete backend example.
Added unit and adversarial tests for registration, discovery, retrieval, failure isolation, malformed responses, result identity, and reload behavior.
This is NOT a breaking change. / 这不是一个破坏性变更.
Scope
This PR intentionally does not standardize:
Plugins may provide those capabilities through their own configuration, commands, or Plugin Pages. Optional management contracts can be considered separately when concrete cross-backend requirements are available.
The existing AstrBot knowledge base database, upload flow, Dashboard APIs, and backup behavior are unchanged.
Screenshots or Test Results / 运行截图或测试结果
Verification performed:
Two existing Dashboard log-capture tests fail locally because warnings are emitted through the configured logger instead of
caplog. The same failures were reproduced onupstream/masterand are unrelated to this PR.The Chinese and English VitePress documentation build also completed successfully.
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Enable plugins to provide external knowledge bases through a shared, resilient retrieval backend contract.
New Features:
Enhancements:
Documentation:
Tests: