-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for Weighted RRF + Hybrid Search Query plan optimization #34222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
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 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. |
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
sdk/cosmosdb/cosmos/src/queryExecutionContext/hybridQueryExecutionContext.ts
Show resolved
Hide resolved
sdk/cosmosdb/cosmos/src/queryExecutionContext/hybridQueryExecutionContext.ts
Show resolved
Hide resolved
topshot99
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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