Skip to content
Rate this page
Thanks for your feedback
Thank you! The feedback has been submitted.

Get free database assistance or contact our experts for personalized support.

Update vector search index

You can use the db.collection.updateSearchIndex() method to update a vector search index.

Warning

updateSearchIndex() replaces the index definition; it does not merge your changes into the existing one. Always submit the complete definition, including the fields you are not changing. Any field you omit is removed from the index.

You cannot rename an index with this method. To rename an index, drop it and create a new one with the desired name.

After you update an index, mongot rebuilds it in the background. The index continues to serve queries with the old definition until the rebuild completes. Use getSearchIndexes() to check the rebuild status.

Update a vector search index

db.<collection>.updateSearchIndex(
  <name>,
  {
    <definition>
  }
)

updateSearchIndex() accepts these fields:

Field Type Required Description
name string Required Name of the index to update.
definition document Required The complete replacement definition for the index. This replaces the existing definition; it is not merged with it.
Add category as a filter field to products_vector_idx

Suppose products_vector_idx currently indexes the embedding field. The following operation adds category as a filter field.

db.products.updateSearchIndex(
  "products_vector_idx",
  {
    fields: [
      {
        type: "vector",
        path: "embedding",
        numDimensions: 768,
        similarity: "cosine"
      },
      {
        type: "filter",
        path: "category"
      }
    ]
  }
);
What happens under the hood

When you update the index

  1. mongod forwards the updated definition to mongot.
  2. mongot builds a new version of the index in the background. The existing index remains available for queries while the rebuild is in progress.
  3. The new index contains the embedding vectors and the category values. During a filtered vector query, category narrows the documents considered for similarity search. It does not affect the vector similarity score.
  4. When the rebuild finishes, the new index replaces the previous version.

Next steps

Delete a search index