[Query]: Adds ability to choose global vs local/focused statistics for FullTextScore#45686
Open
aayush3011 wants to merge 7 commits intoAzure:mainfrom
Open
[Query]: Adds ability to choose global vs local/focused statistics for FullTextScore#45686aayush3011 wants to merge 7 commits intoAzure:mainfrom
aayush3011 wants to merge 7 commits intoAzure:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in way to scope BM25 statistics used by FullTextScore in Cosmos DB hybrid search, allowing callers to choose between global container-wide statistics and “local” statistics limited to the query’s target partition ranges.
Changes:
- Added
full_text_score_scopekwarg toquery_items()(sync + async) with validation and docs. - Updated hybrid search aggregators to scope global statistics queries to either all ranges (Global/default) or target ranges (Local).
- Added sync/async test coverage and updated the package changelog.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/azure/cosmos/container.py | Adds full_text_score_scope kwarg, validates values, documents behavior, and passes the option into query feed options. |
| sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py | Async equivalent of full_text_score_scope kwarg support (validation + docs + feed option). |
| sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/hybrid_search_aggregator.py | Uses fullTextScoreScope option to decide whether global statistics queries target all partition ranges or only query target ranges. |
| sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/aio/hybrid_search_aggregator.py | Async equivalent of local vs global partition-range selection for statistics queries. |
| sdk/cosmos/azure-cosmos/tests/test_query_hybrid_search.py | Adds sync tests for Global vs Local scope behavior. |
| sdk/cosmos/azure-cosmos/tests/test_query_hybrid_search_async.py | Adds async tests for Global vs Local scope behavior. |
| sdk/cosmos/azure-cosmos/CHANGELOG.md | Documents the new full_text_score_scope parameter in the unreleased section. |
You can also share your feedback on Copilot code review. Take the survey.
sdk/cosmos/azure-cosmos/tests/test_query_hybrid_search_async.py
Outdated
Show resolved
Hide resolved
simorenoh
reviewed
Mar 13, 2026
Member
simorenoh
left a comment
There was a problem hiding this comment.
Copilot had some comments that may be worthwhile on the tests added - LGTM otherwise
Member
Author
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Why?
Cosmos DB's implementation of FullTextScore computes BM25 statistics (term frequency, inverse document frequency, and document length) across all documents in the container, including all physical and logical partitions.
While this provides a valid and comprehensive representation of statistics for the entire dataset, it introduces challenges for several common use cases:
This is the Python SDK port of the .NET SDK PR: Azure/azure-cosmos-dotnet-v3#5582
What?
This PR extends the flexibility of BM25 scoring so that developers can choose between:
How?
A new full_text_score_scope keyword argument is added to query_items():
When full_text_score_scope="Local", the hybrid search aggregator uses only the query's target partition ranges (instead of all ranges) when executing the global statistics query. This is a client-side only change, no new HTTP headers are sent to the backend.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines