vectorindexingaws-documentdb

AWS DocumentDB vector indexing options missing apparently


I'm trying to create a vector index in DocumentDB but I keep getting an error following the documentation's example:

db.collection.createIndex(
  { "<vectorField>": "vector" },
  { "name": "<indexName>",
    "vectorOptions": {
      "dimensions": <number_of_dimensions>,
      "similarity": " <euclidean> | <cosine> | <dotProduct> ",
      "lists": <number_of_lists> 
    }
  }
);

When I try to create my index on the "embedding" field in my collection, I use the following:

db.collection.createIndex({
    embedding: 'vector',
}, {
    name: "vectorEmbeddingIdx",
    vectorOptions: {
        dimensions: 2000,
        similarity: "euclidean",
        lists: 1,
    }
})

Which results in the following error:

MongoServerError: vectorOptions input is required to create vector indexes

I've been using the almighty Google but finding little documentation on my situation. Am I missing something?


Solution

  • I discovered that the index creation only works if there are not other properties on the document that will hold the vector. The index creation should also be run using runCommand or db.command from pymongo:

    db.command({"createIndexes": <COLLECTION>, 
        "indexes": [{ 
          "key": {<VECTOR_FIELD>:"vector"}, 
          "vectorOptions": 
             {"dimensions": <N_DIMS>, 
             "similarity": "cosine",
             "lists": <N_DOCUMENTS/1000>,
             }, 
          "name": <index_name>
          }] 
        })