Building RAG Pipelines With Haystack and MongoDB Atlas
Pavel Duchovny4 min read • Published Sep 18, 2024 • Updated Sep 18, 2024
SNIPPET
Rate this quickstart
Integrating Haystack with MongoDB Atlas allows you to build powerful retrieval-augmented generation (RAG) pipelines. This introductory article will guide you through the process of setting up a Haystack-based RAG pipeline using MongoDB Atlas for vector search. Our code will use a grocery product dataset and the RAG pipeline can fetch relevant products for a user cooking request. Relevant groceries are passed to the LLM for a detailed generated guide.
First, install the necessary dependencies:
If you have not created an Atlas cluster, follow our guide.
Set the MongoDB connection string and
OpenAI API key by following the guide on Open AI website.
Create a vector index on your database and collection in MongoDB Atlas. For more information and guidance, visit our Atlas Vector Search index docs. In this tutorial, the database is “ai_shop,”, and the collection name is “test_collection.”. Ensure that the index name is vector_index and specify the following syntax:
Load documents into MongoDB Atlas using the Haystack framework:
Create a pipeline that will retrieve, augment, and generate a response to user questions:
Test the pipeline with a sample query:
Expected output:
In this article, you learned how to integrate Haystack with MongoDB Atlas to build a RAG pipeline. This powerful combination allows you to leverage vector search and retrieval-augmented generation to create sophisticated and responsive applications.
To explore more topics on RAG, have a look at the following tutorials:
If you have questions or want to connect with other developers, join us in the MongoDB Developer Community. Thanks for reading.