Python: Fix Cosmos DB MongoDB vector index kind mapping (#14104) - #14249
Open
MeiSiristhebest wants to merge 2 commits into
Open
Python: Fix Cosmos DB MongoDB vector index kind mapping (#14104)#14249MeiSiristhebest wants to merge 2 commits into
MeiSiristhebest wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the Python Azure Cosmos DB for MongoDB connector where the vector index kind was incorrectly populated with the distance-function similarity code, causing invalid index definitions and preventing index-kind-specific tuning options from being applied.
Changes:
- Correctly map
field.index_kindviaINDEX_KIND_MAP_MONGODBwhen building MongoDB vector index definitions. - Update the MongoDB collection unit test to assert the expected
cosmosSearchOptions["kind"]and["similarity"]values.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/semantic_kernel/connectors/azure_cosmos_db.py | Fixes vector index kind mapping to use the index-kind map (enabling correct vector-* kinds and match-based option handling). |
| python/tests/unit/connectors/memory/azure_cosmos_db/test_azure_cosmos_db_mongodb_collection.py | Updates assertions to validate kind="vector-hnsw" and similarity="COS". |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+101
to
103
| 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 |
MeiSiristhebest
force-pushed
the
fix/python-cosmos-mongo-index-kind
branch
from
August 2, 2026 18:59
6f7b86c to
02fd264
Compare
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.
Motivation and Context
Fixes #14104.
In
python/semantic_kernel/connectors/azure_cosmos_db.py,CosmosMongoCollection._get_index_definitionsassignedindex_kindfromDISTANCE_FUNCTION_MAP_MONGODB[field.distance_function]instead ofINDEX_KIND_MAP_MONGODB[field.index_kind].This caused three issues:
cosmosSearchOptions["kind"]was sent as a similarity string (e.g."COS") rather than a valid vector index kind ("vector-hnsw","vector-ivf","vector-diskann"), leading to index creation failure on Azure Cosmos DB for MongoDB vCore.match index_kind:block never matched anyvector-*pattern, so HNSW/IVF tuning parameters (m,efConstruction,numList) were silently dropped.INDEX_KIND_MAP_MONGODBwas validated for membership but its mapped value was never used.Description
Updated
CosmosMongoCollection._get_index_definitionsto correctly mapfield.index_kindviaINDEX_KIND_MAP_MONGODB[field.index_kind].Also updated the unit test in
test_azure_cosmos_db_mongodb_collection.pyto assert thatcosmosSearchOptions["kind"] == "vector-hnsw"andcosmosSearchOptions["similarity"] == "COS".Contribution Checklist