Docs Menu
Docs Home
/ /

Build a Local RAG Implementation with MongoDB Vector Search

This tutorial demonstrates how to implement retrieval-augmented generation (RAG) locally, without the need for API keys or credits. To learn more about RAG, see Retrieval-Augmented Generation (RAG) with MongoDB.

Specifically, you perform the following actions:

  1. Create a local Atlas deployment.

  2. Set up the environment.

  3. Use a local embedding model to generate vector embeddings.

  4. Create a MongoDB Vector Search index on your data.

  5. Use a local LLM to answer questions on your data.

In addition to the common prerequisites, this tutorial requires the following:

In this section, you create local Atlas deployment loaded with the sample AirBnB listings dataset to use as a vector database.

Note

If you already have an existing local deployment or a MongoDB Community or Enterprise cluster with Search and Vector Search installed, with the sample_airbnb.listingsAndReviews sample data loaded, you can skip this step.

1

Run atlas deployments setup and follow the prompts to create a local deployment.

For detailed instructions, see Create a Local Atlas Deployment.

2
  1. Run the following command in your terminal to download the sample data:

    curl https://atlas-education.s3.amazonaws.com/sampledata.archive -o sampledata.archive
  2. Run the following command to load the data into your deployment, replacing <port-number> with the port where you're hosting the deployment:

    mongorestore --archive=sampledata.archive --port=<port-number>

In this section, you load an embedding model locally and generate vector embeddings by using data from the sample_airbnb database, which contains a collection called listingsAndReviews.

This code might take several minutes to run. After it's finished, you can view your vector embeddings by connecting to your local deployment from mongosh or your application using your deployment's connection string. Then you can run read operations on the sample_airbnb.listingsAndReviews collection.

Tip

You can convert the embeddings in the sample data to BSON vectors for efficient storage and ingestion of vectors in Atlas. To learn more, see how to convert native embeddings to BSON vectors.

To enable vector search on the sample_airbnb.listingsAndReviews collection, create a MongoDB Vector Search index.

Back

AI Agents

Earn a Skill Badge

Master "RAG with MongoDB" for free!

Learn more

On this page