|
| 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 | + |
1 | 15 | import asyncio
|
2 | 16 |
|
3 | 17 | from google.adk.agents import LlmAgent
|
|
6 | 20 | from google.genai import types
|
7 | 21 | from google.adk.tools import VertexAiSearchTool
|
8 | 22 |
|
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" |
13 | 26 |
|
14 | 27 | # Constants
|
15 | 28 | APP_NAME_VSEARCH = "vertex_search_app"
|
|
20 | 33 |
|
21 | 34 | # Tool Instantiation
|
22 | 35 | # 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) |
24 | 37 |
|
25 | 38 | # Agent Definition
|
26 | 39 | doc_qa_agent = LlmAgent(
|
27 | 40 | name=AGENT_NAME_VSEARCH,
|
28 | 41 | model=GEMINI_2_FLASH, # Requires Gemini model
|
29 | 42 | 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}. |
31 | 44 | Use the search tool to find relevant information before answering.
|
32 | 45 | If the answer isn't in the documents, say that you couldn't find the information.
|
33 | 46 | """,
|
|
47 | 60 | async def call_vsearch_agent_async(query):
|
48 | 61 | print("\n--- Running Vertex AI Search Agent ---")
|
49 | 62 | 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.") |
52 | 65 | print("-" * 30)
|
53 | 66 | return
|
54 | 67 |
|
|
0 commit comments