Repository navigation
[Cosmos] Use deterministic ordinal ranks for hybrid-search RRF - #49623
Maya Painter (Maya-Painter) wants to merge 12 commits into
Conversation
Port Azure/azure-cosmos-dotnet-v3#6130 with shared sync/async fusion, numeric document RID ordering, and an internal per-query competition-ranking fallback. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 68efd20b-2c16-45ea-9e93-ecbd62e4e352
|
Azure Pipelines: Successfully started running 3 pipeline(s). 7 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 68efd20b-2c16-45ea-9e93-ecbd62e4e352
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
A verified empty-score ordering regression can raise IndexError in both clients.
1 open issue
What changed in this PR
Updates Cosmos hybrid-search reciprocal rank fusion to use deterministic ordinal ranks in both synchronous and asynchronous clients.
Changes:
- Shares ranking logic with numeric document-RID tie-breaking and optional competition ranking.
- Adds tests for ranking modes, weights, deterministic ordering, and preserved query behavior.
- Documents the behavior change and compatibility setting in release notes.
| File | Description |
|---|---|
sdk/cosmos/azure-cosmos/tests/test_hybrid_search_aggregator.py |
Adds ranking and sync/async regression coverage. |
sdk/cosmos/azure-cosmos/CHANGELOG.md |
Documents ordinal ranking and the competition option. |
sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/hybrid_search_aggregator.py |
Implements shared ranking and numeric RID tie-breaking. |
sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/aio/hybrid_search_aggregator.py |
Uses shared ranking and snapshots the ranking mode. |
.chronus/changes/cosmos-ordinal-rrf-ranking.md |
Adds release metadata describing the ranking fix. |
Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
Size score arrays from the query plan and cover empty-first and all-empty rows in sync and async queries. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 68efd20b-2c16-45ea-9e93-ecbd62e4e352
This comment has been minimized.
This comment has been minimized.
Remove the options override, centralize environment constants, update regression coverage, apply the suggested changelog wording, and remove the Chronus fragment. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 68efd20b-2c16-45ea-9e93-ecbd62e4e352
This comment has been minimized.
This comment has been minimized.
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
Remove the competition-ranking environment switch and update the changelog and tests to match the .NET ranking fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 68efd20b-2c16-45ea-9e93-ecbd62e4e352
This comment has been minimized.
This comment has been minimized.
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
[Pilot] PR Pipeline Failure AnalysisWhat failed
Root causeThe automated Relevant pipeline outputRecommended next steps
|
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 68efd20b-2c16-45ea-9e93-ecbd62e4e352
|
/azp run python - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 68efd20b-2c16-45ea-9e93-ecbd62e4e352

Description
Fixes Cosmos hybrid-search reciprocal rank fusion (RRF) results being ranked incorrectly when component scores are tied. Both synchronous and asynchronous Python clients now use deterministic ordinal ranks, matching Azure/azure-cosmos-dotnet-v3#6188.
Previously, Python used dense ranking: tied component scores shared a rank, and the next distinct score received the next consecutive rank. Every result now receives its 1-based position in the sorted component results, including ties. There is no environment-variable switch or competition-ranking fallback. The RRF formula and component weights are unchanged.
Example
For a descending component with scores
10, 5, 5, 5, 0:With weight 1, the last document contributes
1 / 65instead of1 / 63; the three documents scoring 5 also receive distinct contributions.Equal component scores use the numeric document portion of
_ridas a deterministic client-side tie-breaker, in the component query's sort direction. Equal final RRF scores use numeric document RID descending. Each retained document's numeric RID is decoded once.Both clients share the ranking implementation. Full-RID deduplication, returned payloads, skip/take behavior, query-plan sort directions, and component weights are preserved. Component-score arrays are sized from the query plan so empty-score rows retain the existing fallback regardless of arrival order. No public API signatures or SDK versions change.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines