Skip to content

Conversation

analogrelay
Copy link
Member

For Hybrid Search, as well as ReadMany support, the query engine will need to direct the SDK to issue multiple different queries. However, the Rust SDK's query executor expects to be able to replay the original query on each request. This PR changes that expectation to allow (but not require) each Query Request coming from the pipeline to provide an alternate query. When an alternate query is provided, the pipeline can also indicate if the parameters from the original query should be sent. Often, the alternate query does NOT use the parameters, but in some circumstances (hybrid search) it will.

There are also some small fixes for doc tests and error checking in the engine-less cross-partition query tests. Not sure why these are coming up here and not in main.

@analogrelay analogrelay requested review from Copilot and removed request for Copilot October 9, 2025 17:57
@analogrelay analogrelay requested a review from a team as a code owner October 9, 2025 17:57
@github-actions github-actions bot added the Cosmos The azure_cosmos crate label Oct 9, 2025
@analogrelay analogrelay closed this Oct 9, 2025
@analogrelay
Copy link
Member Author

I'm actually going to do a few other optimizations to the Query Engine API and open a new PR soon

@analogrelay analogrelay reopened this Oct 9, 2025
@analogrelay
Copy link
Member Author

Ok, I've added two more optimizations that I've been meaning to add to this API:

  1. QueryRequest::drain which indicates to the SDK that it should drain all pages from the given partition and give them to the pipeline before continuing. This will reduce "chattiness" for large non-streaming queries.
  2. provide_data now takes a list of results instead of just a single result. This allows the SDK to work asynchronously and batch results. The SDK is expected to keep pages in order, but can interleave results from different partition key ranges if that's helpful to it.

@Copilot Copilot AI review requested due to automatic review settings October 9, 2025 20:53
Copy link
Contributor

@Copilot 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 enhances the Cosmos DB query pipeline to support alternative queries for each request, enabling features like Hybrid Search and ReadMany operations. Instead of replaying the original query for each partition, the pipeline can now direct the SDK to execute different queries with optional parameter inheritance.

  • Modified query pipeline and executor to support optional query overrides per request
  • Added configuration for including/excluding original parameters with alternative queries
  • Enhanced mock query engine infrastructure for comprehensive testing

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk/cosmos/azure_data_cosmos/src/query/engine.rs Extended QueryRequest and QueryResult structures with new fields for query overrides, parameter inclusion, and request ordering
sdk/cosmos/azure_data_cosmos/src/query/executor.rs Updated executor to handle alternative queries and parameter inheritance logic
sdk/cosmos/azure_data_cosmos/src/query/mod.rs Added method to copy parameters between Query instances
sdk/cosmos/azure_data_cosmos/tests/framework/query_engine.rs Enhanced mock infrastructure with query override configuration and request ordering validation
sdk/cosmos/azure_data_cosmos/tests/query_engine.rs Added comprehensive test cases for query override scenarios
sdk/cosmos/azure_data_cosmos/tests/cosmos_query.rs Updated error handling test to use newer API pattern
sdk/cosmos/azure_data_cosmos/src/clients/cosmos_client.rs Fixed documentation example to use Secret wrapper

Copy link

github-actions bot commented Oct 9, 2025

API Change Check

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

azure_data_cosmos

@LarryOsterman
Copy link
Member

@analogrelay Could you please push a small change to this PR? That should unblock the CI pipeline which was accidentally included.

@analogrelay
Copy link
Member Author

Can do! Sorry about the delay, got pulled on to high-pri stuff ;).

@analogrelay analogrelay force-pushed the ashleyst/allow-pipeline-to-return-new-query branch from 7d128e5 to 6d42511 Compare October 16, 2025 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cosmos The azure_cosmos crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants