Integrate Atlas with Google Vertex AI
On this page
You can integrate Vertex AI with MongoDB Atlas to build and deploy AI applications. The Vertex AI platform includes several tools and pre-trained models from Google that you can use with Atlas for RAG and other uses cases such as natural language querying.
Overview
Vertex AI enables a variety of use cases with MongoDB Atlas:
Use foundation models from Google with Atlas Vector Search to build AI applications and implement RAG. To learn more, see Google models.
Use Vertex AI extensions to customize how Google models interact with Atlas. To get started, see Use Vertex AI Extensions for Natural Language MongoDB Queries.
Use the Vertex AI Agent Engine to build and scale AI agents with Atlas as the database. To get started, see Build AI Agents with Vertex AI Agent Engine and Atlas.
Get Started
The following sample application demonstrates how to use Vertex AI with Atlas for RAG. The application includes an interface that allows you to upload PDF documents and answer questions on the PDF data by using Atlas Vector Search and Vertex AI models.
Prerequisites
Before starting this tutorial, you must have the following:
An Atlas account with a cluster running MongoDB version 6.0.11, 7.0.2, or later (including RCs). Ensure that your IP address is included in your Atlas project's access list. To learn more, see Create a Cluster.
Access to a Google Cloud project with Vertex AI API enabled. To learn more, see Google Cloud documentation.
Create a Google Cloud Compute Instance
Follow the steps in the Google Cloud documentation to create and start a virtual machine (VM) instance in your Google Cloud console. Configure the Google Cloud VM instance with the following settings and use the default settings for the remaining options:
Option | Configuration |
---|---|
Name |
|
Region and Zone | Any Google Cloud region and zone near your physical location |
Machine Configuration |
|
Boot disk | Size: 100 GB |
Access | Allow full access to all Cloud APIs |
Firewall | Select all |
Networking | For the External IP range, specify Reserve external static IP address |
Deploy and Run the Application
This section loads a sample application that you can use to transform and store PDFs in Atlas and query them using Atlas Vector Search. To deploy and run the application on your Google Cloud VM instance, complete the following steps:
Create an Atlas Vector Search index.
You must create an Atlas Vector Search index named vector_index
on the vertexaiApp.chat-vec
namespace
in your Atlas cluster to enable queries against
your vector embeddings. Use the default settings
and specify 768
dimensions.
To learn more, see How to Index Fields for Vector Search.
Get the sample application.
Connect to the VM instance by using SSH. In the environment, clone the GitHub repository that contains the application code:
git clone https://github.com/mongodb-partners/MongoDB-VertexAI-Qwiklab.git
Note
To learn more about the application, see the repository.
Upload PDF documents by using the application's interface.
In the application, upload PDF data that you want to search.
The repository includes a sample PDF file that you can use. The app chunks the data into batches, converts each chunk into vector embeddings by using an embedding model from Vertex AI, and ingests this data into your Atlas collection.
Tip
After uploading the file, you can
view your vector embeddings in the Atlas UI
by navigating to the vertexaiApp.chat-vec
collection in your cluster.
Answer questions on your data.
In the application, click the Q&A tab.
Enter a question in the search bar, and then press Enter.
The application performs RAG by running a vector search query on your collection to retrieve the most relevant documents, and then uses a chat model from Vertex AI to generate a context-aware response.