You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: opt-in rank-based fusion across knowledge bases
#4291
Following the triage on #4290, I’d like to discuss an opt-in merge strategy for deploying RAGMiddleware with knowledge bases that use different embedding models.
Why this matters
_search_across() flattens results from all knowledge bases, sorts them by raw similarity score, and cuts the candidate pool before the optional reranker runs. Scores are meaningful within each knowledge base. A source that produces higher scores can fill all candidate slots, even when another source has a highly relevant first hit.
I ran the following on AgentScope e53b1b3. The script uses the actual merge function with two stub knowledge bases and a stub reranker that prefers B1 when it is present. It requires no API keys or vector database.
B1 is the first hit in B, but it is already gone when the reranker runs. Under the proposed strategy, the candidate pool would be ['A1', 'B1'] and the stub reranker would return B1.
Proposed behavior
Add a merge_strategy option to RAGMiddleware. Keep score as the default and add an opt-in rank mode. The option names are open to feedback.
In rank mode, take the first result from each non-empty knowledge base in configured order, then the second from each, and continue up to the existing candidate limit. Equal ranks follow configured knowledge-base order even when searches finish in a different order. Each hit keeps its original score, and hits from different bases keep their own identity.
Use the same merge for static retrieval and the search_knowledge tool. Keep threshold filtering at the knowledge-base search step and apply any configured reranker to the merged candidates. If the reranker fails, return results in the selected merge order.
Regression test plan
Use the stub knowledge bases and recording reranker in tests/middleware_rag_test.py to assert that rank mode admits B1 and that the default still sends A1 and A2.
Exercise both middleware modes. Cover a single knowledge base, uneven or empty result lists, and deterministic ordering when the same-rank searches finish in reverse order.
Assert that hit scores are preserved and that a failing reranker returns the top hits in the selected merge order.
Would the maintainers accept an opt-in per-knowledge-base rank merge with configured source order as the tie-breaker? I’d like to implement it and add the regression tests once we agree on the behavior.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Following the triage on #4290, I’d like to discuss an opt-in merge strategy for deploying RAGMiddleware with knowledge bases that use different embedding models.
Why this matters
_search_across()flattens results from all knowledge bases, sorts them by raw similarity score, and cuts the candidate pool before the optional reranker runs. Scores are meaningful within each knowledge base. A source that produces higher scores can fill all candidate slots, even when another source has a highly relevant first hit.Source note on score comparability · Candidate selection and reranking
Reproduction
I ran the following on AgentScope
e53b1b3. The script uses the actual merge function with two stub knowledge bases and a stub reranker that prefers B1 when it is present. It requires no API keys or vector database.B1 is the first hit in B, but it is already gone when the reranker runs. Under the proposed strategy, the candidate pool would be
['A1', 'B1']and the stub reranker would return B1.Proposed behavior
merge_strategyoption toRAGMiddleware. Keepscoreas the default and add an opt-inrankmode. The option names are open to feedback.rankmode, take the first result from each non-empty knowledge base in configured order, then the second from each, and continue up to the existing candidate limit. Equal ranks follow configured knowledge-base order even when searches finish in a different order. Each hit keeps its original score, and hits from different bases keep their own identity.search_knowledgetool. Keep threshold filtering at the knowledge-base search step and apply any configured reranker to the merged candidates. If the reranker fails, return results in the selected merge order.Regression test plan
tests/middleware_rag_test.pyto assert that rank mode admits B1 and that the default still sends A1 and A2.Would the maintainers accept an opt-in per-knowledge-base rank merge with configured source order as the tie-breaker? I’d like to implement it and add the regression tests once we agree on the behavior.
All reactions