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-2.5-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
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno google-genai
3
Export environment variables
export GOOGLE_CLOUD_LOCATION="your_google_cloud_location_here"
export GOOGLE_CLOUD_PROJECT="your_google_cloud_project_here"
$Env:GOOGLE_CLOUD_LOCATION="your_google_cloud_location_here"
$Env:GOOGLE_CLOUD_PROJECT="your_google_cloud_project_here"
4
Authenticate with Google Cloud
Sign in with Application Default Credentials:
gcloud auth application-default login
5
Run the example
Save the code above as
vertex_ai_search.py, then run:python vertex_ai_search.py