I already created an Index for MongoDB vCore, but when I query that database, I get the error 'Similarity index was not found for a vector similarity search query'

Tyler Suard 95 Reputation points
2024-04-01T16:43:18.56+00:00

Here is my code for creating the collection. When I run it, I see that an index was created. However, when I try to query the database using a vector, it says that there is no index, as in the error above:

import pymongo
import openai
from openai import AzureOpenAI
import json
import ast
import re

vector_mongo_client = pymongo.MongoClient("<credentials")
vector_db = vector_mongo_client["WCS_vectordb"]
vector_collection = vector_db["WCS_parts_vector_collection"]

vector_db.command({
  'createIndexes': 'WCS_parts_vector_collection',
  'indexes': [
    {
      'name': 'ProductGPT_vector_index',
      'key': {
        "Vector": "cosmosSearch"
      },
      'cosmosSearchOptions': {
        'kind': 'vector-ivf',
        'numLists': 800,
        'similarity': 'COS',
        'dimensions': 1536
      }
    }
  ]
})


index = {
    'vectors': 'Vector',
    'type': 'vector-ivf',
    'params':{
        'dim': 1536,
        'metric': 'cosine',
        'numLists': 1000
    }
}

for index in vector_collection.list_indexes():
    print(index)
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,699 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Tyler Suard 95 Reputation points
    2024-04-05T17:10:29.34+00:00

    I was trying to connect to the wrong database and collection.


  3. GeethaThatipatri-MSFT 29,487 Reputation points Microsoft Employee
    2024-04-22T18:09:20.0033333+00:00

    @Tyler Suard I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue: You have created an index for MongoDB vCore, but when you query the database using a vector, you are getting the error "Similarity index was not found for a vector similarity search query."

    Solution: As you mentioned you have set the wrong database and collection and by correcting your issue got resolved.

    If you have any other questions or are still running into more issues, please let me know.

    Please remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution.

    Regards

    Geetha

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.