Lesson 1: Managing Atlas Vector Search Indexes in the Atlas CLI / Learn

Video Transcript (English)

Welcome back! While there are many ways to manage vector search indexes, the Atlas CLI is one of the most popular. The Atlas CLI enables you to manage your indexes directly from CI/CD pipelines, providing streamlined automation and integration capabilities.

In this video, we’ll learn how to create, view, update, and delete vector search indexes using the Atlas CLI. Let’s get started!

First, we need to make sure that we have the proper Atlas user role for creating and managing vector search indexes.

To create vector search indexes we must have the Project Data Access Admin role or higher.

To view, manage, update, and delete vector search indexes we must have the Project Search Index Editor role or higher.

Ok, now let’s create a vector search index using the Atlas CLI. To start off, we will create a JSON file that we'll use to define the index.

Inside the JSON file, we define the database and collection that we want to use. For this example, we’re using the sample_mflix data set.

Next, we choose the type of index which in this case is vector search.

We’ll give the index an easily identifiable name like movies_vector_index.

Lastly, we’ll define the fields that we want to index. For this example, we index the plot_embedding field, which has a vector type, 1536 dimensions, and cosine similarity.

If this looks unfamiliar to you, I highly recommend that you check out the unit on Semantic Search with Vector Search.

Now that we have a JSON file that holds the vector search index definition, let’s save it.

Back in the CLI, we’ll use the Atlas clusters search indexes create command to create the index.

This command requires us to pass in the name of the cluster and the path to the JSON file where we defined the index.

Before we run the command, remember that when you're creating an index, your cluster's performance might dip a little. But once the index is fully built, things should return to normal. It’s a good idea to only run commands like this during low-traffic periods.

After running the command, we should see a confirmation message with the name of our index.

But what if we want further confirmation that the index has been built? There are a couple of ways to do this.

One way to check your indexes is with the Atlas clusters search indexes list command.

We’ll need to supply the cluster, database, and collection that has the index.

We can also choose the format of the output . Let’s go with JSON.

After running the command, we’ll receive an array holding each of our indexes. Here we only have one.

As you can see, it provides us with all kinds of information, like which collection and database the index is on.

We can also see the index ID which will come in handy a little later.

After that, we see the name of the index.

We can also check the status of the index.

And finally, we see the index definition.

If you have several indexes, checking one of them this way can be a little time-consuming. So let's go over a command that we can use to look up a specific index.

To do this, we use the Atlas clusters search indexes describe command.

For this to work, we provide the index id and the cluster it resides on.

Like before, we’ll also use JSON for the output format.

The output is similar to the previous command, except we’ll only get a single document with information about the index we specified.

Creating indexes is important but we also need to be able to update existing ones to keep up with evolving workload needs.

To do this, we can create a new JSON file or update the file with the existing index definition.

We’ll update our existing file and add a filter to our index definition.

Once we’re happy with the updated index, we save the JSON file.

Back in the CLI, we use the Atlas clusters search indexes update command to update the index.

Again, we provide the index id, which cluster it resides on, and the path to the file where the index is defined.

We’ll also use JSON for the output format of the confirmation message.

After running the command, we receive a confirmation that shows the new index definition and its status. We can see that the new filter was added in the update.

Keep in mind that while your search index is updating, the old one can still be used. But once the updated index is built, the old one is no longer usable.

Also, similar to creating an index, updating one may also temporarily have a negative impact on your cluster's performance until the update is fully completed.

Last but not least, we can delete vector search indexes using the Atlas CLI.

You should always approach deleting an index with care. Consider things like:

Is this indexed being used?

Will I have to rebuild it?

When is the best time to delete the index?

If these things aren't taken into consideration, deleting the index could have a negative impact on the performance of your application.

To do so, we’ll use the Atlas clusters search indexes delete command.

We provide the id of the index that we want to delete and the cluster that it’s on.

After running the command, we’ll be prompted to confirm our decision.

After confirming that we want to delete the index, we’ll see a message telling us that the index has been deleted.

We can get further confirmation that our vector search index has been deleted by using the list command.

As you can see, it returns an empty array which means our search index has been deleted. 

Keep in mind that it takes time for indexes to be deleted. The bigger the index, the more time it takes to be deleted.

Great work! In this video, you learned how to create, view, update, and delete vector search indexes with the Atlas CLI.

Until next time. Keep learning!