Add support for Weighted RRF + Hybrid Search Query plan optimization#34222
Merged
Add support for Weighted RRF + Hybrid Search Query plan optimization#34222
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for Weighted RRF scoring in hybrid search queries and introduces a query plan optimization flag to support optimized query plans for hybrid search.
- Introduces new weighted RRF scoring with component weights and a comparator function.
- Updates integration and unit tests to validate the new query plan optimization behavior and weighted ranking functionality.
- Modifies header construction and query feature support to incorporate the new options.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmosdb/cosmos/test/public/integration/fullTextSearch.spec.ts | Updated integration tests for weighted RRF and hybrid query plan optimization. |
| sdk/cosmosdb/cosmos/test/internal/unit/utils/supportedQueryFeaturesBuilder.spec.ts | Updated tests for supported query features with new optimization flag. |
| sdk/cosmosdb/cosmos/test/internal/unit/hybridExecutionContext.spec.ts | Updated unit tests to pass new componentWeights to sort functions. |
| sdk/cosmosdb/cosmos/src/utils/supportedQueryFeaturesBuilder.ts | Changed API to take FeedOptions for determining query features. |
| sdk/cosmosdb/cosmos/src/request/hybridSearchQueryResult.ts | Adjusted extraction of payload data for newer query plan format. |
| sdk/cosmosdb/cosmos/src/request/FeedOptions.ts | Added disableHybridSearchQueryPlanOptimization flag documentation. |
| sdk/cosmosdb/cosmos/src/request/ErrorResponse.ts | Documented componentWeights in error response interface. |
| sdk/cosmosdb/cosmos/src/queryExecutionContext/hybridQueryExecutionContext.ts | Refactored sorting and score computation logic to incorporate component weights. |
| sdk/cosmosdb/cosmos/src/common/constants.ts | Added new query feature constants for weighted ranking and hybrid optimization. |
| sdk/cosmosdb/cosmos/src/ClientContext.ts | Updated header construction to use the new supportedQueryFeaturesBuilder signature. |
Collaborator
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
topshot99
reviewed
May 6, 2025
topshot99
reviewed
May 6, 2025
topshot99
reviewed
May 6, 2025
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.
Packages impacted by this PR
@azure/cosmos
Issues associated with this PR
#34221
Describe the problem that is addressed by this PR
Add support for weighted RRF in hybrid search.
We allow weights to be negative but the negative sign is used to signal that we should sort scores in ascending order for the corresponding component. The final WRRF score is then computed using the absolute value of the weight.
In this approach, the sign of the weight indicates the interpretation of the ranking itself rather than directly affecting the calculated score:
WRRF(d) = ∑ |w_i| × 1/(k + r_i'(d))
Adds support for the optimized query plan
Adds a QueryFeature that returns optimized query plan, effectively removing the need for rewriting orderByExpressions in the SDK.
A flag
disableHybridSearchQueryPlanOptimizationis added to disable returning optimized query plan. This is done to ensure the query works as expected for older gateways.Are there test cases added in this PR? (If not, why?)
Yes
Provide a list of related PRs (if any)
Command used to generate this PR:**(Applicable only to SDK release request PRs)
Checklists