Skip to content

Conversation

@neildsh
Copy link
Contributor

@neildsh neildsh commented Apr 10, 2025

Description

Adds support for the optimized query plan that skips the order by rewrite. The new hybrid search component query plan "lies" to the SDK about there being no ORDER BY on the component queries. However, the hybrid search query pipeline stage knows that the component scores need to be sorted. Since there is no information about this sorting on the query plan anymore, the hybrid search query pipeline stage will always sort descending in this scenario. The component score projections are rewritten to safeguard this assumption.

This change is backward compatible so that the SDK can accept both the old style query plan with rewritten ORDER BY as well as the new one that skips the order by rewrite.

The end user can disable the optimized query plan by setting the environment variable AZURE_COSMOS_HYBRID_SEARCH_QUERYPLAN_OPTIMIZATION_DISABLED flag to true.

Type of change

  • New feature (non-breaking change which adds functionality)

@neildsh neildsh force-pushed the users/ndeshpan/hybridSearchQueryPlanOpt branch from e148be4 to 9d90576 Compare May 5, 2025 19:52
sboshra
sboshra previously approved these changes May 5, 2025
Copy link
Contributor

@sboshra sboshra left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

@adityasa adityasa left a comment

Choose a reason for hiding this comment

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

:shipit:

@microsoft-github-policy-service microsoft-github-policy-service bot merged commit 6d57959 into master May 6, 2025
26 checks passed
@microsoft-github-policy-service microsoft-github-policy-service bot deleted the users/ndeshpan/hybridSearchQueryPlanOpt branch May 6, 2025 01:21
microsoft-github-policy-service bot pushed a commit that referenced this pull request May 6, 2025
…h to be disabled (#5171)

## Description
#5120 enabled the switch to ask for the optimized query plan by default.
However, the pipeline support for the optimized query plan is in #5121.
This will lead to exceptions in the hybrid search query pipeline in
version 3.49.0 if the SDK talks to a newer gateway that can return the
optimized query plan. To prevent this, we change this optimization to be
disabled by default.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

Co-authored-by: Debdatta Kunda <[email protected]>
neildsh added a commit that referenced this pull request May 6, 2025
…h to be disabled (#5171)

## Description
#5120 enabled the switch to ask for the optimized query plan by default.
However, the pipeline support for the optimized query plan is in #5121.
This will lead to exceptions in the hybrid search query pipeline in
version 3.49.0 if the SDK talks to a newer gateway that can return the
optimized query plan. To prevent this, we change this optimization to be
disabled by default.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

Co-authored-by: Debdatta Kunda <[email protected]>
microsoft-github-policy-service bot pushed a commit that referenced this pull request May 6, 2025
…h to be disabled (#5174)

This is a cherry-pick of #5171 

## Description
#5120 enabled the switch to ask for the optimized query plan by default.
However, the pipeline support for the optimized query plan is in #5121.
This will lead to exceptions in the hybrid search query pipeline in
version 3.49.0 if the SDK talks to a newer gateway that can return the
optimized query plan. To prevent this, we change this optimization to be
disabled by default.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

Co-authored-by: Debdatta Kunda <[email protected]>
amanrao23 added a commit to Azure/azure-sdk-for-js that referenced this pull request May 9, 2025
…34222)

### 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)_
* Azure/azure-cosmos-dotnet-v3#5064
* Azure/azure-cosmos-dotnet-v3#5120
* Azure/azure-cosmos-dotnet-v3#5121

### 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](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge Enables automation to merge PRs QUERY

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants