Docs Menu
Docs Home
/
MongoDB Atlas
/

Atlas Vector Search Quick Start

On this page

  • Objectives
  • Prerequisites
  • Index Vector Embeddings
  • Run a Vector Search Query

This quick start describes how to index vector embeddings in your data on an Atlas cluster and run queries that search vector embeddings for similar data.

A vector is an array of values arranged in one or more dimensions. Vector embeddings that bidirectional encoder models, like OpenAI text-embedding-ada-002, produce can represent words, phrases, and sentences. You can index vector embeddings and search for items related in meaning or context. To learn more, see Atlas Vector Search Overview.

In this quick start, you will do the following steps:

  1. Create an index definition for the sample_mflix.embedded_movies collection that indexes the plot_embedding field as the vector type. The plot_embedding field contains embeddings created using OpenAI's text-embedding-ada-002 embeddings model. The index definition specifies 1536 vector dimensions and measure similarity using cosine.

  2. Run an Atlas Vector Search query that searches the sample sample_mflix.embedded_movies collection. The query uses the $vectorSearch stage to search the plot_embedding field, which contains embeddings created using OpenAI's text-embedding-ada-002 embeddings model. The query searches the plot_embedding field using vector embeddings for the string time travel. It considers up to 150 nearest neighbors, and returns 10 documents in the results.

To complete this quick start, you must meet the following prerequisites.

You must have the following cluster configuration:

  • An Atlas cluster with MongoDB version 6.0.11, or v7.0.2 or later (including RCs).

  • The sample data loaded into your Atlas cluster.

You must have one of the following applications to run queries on your Atlas cluster:

  • mongosh

  • C#

  • Java

  • MongoDB Node Driver

  • Pymongo

You can also use Atlas Vector Search with local Atlas deployments that you create with the Atlas CLI. To learn more, see Create a Local Atlas Deployment.

To create an Atlas Vector Search index, you must have Project Data Access Admin or higher access to the project.

Use the following example to index vector embeddings in your data on an Atlas cluster.

1
  1. If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.

  2. If it is not already displayed, select your desired project from the Projects menu in the navigation bar.

  3. If the Clusters page is not already displayed, click Database in the sidebar.

2
  1. Click your cluster's name.

  2. Click the Atlas Search tab.

3
  1. Click Create Search Index.

  2. In the Atlas Vector Search section, select JSON Editor.

  3. Click Next.

4
  1. In the Database and Collection section, find the sample_mflix database, and select the embedded_movies collection.

  2. In the Index Name field, specify vector_index.

5

The following example index definition for the sample_mflix.embedded_movies collection indexes the plot_embedding field as the vector type. The plot_embedding field contains embeddings created using OpenAI's text-embedding-ada-002 embeddings model. The index definition specifies 1536 vector dimensions and measures similarity using cosine.

1{
2 "fields": [{
3 "type": "vector",
4 "path": "plot_embedding",
5 "numDimensions": 1536,
6 "similarity": "cosine"
7 }]
8}

To learn more, see How to Index Fields for Vector Search.

6

Review the index definition and click Create Search Index.

A modal window indicates that your index is building.

7

Click Close to close the You're All Set! modal window and wait for the index to finish building.

The index should take about one minute to build. While it builds, the Status column reads Initial Sync. When it finishes building, the Status column reads Active.

Use the following example to run a query that searches vector embeddings.


Use the Select your language drop-down menu to select the client to use to run the example queries in this section.


← Atlas Vector Search