Tutorial: Building a RAG Chat App with MongoDB Atlas Document Store

Learn how to build a chat system running on your data in MongoDB Atlas.

  • Level: Beginner
  • Time to complete: 20 minutes
  • Prerequisites:
  • Goal: After completing this tutorial, you will have built a chat application that runs on the sample movie dataset in MongoDB Atlas. It uses both full text search and semantic search to retrieve relevant documents.

Connect deepset to MongoDB Atlas

You need the MongoDB Atlas connection string.

  1. Log in to MongoDB Atlas and open your project overview.

  2. In the Application Development section click Get connection string, and copy the connection string in step 3.

  3. Go to deepset AI Platform, click your initials in the top right corner, and choose Connections.

    The Connections menu
  4. Scroll down to MongoDB and click Connect next to it.

  5. Paste your MongoDB connection string replacing db_password with your database password and click Connect.

Result: deepset AI Platform is connected to your MongoDB Atlas database, which means that deepset can access data in your MongoDB Atlas database.

Create a Search Index for Your MongoDB Collection

Create Full Text Search Index

First, create a full text search index for keyword searches. For details and other methods of creating the index, see Atlas Search in MongoDB Atlas documentation.

  1. In MongoDB Atlas, open your cluster, and click the Atlas Search tab.

  2. Click Create Search Index.

  3. Choose Atlas Search as the index type.

  4. Type text_index as the index name.

  5. Choose embedded_movies as the collection.

  6. Choose Visual Editor as the configuration method and click Next.

  7. Click Create Search Index.

Result: You have created a full text search index called text_search. It's listed under Atlas Search in your cluster view. You may need to wait a while until Atlas builds your index and its status changes to Ready.

Add Field Mapping

  1. On the Atlas Search tab, click More Actions next to your text index and choose Edit With Visual Editor.

  2. On the Index Overview tab, scroll down to Field Mappings, and choose Add Field Mapping.

  3. Find Field Name, choose fullplot, and click Add.

  4. Save your settings.

Result: You added fullplot as your index field. It's now showing under Index Fields in the Atlas Search tab.

Create a Vector Search Index

Now, you'll create a vector search index for semantic searches. You can also follow MongoDB Atlas documentation on Atlas Vector Search to complete this step.

  1. In MongoDB Atlas, on the Atlas Search tab, click CREATE SEARCH INDEX.

  2. Choose Vector Search as its type.

  3. Leave vector_index as the name.

  4. Choose embedded_movies as the collection.

  5. Choose Visual Editor as the configuration method and click Next.

  6. Make sure plot_embedding is chosen as the path of the Vector Field.

    the vector search index configuration
  7. Choose the similarity method and click Next.

  8. Review your vector index configuration and click Create Vector Search Index.

Result: You have create a vector search index on the plot_embedding field. The index is listed under the Atlas Search tab. You may need to wait a while until Atlas builds it and the index is ready.

The Atlas Search tab in MongoDB Atlas with two indexes listed - text index and vector index

Create a RAG Chat Application

  1. In deepset AI Platform go to Pipeline Templates.
  2. Choose the Conversational category and find the MongoDB Atlas RAG Chat GPT-4o template.
  3. Hover over the template and click Use Template.
  4. Leave the default name and click Create Pipeline.
  5. On the Pipeline Builder page, click Deploy.

Result: Congratulations! You have created a RAG chat application that uses gpt-4o and runs on the sample dataset in your MongoDB Atlas database. You can now try it out in Playground. For instructions, see Testing Your Pipeline.

📘

Indexing Status

Since MongoDB Atlas is an external document store, you won't be able to view indexing status or see which files are part of your index. However, you can access the logs for insights into the indexing process.

For details, read Document Stores.