From 8ff1f0bf9e120e3596c10014fd915b069ff3326f Mon Sep 17 00:00:00 2001 From: Mei Date: Sun, 2 Aug 2026 22:01:22 +0800 Subject: [PATCH 1/2] Python: Fix Cosmos DB MongoDB vector index kind mapping (#14104) --- python/semantic_kernel/connectors/azure_cosmos_db.py | 2 +- .../test_azure_cosmos_db_mongodb_collection.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/semantic_kernel/connectors/azure_cosmos_db.py b/python/semantic_kernel/connectors/azure_cosmos_db.py index 2d1bb53d9630..8e095b02c22c 100644 --- a/python/semantic_kernel/connectors/azure_cosmos_db.py +++ b/python/semantic_kernel/connectors/azure_cosmos_db.py @@ -399,7 +399,7 @@ def _get_index_definitions(self, **kwargs: Any) -> dict[str, Any]: f"Distance function '{field.distance_function}' is not supported by Azure Cosmos DB for MongoDB." ) index_name = f"{field.storage_name or field.name}_" - index_kind = DISTANCE_FUNCTION_MAP_MONGODB[field.distance_function] + index_kind = INDEX_KIND_MAP_MONGODB[field.index_kind] index: dict[str, Any] = { "name": index_name, FieldTypes.KEY: {field.storage_name or field.name: "cosmosSearch"}, diff --git a/python/tests/unit/connectors/memory/azure_cosmos_db/test_azure_cosmos_db_mongodb_collection.py b/python/tests/unit/connectors/memory/azure_cosmos_db/test_azure_cosmos_db_mongodb_collection.py index 8da8a1ab08e8..f38450e313a7 100644 --- a/python/tests/unit/connectors/memory/azure_cosmos_db/test_azure_cosmos_db_mongodb_collection.py +++ b/python/tests/unit/connectors/memory/azure_cosmos_db/test_azure_cosmos_db_mongodb_collection.py @@ -98,8 +98,8 @@ async def test_ensure_collection_exists_calls_database_methods(definition) -> No # Check the vector field index creation assert command_args["indexes"][1]["name"] == "vector_" assert command_args["indexes"][1]["key"] == {"vector": "cosmosSearch"} - assert command_args["indexes"][1]["cosmosSearchOptions"]["kind"] == "COS" - assert command_args["indexes"][1]["cosmosSearchOptions"]["similarity"] is not None + assert command_args["indexes"][1]["cosmosSearchOptions"]["kind"] == "vector-hnsw" + assert command_args["indexes"][1]["cosmosSearchOptions"]["similarity"] == "COS" assert command_args["indexes"][1]["cosmosSearchOptions"]["dimensions"] == 5 From 02fd264b3b5ed1bd3292cf27f1c08e3da8a667a9 Mon Sep 17 00:00:00 2001 From: MeiSiristhebest Date: Mon, 3 Aug 2026 02:57:24 +0800 Subject: [PATCH 2/2] test(python): add tuning kwargs assertions to Cosmos DB MongoDB collection test --- .../test_azure_cosmos_db_mongodb_collection.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/tests/unit/connectors/memory/azure_cosmos_db/test_azure_cosmos_db_mongodb_collection.py b/python/tests/unit/connectors/memory/azure_cosmos_db/test_azure_cosmos_db_mongodb_collection.py index f38450e313a7..99e95884d92b 100644 --- a/python/tests/unit/connectors/memory/azure_cosmos_db/test_azure_cosmos_db_mongodb_collection.py +++ b/python/tests/unit/connectors/memory/azure_cosmos_db/test_azure_cosmos_db_mongodb_collection.py @@ -84,10 +84,10 @@ async def test_ensure_collection_exists_calls_database_methods(definition) -> No ) # Act - await collection.ensure_collection_exists(customArg="customValue") + await collection.ensure_collection_exists(customArg="customValue", m=16, efConstruction=64) # Assert - mock_database.create_collection.assert_awaited_once_with("test_collection", customArg="customValue") + mock_database.create_collection.assert_awaited_once_with("test_collection", customArg="customValue", m=16, efConstruction=64) mock_database.command.assert_awaited() command_args = mock_database.command.call_args.kwargs["command"] @@ -101,6 +101,8 @@ async def test_ensure_collection_exists_calls_database_methods(definition) -> No assert command_args["indexes"][1]["cosmosSearchOptions"]["kind"] == "vector-hnsw" assert command_args["indexes"][1]["cosmosSearchOptions"]["similarity"] == "COS" assert command_args["indexes"][1]["cosmosSearchOptions"]["dimensions"] == 5 + assert command_args["indexes"][1]["cosmosSearchOptions"]["m"] == 16 + assert command_args["indexes"][1]["cosmosSearchOptions"]["efConstruction"] == 64 async def test_context_manager_calls_aconnect_and_close_when_managed(mock_model) -> None: