Skip to main content

馃憪 Create a vector search index

To retrieve documents from MongoDB using vector search, you must configure a vector search index on the collection into which you ingested your data.

You can create vector search indexes using the Atlas web UI, Atlas CLI, Compass, or any MongoDB driver. We'll create a vector search index using the Python driver.

Fill in any <CODE_BLOCK_N> placeholders and run the cells under the Step 5: Create a vector search index section in the notebook to create a vector search index on the books collection.

The answers for code blocks in this section are as follows:

CODE_BLOCK_8

Answer
collection.create_search_index(model=model)

To verify that the index was created, navigate to the Overview page in the Atlas UI. In the Clusters section, select your cluster and click Browse collections.

Browse collections

Navigate to Search Indexes for the books collection in the mongodb_genai_devday database.

Navigate to search indexes

The index is ready to use once the status changes from PENDING to READY.

Index ready to use