From ee14012ca7060e1ef7466a8de6cb77f353a6bf37 Mon Sep 17 00:00:00 2001 From: NNIIOVO Date: Mon, 9 Nov 2026 00:34:18 -0600 Subject: [PATCH] Python: compare whole-number floats with int fields in Cosmos filters Signed-off-by: NNIIOVO --- .../agent_framework_azure_cosmos/_vector_store.py | 4 ++-- .../tests/azure_cosmos/test_vector_store.py | 15 +++++++++++++++ .../azure_cosmos/test_vector_store_integration.py | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/python/packages/azure-cosmos/agent_framework_azure_cosmos/_vector_store.py b/python/packages/azure-cosmos/agent_framework_azure_cosmos/_vector_store.py index 04f9b282fe6..5a08affb2c9 100644 --- a/python/packages/azure-cosmos/agent_framework_azure_cosmos/_vector_store.py +++ b/python/packages/azure-cosmos/agent_framework_azure_cosmos/_vector_store.py @@ -648,8 +648,8 @@ def _filter_value_compatible(field: VectorStoreField, value: Any) -> bool: field.type_ is None or (field.type_ == "str" and isinstance(value, str)) or (field.type_ == "bool" and type(value) is bool) - or (field.type_ == "int" and type(value) is int) - or (field.type_ == "float" and type(value) in (int, float)) + # Cosmos stores every JSON number as a double, so 2 and 2.0 compare equal. + or (field.type_ in ("int", "float") and type(value) in (int, float)) ) diff --git a/python/packages/azure-cosmos/tests/azure_cosmos/test_vector_store.py b/python/packages/azure-cosmos/tests/azure_cosmos/test_vector_store.py index a001b55f578..fddf91060ca 100644 --- a/python/packages/azure-cosmos/tests/azure_cosmos/test_vector_store.py +++ b/python/packages/azure-cosmos/tests/azure_cosmos/test_vector_store.py @@ -911,6 +911,21 @@ async def test_full_batch_item_size_and_json_preflight() -> None: ), (Filter("count", "eq", True), "false", []), (Filter("count", "ne", True), 'IS_DEFINED(c["count"])', []), + ( + Filter("count", "eq", 2.0), + '(IS_DEFINED(c["count"]) AND NOT IS_NULL(c["count"]) AND c["count"] = @filter_0)', + [2.0], + ), + ( + Filter("count", "ne", 2.0), + '(IS_DEFINED(c["count"]) AND (IS_NULL(c["count"]) OR c["count"] != @filter_0))', + [2.0], + ), + ( + Filter("count", "gt", 1.5), + '(IS_DEFINED(c["count"]) AND NOT IS_NULL(c["count"]) AND c["count"] > @filter_0)', + [1.5], + ), ( Filter("count", "gt", 1), '(IS_DEFINED(c["count"]) AND NOT IS_NULL(c["count"]) AND c["count"] > @filter_0)', diff --git a/python/packages/azure-cosmos/tests/azure_cosmos/test_vector_store_integration.py b/python/packages/azure-cosmos/tests/azure_cosmos/test_vector_store_integration.py index bd1b5e510a1..e028c7987a9 100644 --- a/python/packages/azure-cosmos/tests/azure_cosmos/test_vector_store_integration.py +++ b/python/packages/azure-cosmos/tests/azure_cosmos/test_vector_store_integration.py @@ -269,6 +269,11 @@ async def test_disposable_vector_database_crud_filter_and_search() -> None: } assert await default_collection.get(filter=Filter("count", "eq", True)) == [] assert await default_collection.get(filter=Filter("active", "eq", 1)) == [] + assert [item["key"] for item in await default_collection.get(filter=Filter("count", "eq", 2.0))] == ["two"] + assert {item["key"] for item in await default_collection.get(filter=Filter("count", "ne", 2.0))} == { + "one", + "three", + } not_value = FilterGroup("not", [Filter("optional", "eq", "value")]) assert {item["key"] for item in await default_collection.get(filter=not_value)} == {"one", "three"}