Vertex AI Search with Gemini

Vertex AI Search allows Gemini to search through your data stores, providing grounded responses based on your private knowledge base.

vertex_ai_search.py
"""Vertex AI Search with Gemini.

Vertex AI Search allows Gemini to search through your data stores,
providing grounded responses based on your private knowledge base.

Prerequisites:
1. Set up Vertex AI Search datastore in Google Cloud Console
2. Export environment variables:
   export GOOGLE_GENAI_USE_VERTEXAI="true"
   export GOOGLE_CLOUD_PROJECT="your-project-id"
   export GOOGLE_CLOUD_LOCATION="your-location"

Run `uv pip install google-generativeai` to install dependencies.
"""

from agno.agent import Agent
from agno.models.google import Gemini

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

# Replace with your actual Vertex AI Search datastore ID
# Format: "projects/{project_id}/locations/{location}/collections/default_collection/dataStores/{datastore_id}"
datastore_id = "projects/your-project-id/locations/global/collections/default_collection/dataStores/your-datastore-id"

agent = Agent(
    model=Gemini(
        id="gemini-3.7-flash",
        vertexai_search=True,
        vertexai_search_datastore=datastore_id,
        vertexai=True,  # Use Vertex AI endpoint
    ),
    markdown=True,
)

# Ask questions that can be answered from your knowledge base
agent.print_response("What are our company's policies regarding remote work?")

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno google-genai

Export environment variables

export GOOGLE_CLOUD_LOCATION="global"
export GOOGLE_CLOUD_PROJECT="your_google_cloud_project_here"

Authenticate with Google Cloud

Sign in with Application Default Credentials:

gcloud auth application-default login

Select your search datastore

Replace datastore_id with your populated Vertex AI Search datastore resource name and give the configured Google identity access to it.

Run the example

Save the code above as vertex_ai_search.py, then run:

python vertex_ai_search.py

Full source: cookbook/90_models/google/gemini/vertex_ai_search.py