Skip to content

Fix duplicate hybrid search result subscription#49831

Open
arnabnandy7 wants to merge 2 commits into
Azure:mainfrom
arnabnandy7:fix/rrf-index-out-of-bounds
Open

Fix duplicate hybrid search result subscription#49831
arnabnandy7 wants to merge 2 commits into
Azure:mainfrom
arnabnandy7:fix/rrf-index-out-of-bounds

Conversation

@arnabnandy7

@arnabnandy7 arnabnandy7 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes an intermittent IndexOutOfBoundsException when executing cross-partition hybrid search queries using ORDER BY RANK RRF(...).

The coalesced component-query results were consumed by two reactive branches. Because the result Mono was cold, each branch independently re-executed the cross-partition query pipeline and could receive a differently sized result list. The ranks calculated from one result set could then be applied to another, causing the exception.

This change caches the coalesced result Mono, ensuring rank calculation and RRF score calculation operate on the same materialized results.

Fixes #49823.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

The azure-cosmos module was successfully compiled for both the Java baseline and module-path build. No new automated test was added because reproducing the original failure requires nondeterministic timing differences between duplicate subscriptions to a live, cross-partition query. Existing hybrid-search integration tests continue to cover RRF query execution.

Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
Copilot AI review requested due to automatic review settings July 15, 2026 21:33
@arnabnandy7
arnabnandy7 requested review from a team and kirankumarkolli as code owners July 15, 2026 21:33
@github-actions github-actions Bot added Community Contribution Community members are working on the issue Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Jul 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution @arnabnandy7! We will review the pull request and get back to you soon.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
33 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an intermittent IndexOutOfBoundsException in cross-partition hybrid search queries (ORDER BY RANK RRF(...)) by ensuring the coalesced component-query results are materialized once and shared across downstream reactive branches, preventing mismatched rank/score computations caused by duplicate subscriptions.

Changes:

  • Cached the coalesced-and-sorted hybrid search result Mono to prevent duplicate re-execution and inconsistent result sizing across reactive branches.
  • Added a CHANGELOG entry documenting the bug fix and linking to the tracked issue.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/HybridSearchDocumentQueryExecutionContext.java Adds .cache() to the coalesced-and-sorted results Mono so rank and RRF computations consume the same materialized result set.
sdk/cosmos/azure-cosmos/CHANGELOG.md Documents the hybrid search cross-partition IndexOutOfBoundsException fix and references Issue #49823.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Hybrid search ORDER BY RANK RRF throws IndexOutOfBoundsException — coalescedAndSortedResults Mono subscribed twice without .cache()

2 participants