Deploy a modern Retrieval-Augmented Generation (RAG) stack on Google Cloud using Terraform, Vertex AI, Discovery Engine, and GCS.
You can deploy this RAG solution on Google Cloud in two ways:
- Option 1: Terraform/CLI (Recommended for automation)
- Option 2: Google Cloud Console (No CLI, UI only)
Retrieval-Augmented Generation (RAG) is an AI technique that enhances Large Language Models (LLMs) by combining information retrieval with generative capabilities. Instead of relying solely on model parameters, RAG retrieves relevant external documents from a knowledge base or data store, resulting in more accurate, contextual, and up-to-date responses.
- 🏢 Google Cloud project with billing enabled
- 👤 IAM Role: Project Owner or Editor
- 🧑💻 Basic knowledge: Google Cloud, Terraform, Generative AI, LLMs, Embeddings
You can run the following commands in Google Cloud Shell or your local terminal (with
gcloudCLI configured).
git clone https://github.com/anudishu/RAG-Terraform-Vertex.git
cd RAG-Terraform-Vertexgcloud services enable \
compute.googleapis.com \
aiplatform.googleapis.com \
storage.googleapis.com \
discoveryengine.googleapis.comVerify APIs:
- Go to Google Cloud Console → Search for "AI Application"
- Navigate to the AI Applications page
- Click Continue and activate the API if prompted
- Confirm all required APIs are listed and active
Replace placeholders with your actual values and execute it one-by-one
export PROJECT_ID="your-gcp-project-id" # get your project id from google cloud console
export REGION="us-central1" # e.g. us-central1
gcloud config set project $PROJECT_IDAuthenticate your environment to allow Terraform and Python scripts to access Google Cloud services:
gcloud auth application-default loginFollow the authentication flow:
- Copy the provided link from the terminal
- Open it in your browser and login with your GCP account
- Copy the authorization code and paste it back in the terminal
Before you deploy infrastructure:
Open the
terraform.tfvarsfile and update theproject_idvariable with your actual Google Cloud project ID.project_id = "your-gcp-project-id"Save the file after making the change.
This will provision all required infrastructure on Google Cloud:
- Discovery Engine Data Store
- Discovery Engine Search Engine
terraform init
terraform plan
terraform apply -auto-approveAfter successful deployment, note the Terraform outputs:
test_data_store_id = "demo_store_id" test_engine_id = "demo_engine_app"
Open loaddata.py and set the correct project ID at the end of the file:
PROJECT_ID = "your-gcp-project-id"python loaddata.pyThis script will upload public documents (gs://cloud-samples-data/gen-app-builder/search/alphabet-investor-pdfs) into your configured Vertex AI Search data store.
Once your data is indexed:
- Send test queries using the deployed app interface (if applicable)
- Or trigger inference via Vertex AI API
- Ensure that answers reflect content from the uploaded documents
Open query.py, set the correct project ID at the end of the file, then run:
python query.pyQUERY = "who is ceo of google? what is total revenue of google?"
# More examples:
QUERY = "What were Google Cloud earnings in 2024?"
QUERY = "Google Cloud financial results and revenue growth"
QUERY = "What is Google's market capitalization and stock performance?"
QUERY = "Google advertising revenue breakdown by quarter"
QUERY = "Alphabet Inc financial highlights and key metrics"
QUERY = "Google Cloud vs AWS market share comparison"
QUERY = "What are Google's main business segments and revenue sources?"
QUERY = "Google's investment in AI and machine learning initiatives"
QUERY = "YouTube revenue and user engagement statistics"
QUERY = "Google's data center locations and infrastructure investments"To avoid incurring charges, destroy the provisioned infrastructure when no longer needed:
terraform destroy -auto-approve- Ensure your IAM permissions allow you to create and manage required resources.
- For troubleshooting, check the Google Cloud documentation or open an issue in this repo.
Happy Building! 🚀
No CLI or Terraform required! Use the Google Cloud Console UI for a fully guided, point-and-click deployment.
This guide walks you through deploying a Retrieval-Augmented Generation (RAG) application using only the Google Cloud Console (web UI). No command line or Terraform is required. Follow these steps to complete the hands-on lab:
- Go to the Google Cloud Console.
- In the top navigation bar, click the project dropdown and select an existing project or click New Project to create one.
- Ensure billing is enabled for your project. (Enable billing)
- In the left menu, go to APIs & Services > Library.
- Search for and enable each of the following APIs:
- Vertex AI API (
aiplatform.googleapis.com) - Discovery Engine API (
discoveryengine.googleapis.com) - Cloud Storage API (
storage.googleapis.com) - Compute Engine API (
compute.googleapis.com)
- Vertex AI API (
- In the Google Cloud Console, search for AI Application.
- Under Datastores, select Create Data stores.
- Select Data Source as Cloud Storage.
- Leave all settings as default. For the GCS URL, enter:
cloud-samples-data/gen-app-builder/search/alphabet-investor-pdfs
- Fill in the required details:
- Datastore Name: Enter a name for your data store.
- Click Create and wait for the data store to be provisioned.
- Note your Data Store ID for later use.
- In AI Application, go to the right-side menu and click App > Create App.
- Select Custom Search.
- Enter an App Name.
- Enter a Company Name (you can use any value).
- Click Continue.
- Attach the previously created datastore.
- Done!
Note: All steps above use only the Google Cloud Console UI. For advanced automation, see the Terraform-based instructions above.