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 55 Reputation points

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"]

  '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',
        'dim': 1536,
        'metric': 'cosine',
        'numLists': 1000

for index in vector_collection.list_indexes():
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,440 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 55 Reputation points

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

  3. GeethaThatipatri-MSFT 27,017 Reputation points Microsoft Employee

    @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.



    0 comments No comments