Skip to content
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

[Cosmos][VectorSearch] Non Streaming Order By Query #39897

Merged

Conversation

aayush3011
Copy link
Member

@aayush3011 aayush3011 commented Apr 24, 2024

Description

Java follow up to the .Net PR: Azure/azure-cosmos-dotnet-v3#4362

  • Using the flag for nonStreamingOrderBy that is now present in the query plan, we choose to create a separate query execution context for these types of operations.
  • This update introduces NonStreamingOrderByQueryQueryContext, essential for vector search capabilities. Previously, the SDK operated under the assumption that documents returned in response to ORDER BY queries were fully ordered across all continuations. However, with the newly implemented non-streaming OrderBy feature in the backend, this assumption is no longer valid.
  • The approach for this is having a Priority of size TOP +1 or LIMIT+OFFSET+1 for every document producer. This query pipeline functions as a blocking pipeline, similar to the GROUP BY. We will accumulate all the backend responses for every document producer in it's own PQ which is ordered using the comparator passed by the BE. Once all the document producers are processed, the are re-balanced together to yield the results.
  • The reason for having the size of PQ as TOP +1 or LIMIT+OFFSET+1, because once the PQ has reached the TOP size, we want to add one document, and then remove based on the ordering. If we just used TOP or LIMIT+OFFSET, adding a new document after reaching the limit would make the PQ 50% bigger, which could mess up the results.

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 have 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.

…ngPolicy (Azure#40004)

* Adding changes for vectorIndex and vectorEmbeddingPolicy

* Adding some necessary comments

* Adding test case

* updating enum values

* Updating test case

* Updating test case

* Updating test case

* updating changelog

* Updating test case

* Resolving comments

* Resolving comments

* Fixing test case

* Resolving comments

* Resolving Comments

* Fixing build issues

* Resolving comments

* Resolving Comments
@azure-sdk
Copy link
Collaborator

azure-sdk commented May 3, 2024

API change check

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

com.azure:azure-cosmos

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

} else {
initialPageSize = pageSizeWithTopOrLimit;
}
initialPageSize = pageSizeWithTopOrLimit;
Copy link
Member

Choose a reason for hiding this comment

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

why the change here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because for Top greater than 100, and maxItemCount not set, initialPageSize by default is 100. So the top value was always being 100.

And if Non-streaming order by, top or limit will always be there, and their value should be picked up.

Copy link
Member

Choose a reason for hiding this comment

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

limit is dangerous - because for several queries offset/limit are actually client-side processing

Copy link
Member Author

Choose a reason for hiding this comment

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

But initialPageSize is used as the size of our PQ. For limit if we use the default initialPageSize, then we will not get the correct number of items back.

Copy link
Member

Choose a reason for hiding this comment

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

From some of the discussions on the JS SDK, I think we need to have OFFSET+LIMIT tests for at least the single partition and multiple partition cases, since they are processed differently by the service.

Copy link
Member

@xinlian12 xinlian12 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@aayush3011
Copy link
Member Author

/azp run java - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@aayush3011
Copy link
Member Author

/azp run java - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@aayush3011
Copy link
Member Author

/azp run java - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@aayush3011
Copy link
Member Author

/azp run java - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@aayush3011
Copy link
Member Author

/azp run java - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@aayush3011
Copy link
Member Author

/azp run java - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kushagraThapar
Copy link
Member

/check-enforcer override

@kushagraThapar kushagraThapar dismissed FabianMeiswinkel’s stale review May 20, 2024 00:08

Query and service team has decided to go ahead with the opt-out env variable vector search feature, need to release today.

@kushagraThapar kushagraThapar merged commit 0c4e817 into Azure:main May 20, 2024
85 of 93 checks passed
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.

None yet

7 participants