> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# Integrate Atlas with Google Vertex AI

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 (Retrieval-Augmented Generation) and other uses cases such as [natural language querying.](https://www.mongodb.com/docs/atlas/ai-integrations/google-vertex-ai/extensions.md#std-label-vertex-ai-extensions)

## Overview

Vertex AI enables a variety of use cases with MongoDB Atlas:

- Use foundation models from Google with MongoDB Vector Search to build AI applications and implement RAG (Retrieval-Augmented Generation). To learn more, see [Google models.](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/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.](https://www.mongodb.com/docs/atlas/ai-integrations/google-vertex-ai/extensions.md#std-label-vertex-ai-extensions)

- 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.](https://www.mongodb.com/docs/atlas/ai-integrations/google-vertex-ai/agent-engine.md#std-label-vertex-ai-agent-engine)

## Get Started

The following sample application demonstrates how to use Vertex AI with Atlas for RAG (Retrieval-Augmented Generation). The application includes an interface that allows you to upload PDF documents and answer questions on the PDF data by using MongoDB Vector Search and Vertex AI models.

### Prerequisites

Before starting this tutorial, you must have the following:

- An [Atlas cluster](https://www.mongodb.com/docs/atlas/tutorial/create-new-cluster.md#std-label-create-new-cluster) running MongoDB version 6.0.11, 7.0.2, or later. Ensure that your IP address (Internet Protocol address) is included in your Atlas project's [access list.](https://www.mongodb.com/docs/atlas/security/ip-access-list.md#std-label-access-list)

- Access to a Google Cloud project with Vertex AI API enabled. To learn more, see [Google Cloud documentation.](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)

### Create a Google Cloud Compute Instance

Follow the steps in the [Google Cloud documentation](https://cloud.google.com/compute/docs/instances/create-start-instance#console) 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 | `vertexai-chatapp` |
| Region and Zone | Any Google Cloud region and zone near your physical location |
| Machine Configuration | Series: High Memory; Machine Type: `n1-standard-1` |
| 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 MongoDB Vector Search. To deploy and run the application on your Google Cloud VM instance, complete the following steps:

1. Create a MongoDB Vector Search index.

   You must create a MongoDB 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.](https://www.mongodb.com/docs/vector-search/indexes/vector-search-type.md#std-label-avs-types-vector-search)

2. Get the sample application.

   Connect to the VM instance by using [SSH](https://cloud.google.com/compute/docs/connect/standard-ssh). In the environment, clone the GitHub repository that contains the application code:

   ```bash
   git clone https://github.com/mongodb-partners/MongoDB-VertexAI-Qwiklab.git
   ```

   **Note:**

   To learn more about the application, see the [repository.](https://github.com//mongodb-partners/MongoDB-VertexAI-Qwiklab)

3. Install the dependencies from the cloned repository.

   Run the following commands to install the dependencies:

   ```shell
   sudo apt update
   sudo apt install python3-pip
   sudo apt install git
   cd MongoDB-VertexAI-Qwiklab
   pip3 install -r requirements.txt
   ```

4. Run the application using Streamlit.

   ```bash
   streamlit run app.py
   ```

5. Access the application.

   Open the public IP address of your VM in a web browser with the port shown in the command output.

6. 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, if you're using Atlas, you can verify your vector embeddings by navigating to the `vertexaiApp.chat-vec` namespace [in the Atlas UI.](https://www.mongodb.com/docs/atlas/atlas-ui/collections.md#std-label-atlas-ui-view-collections)

7. 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 (Retrieval-Augmented Generation) 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.
