fix: 修复多知识库稀疏检索排序失真 - #9426
Open
chinatsu1124 wants to merge 1 commit into
Open
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
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.
修复多个知识库各自使用独立 FTS5 索引时,直接按原始 BM25 分数合并候选导致的排序失真。
不同 FTS5 索引的 BM25 分数受各自语料规模、词频和文档长度统计影响,不能直接跨索引比较。此前合并后的位置被当作稀疏检索排名传入 RRF,可能使小知识库中的高相关结果被大知识库候选压低。
Fixes #9425
Modifications / 改动点
为
SparseResult增加可选的来源排名rank。FTS5 检索时保留候选在各知识库独立索引中的局部排名,RRF 使用该排名计算贡献。
内存 BM25 回退路径仍在统一候选集上排序,并记录全局排名,保持原有语义。
对未提供
rank的旧调用保留按列表顺序计算排名的兼容行为。增加跨知识库稀疏检索和 RRF 融合回归测试,测试数据均为虚构内容。
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
验证步骤:
结果:
4 条警告来自既有
aiosqlite原子性测试在线程结束时访问已关闭的事件循环,与本次改动无关。Checklist / 检查清单
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。/ 我的更改没有引入恶意代码。
Summary by Sourcery
Preserve per-knowledge-base sparse retrieval ranks and use them in rank fusion to avoid distorted ordering across independent FTS5 indexes.
Bug Fixes:
Enhancements:
Tests: