Vector Index Issue in DocumentDB
I am trying to create a vector index for my DocumentDB. According to pymongo's documentation, you are supposed to use create_index
to do so. Whenever I drop all my indexes using drop_indexes
before initially creating or recreating my vector index, all works well. However, when I remove the drop_indexes
and try to create an index (on the pre-existing one), I get an error.
According to the documentation, the create_index
function shouldn't create an index if a pre-existing one already exists. The function will check if the index exists and if the arguments passed in are the same, if they are, the index doesn't get created and no error is thrown. This is the functionality I expect and need for my use case. However, although all settings remain the same for the vector index I'm creating, additional calls afterwards for creating the index are "going through" and actually trying to be created when nothing of the index changes.
Here is the error I receive:
Index already exists with different options, full error: {'ok': 0.0, 'operationTime': Timestamp(1723494808, 1), 'code': 85, 'errmsg': 'Index already exists with different options'}
Here is a simplified example to illustrate the issue:
# Initial index creation col.create_index( [("embedding_key", "vector")], vectorOptions={ "type": "hnsw", "similarity": "cosine", "dimensions": 128, "m": 16, "efConstruction": 64, }, name="my_vss_index", )
Attempting to create the same index again later (this isn’t my specific use case but this does mimic my case effectively)
col.create_index(
[(“embedding_key”, “vector”)],
vectorOptions={
“type”: “hnsw”,
“similarity”: “cosine”,
“dimensions”: 128,
“m”: 16,
“efConstruction”: 64,
},
name=“my_vss_index”,
)
On the other hand, creating an index with text search capability and the same use case does work as expected:
Initial text index creation
col.create_index([(“content”, “text”)], name=“my_memories_index”)
Attempting to create the same text index again later
col.create_index([(“content”, “text”)], name=“my_memories_index”)
I would appreciate any guidance on why the vector index behaves differently and how to ensure that create_index
does not recreate an existing vector index if it already exists.
Thank you!