Skip to content

Commit 302a01c

Browse files
docs(samples): Update Vertex AI Gemini Grounding with new syntax from v1.64.0 (GoogleCloudPlatform#12537)
* docs(samples): Update Vertex AI Gemini Grounding with new syntax from v1.64.0 - https://github.com/googleapis/python-aiplatform/releases/tag/v1.64.0 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Updated testing --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent b679b73 commit 302a01c

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

generative_ai/gemini_grounding_example.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,34 @@ def generate_text_with_grounding_web() -> GenerationResponse:
5353

5454

5555
def generate_text_with_grounding_vertex_ai_search(
56-
data_store_path: str,
56+
data_store_id: str,
5757
) -> GenerationResponse:
5858
# [START generativeaionvertexai_gemini_grounding_with_vais]
5959
import vertexai
6060

61-
from vertexai.preview.generative_models import grounding
62-
from vertexai.generative_models import GenerationConfig, GenerativeModel, Tool
61+
from vertexai.preview.generative_models import (
62+
GenerationConfig,
63+
GenerativeModel,
64+
Tool,
65+
grounding,
66+
)
6367

6468
# TODO (developer): update project_id
6569
vertexai.init(project=PROJECT_ID, location="us-central1")
6670

6771
model = GenerativeModel("gemini-1.5-flash-001")
6872

69-
# TODO(developer): Update and un-comment below line with the correct data store path
70-
# data_store_path = "projects/{project_id}/locations/{location}/collections/default_collection/dataStores/{data_store_id}"
73+
# TODO(developer): Update project id, location, and data store id for your Vertex AI Search data store.
74+
# data_store_id = "DATA_STORE_ID"
75+
7176
tool = Tool.from_retrieval(
72-
grounding.Retrieval(grounding.VertexAISearch(datastore=data_store_path))
77+
grounding.Retrieval(
78+
grounding.VertexAISearch(
79+
datastore=data_store_id,
80+
project=PROJECT_ID,
81+
location="global",
82+
)
83+
)
7384
)
7485

7586
prompt = "How do I make an appointment to renew my driver's license?"

generative_ai/requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ pandas==2.0.3; python_version == '3.8'
33
pandas==2.1.4; python_version > '3.8'
44
pillow==9.5.0; python_version < '3.8'
55
pillow==10.3.0; python_version >= '3.8'
6-
# google-cloud-aiplatform[pipelines,rapid_evaluation,reasoningengine,tokenization]==1.57.0
7-
google-cloud-aiplatform[all]==1.63.0
6+
google-cloud-aiplatform[all]==1.64.0
87
sentencepiece==0.2.0
98
google-auth==2.29.0
109
anthropic[vertex]==0.28.0
1110
langchain-core==0.2.11
1211
langchain-google-vertexai==1.0.6
1312
numpy<2
1413
openai==1.30.5
15-
immutabledict==4.2.0
14+
immutabledict==4.2.0

generative_ai/test_gemini_examples.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,8 @@ def test_gemini_grounding_web_example() -> None:
136136

137137

138138
def test_gemini_grounding_vais_example() -> None:
139-
data_store_path = f"projects/{PROJECT_ID}/locations/global/collections/default_collection/dataStores/grounding-test-datastore"
140139
response = gemini_grounding_example.generate_text_with_grounding_vertex_ai_search(
141-
data_store_path=data_store_path,
140+
"grounding-test-datastore"
142141
)
143142
assert response
144143

0 commit comments

Comments
 (0)