Skip to content

Conversation

@amanrao23
Copy link
Member

Packages impacted by this PR

@azure/cosmos

Issues associated with this PR

#34221

Describe the problem that is addressed by this PR

  1. 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))

  2. 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 disableHybridSearchQueryPlanOptimization is 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

  • Added impacted package name to the issue description
  • Does this PR needs any fixes in the SDK Generator?** (If so, create an Issue in the Autorest/typescript repository and link it here)
  • Added a changelog (if necessary)

Copilot AI review requested due to automatic review settings May 5, 2025 16:43
@github-actions github-actions bot added the Cosmos label May 5, 2025
Copy link
Contributor

Copilot AI left a 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.

@Azure Azure deleted a comment from Copilot AI May 5, 2025
@Azure Azure deleted a comment from Copilot AI May 5, 2025
@azure-sdk
Copy link
Collaborator

azure-sdk commented May 5, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

@azure/cosmos

Copy link
Member

@topshot99 topshot99 left a comment

Choose a reason for hiding this comment

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

LGTM

@amanrao23 amanrao23 merged commit 887559c into main May 9, 2025
11 checks passed
@amanrao23 amanrao23 deleted the cosmosdb/hybrid-search-optimizations branch May 9, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants