Skip to content

Python: Compare float operands with int fields in Cosmos filters - #10183

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
nniiovoo:python-cosmos-int-float-filter
Nov 9, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
nniiovoo:python-cosmos-int-float-filter

Conversation

@nniiovoo

Copy link
Copy Markdown
Contributor

Motivation & Context

Filtering a Cosmos int field with a float like 2.0 gives wrong results: eq compiles to false, and ne compiles to IS_DEFINED(...), so ne 2.0 also returns the rows where count is 2. Repro is in #10182.

Description & Review Guide

  • What are the major changes? _filter_value_compatible now accepts int and float operands for both int and float fields. Before, only float fields accepted both. Bools are still rejected on numeric fields.
  • What is the impact of these changes? eq/ne with a float on an int field now compile to a normal comparison, like in/not_in already do. Cosmos stores numbers as doubles, so 2 = 2.0 is true there.
  • What do you want reviewers to focus on? Ordered filters with a float on an int field (e.g. gt 1.5) now work instead of raising a TypeError. InMemoryCollection accepts those too, but I can limit the change to eq/ne if you prefer.

Tests: I added eq/ne/gt cases with float values to the filter translation test (they fail on main), and eq/ne 2.0 checks to the Cosmos integration test. I couldn't run the integration test myself because it needs a Cosmos account.

Related Issue

Fixes #10182

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: issue analysis, implementation, tests, and this description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Signed-off-by: NNIIOVO <haimingni44@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the numeric-filter compatibility change.

No open issues 🎉

What changed in this PR

Fixes #10182 by allowing float operands when filtering integer fields in the Python Cosmos vector store, aligning numeric comparisons with existing membership-filter behavior.

Changes:

  • Accepts integer and float operands for both numeric field types while continuing to reject booleans.
  • Adds translation tests for eq, ne, and gt with float operands on integer fields.
  • Adds integration assertions for eq and ne with 2.0; live Cosmos validation remains unverified.
File Description
python/​packages/​azure-cosmos/​tests/​azure_cosmos/​test_vector_store.py Adds regression coverage for numeric filter translation.
python/​packages/​azure-cosmos/​tests/​azure_cosmos/​test_vector_store_integration.py Adds result assertions for float equality and inequality on integer fields.
python/​packages/​azure-cosmos/​agent_framework_azure_cosmos/​_vector_store.py Unifies numeric operand compatibility for integer and float fields.

Review effort: Balanced

Merged via the queue into microsoft:main with commit f87ec53 Nov 9, 2026
55 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — ee14012c Deployed Nov 9, 2026 by nniiovoo via team_check #8970
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Cosmos vector store: eq/ne with a float like 2.0 on an int field give wrong results

3 participants