Skip to content

Commit da6d18f

Browse files
authored
chore: Updated code sample to genericize region in datastore ID (#622)
* Updated code sample to genericize region in datastore ID * Added licensing information.
1 parent 7f28b00 commit da6d18f

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

examples/python/snippets/tools/built-in-tools/vertexai_search.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
import asyncio
216

317
from google.adk.agents import LlmAgent
@@ -6,10 +20,9 @@
620
from google.genai import types
721
from google.adk.tools import VertexAiSearchTool
822

9-
# Replace with your actual Vertex AI Search Datastore ID
10-
# Format: projects/<PROJECT_ID>/locations/<LOCATION>/collections/default_collection/dataStores/<DATASTORE_ID>
11-
# e.g., "projects/12345/locations/us-central1/collections/default_collection/dataStores/my-datastore-123"
12-
YOUR_DATASTORE_ID = "YOUR_DATASTORE_ID_HERE"
23+
# Replace with your Vertex AI Search Datastore ID, and respective region (e.g. us-central1 or global).
24+
# Format: projects/<PROJECT_ID>/locations/<REGION>/collections/default_collection/dataStores/<DATASTORE_ID>
25+
DATASTORE_PATH = "DATASTORE_PATH_HERE"
1326

1427
# Constants
1528
APP_NAME_VSEARCH = "vertex_search_app"
@@ -20,14 +33,14 @@
2033

2134
# Tool Instantiation
2235
# You MUST provide your datastore ID here.
23-
vertex_search_tool = VertexAiSearchTool(data_store_id=YOUR_DATASTORE_ID)
36+
vertex_search_tool = VertexAiSearchTool(data_store_id=DATASTORE_PATH)
2437

2538
# Agent Definition
2639
doc_qa_agent = LlmAgent(
2740
name=AGENT_NAME_VSEARCH,
2841
model=GEMINI_2_FLASH, # Requires Gemini model
2942
tools=[vertex_search_tool],
30-
instruction=f"""You are a helpful assistant that answers questions based on information found in the document store: {YOUR_DATASTORE_ID}.
43+
instruction=f"""You are a helpful assistant that answers questions based on information found in the document store: {DATASTORE_PATH}.
3144
Use the search tool to find relevant information before answering.
3245
If the answer isn't in the documents, say that you couldn't find the information.
3346
""",
@@ -47,8 +60,8 @@
4760
async def call_vsearch_agent_async(query):
4861
print("\n--- Running Vertex AI Search Agent ---")
4962
print(f"Query: {query}")
50-
if "YOUR_DATASTORE_ID_HERE" in YOUR_DATASTORE_ID:
51-
print("Skipping execution: Please replace YOUR_DATASTORE_ID_HERE with your actual datastore ID.")
63+
if "DATASTORE_PATH_HERE" in DATASTORE_PATH:
64+
print("Skipping execution: Please replace DATASTORE_PATH_HERE with your actual datastore ID.")
5265
print("-" * 30)
5366
return
5467

0 commit comments

Comments
 (0)