fix(kb): improve retrieval resilience on per-KB failure and rerank selection#9122
Conversation
…lection - Remove RuntimeError on single-KB dense retrieval failure: always skip the faulty KB and return partial results instead of crashing. - Simplify rerank provider selection: remove redundant rerank_pi check since the provider is already loaded from that ID.
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
_dense_retrieve, changing single-KB failures from raising to just logging and skipping alters error visibility; consider at least surfacing a clear signal to the caller (e.g., a special result or aggregated error info) so that a completely failed retrieval is distinguishable from an empty successful one. - When logging dense retrieval failures, including the exception type and relevant KB configuration (e.g., provider IDs or vec_db meta info) in the log message would make operational debugging of per-KB failures easier.
- In the rerank selection loop, you can short-circuit earlier by iterating directly over
kb_options.values()instead of usingkb_idindexing, which would simplify the code further and avoid repeated dictionary lookups.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_dense_retrieve`, changing single-KB failures from raising to just logging and skipping alters error visibility; consider at least surfacing a clear signal to the caller (e.g., a special result or aggregated error info) so that a completely failed retrieval is distinguishable from an empty successful one.
- When logging dense retrieval failures, including the exception type and relevant KB configuration (e.g., provider IDs or vec_db meta info) in the log message would make operational debugging of per-KB failures easier.
- In the rerank selection loop, you can short-circuit earlier by iterating directly over `kb_options.values()` instead of using `kb_id` indexing, which would simplify the code further and avoid repeated dictionary lookups.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request simplifies the reranking provider selection logic and modifies error handling in dense retrieval to skip faulty knowledge bases instead of raising a RuntimeError when only one knowledge base is queried. Feedback points out that simplifying the reranking logic by removing the ID consistency check could lead to executing reranking when disabled or using an expired reranker, and suggests retaining the validation checks.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…lection (AstrBotDevs#9122) * fix(kb): improve retrieval resilience on per-KB failure and rerank selection - Remove RuntimeError on single-KB dense retrieval failure: always skip the faulty KB and return partial results instead of crashing. - Simplify rerank provider selection: remove redundant rerank_pi check since the provider is already loaded from that ID. * fix(kb): simplify rerank selection loop, improve dense retrieval error log
Modifications / 改动点
astrbot/core/knowledge_base/retrieval/manager.py:RuntimeError,改为记录日志并跳过错的知识库,与其他知识库的行为保持一致,避免单点故障导致整体检索崩溃rerank_pi == rerank_provider.meta().id检查(provider 本身就是从该 ID 加载的),以及不必要的嵌套条件This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
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
Improve knowledge base retrieval resilience and simplify rerank provider selection.
Bug Fixes:
Enhancements: