From 037fcac7733e3a9c10a4778973deaf13fea9bade Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Mon, 26 Oct 2026 00:10:10 +0000 Subject: [PATCH] fix(generative_ai): update models, SDK configs, and RAG region across chat_completions, rag, and model_garden Problem: Several samples in generative_ai/chat_completions, generative_ai/rag, and generative_ai/model_garden were failing due to retired model versions, outdated SDK imports/configurations, and regional tier defaults: 1. generative_ai/chat_completions samples referenced retired Gemini 1.5 models on regional endpoints and constructed single-turn tool-call conversations without appending the assistant tool_calls message. 2. generative_ai/model_garden Anthropic Claude samples referenced retired claude-3-5-sonnet-v2@20241022 and pinned an older anthropic[vertex] dependency. 3. generative_ai/rag samples referenced retired text-embedding-004 and gemini-2.0-flash-001 models, used outdated google.genai imports or non-existent client.files/client.corpora methods, passed both gcs_source and google_drive_source simultaneously in ImportRagFilesConfig (violating the API oneof constraint), omitted api_auth in Pinecone/Weaviate corpus creation configs, and defaulted to us-central1 (where Spanner-backed Basic tier requires allowlisting for new projects). Solution: - generative_ai/chat_completions (9 files): Update all OpenAI-compatible Vertex AI samples to use google/gemini-3.8-flash on the global endpoint, fix the two-turn function calling conversation flow in basic and config samples, and update test assertions in chat_completions_test.py. - generative_ai/model_garden (4 files): Update Claude samples from claude-3-5-sonnet-v2@20241022 to claude-sonnet-4-6 and bump anthropic[vertex] to 2.2.0. - generative_ai/rag (20 files): - Unify all RAG Engine samples on the unrestricted GA region us-east5 with a reference comment to the RAG Engine supported-regions documentation. - Update embedding model references from text-embedding-004 to text-embedding-005 and generation model references to gemini-3.8-flash. - Fix SDK methods (client.rag.delete_corpus, client.rag.get_corpus, client.rag.delete_file, client.rag.get_file, client.rag.list_files, client.rag.upload_file), genai_types imports, and ImportRagFilesConfig GCS source configuration. - Wire ApiAuth into RagVectorDbConfig in Pinecone and Weaviate corpus creation samples, and move rag_embedding_model_config inside RagVectorDbConfig in create_corpus_weaviate_example.py. - Update generative_ai/rag/requirements.txt to google-cloud-aiplatform==2.6.0 and google-genai==2.29.0. --- .../chat_completions_authentication.py | 6 ++-- .../chat_completions_credentials_refresher.py | 8 ++--- ...chat_completions_function_calling_basic.py | 13 ++++---- ...hat_completions_function_calling_config.py | 13 ++++---- .../chat_completions_non_streaming_image.py | 8 ++--- .../chat_completions_non_streaming_text.py | 8 ++--- .../chat_completions_streaming_image.py | 8 ++--- .../chat_completions_streaming_text.py | 8 ++--- .../chat_completions/chat_completions_test.py | 19 +++++++++-- .../claude_3_streaming_example.py | 2 +- .../model_garden/claude_3_tool_example.py | 2 +- .../model_garden/claude_3_unary_example.py | 2 +- generative_ai/model_garden/requirements.txt | 2 +- generative_ai/rag/create_corpus_example.py | 5 +-- .../create_corpus_feature_store_example.py | 5 +-- .../rag/create_corpus_pinecone_example.py | 13 +++++--- .../create_corpus_vector_search_example.py | 6 ++-- .../create_corpus_vertex_ai_search_example.py | 5 +-- .../rag/create_corpus_weaviate_example.py | 16 ++++++--- generative_ai/rag/delete_corpus_example.py | 11 ++++--- generative_ai/rag/delete_file_example.py | 11 ++++--- generative_ai/rag/generate_content_example.py | 12 +++---- generative_ai/rag/get_corpus_example.py | 11 ++++--- generative_ai/rag/get_file_example.py | 11 ++++--- .../rag/import_files_async_example.py | 33 +++++++------------ generative_ai/rag/import_files_example.py | 33 +++++++------------ generative_ai/rag/list_corpora_example.py | 5 +-- generative_ai/rag/list_files_example.py | 13 ++++---- generative_ai/rag/quickstart_example.py | 27 +++++++-------- generative_ai/rag/requirements.txt | 3 +- generative_ai/rag/retrieval_query_example.py | 9 ++--- generative_ai/rag/test_rag_examples.py | 4 +-- generative_ai/rag/upload_file_example.py | 11 ++++--- 33 files changed, 179 insertions(+), 164 deletions(-) diff --git a/generative_ai/chat_completions/chat_completions_authentication.py b/generative_ai/chat_completions/chat_completions_authentication.py index aae029c2163..08a7c01603f 100644 --- a/generative_ai/chat_completions/chat_completions_authentication.py +++ b/generative_ai/chat_completions/chat_completions_authentication.py @@ -13,7 +13,7 @@ # limitations under the License. -def generate_text(project_id: str, location: str = "us-central1") -> object: +def generate_text(project_id: str, location: str = "global") -> object: # [START generativeaionvertexai_gemini_chat_completions_authentication] import openai @@ -22,7 +22,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # TODO(developer): Update and un-comment below lines # project_id = "PROJECT_ID" - # location = "us-central1" + # location = "global" # Programmatically get an access token credentials, _ = default(scopes=["https://www.googleapis.com/auth/cloud-platform"]) @@ -42,7 +42,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # OpenAI Client client = openai.OpenAI( - base_url=f"https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/{ENDPOINT_ID}", + base_url=f"https://aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/{ENDPOINT_ID}", api_key=credentials.token, ) # [END generativeaionvertexai_gemini_chat_completions_authentication] diff --git a/generative_ai/chat_completions/chat_completions_credentials_refresher.py b/generative_ai/chat_completions/chat_completions_credentials_refresher.py index a60d2391a1c..212b8d21f36 100644 --- a/generative_ai/chat_completions/chat_completions_credentials_refresher.py +++ b/generative_ai/chat_completions/chat_completions_credentials_refresher.py @@ -43,19 +43,19 @@ def __getattr__(self, name: str) -> Any: # [END generativeaionvertexai_credentials_refresher] -def generate_text(project_id: str, location: str = "us-central1") -> object: +def generate_text(project_id: str, location: str = "global") -> object: # [START generativeaionvertexai_credentials_refresher] # TODO(developer): Update and un-comment below lines # project_id = "PROJECT_ID" - # location = "us-central1" + # location = "global" client = OpenAICredentialsRefresher( - base_url=f"https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", + base_url=f"https://aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", ) response = client.chat.completions.create( - model="google/gemini-2.0-flash-001", + model="google/gemini-3.8-flash", messages=[{"role": "user", "content": "Why is the sky blue?"}], ) diff --git a/generative_ai/chat_completions/chat_completions_function_calling_basic.py b/generative_ai/chat_completions/chat_completions_function_calling_basic.py index d64c9aa1494..a59514a1b5d 100644 --- a/generative_ai/chat_completions/chat_completions_function_calling_basic.py +++ b/generative_ai/chat_completions/chat_completions_function_calling_basic.py @@ -19,22 +19,21 @@ def generate_text() -> object: # [START generativeaionvertexai_gemini_chat_completions_function_calling_basic] + from google.auth import default + import google.auth.transport.requests import openai - from google.auth import default, transport - # TODO(developer): Update & uncomment below line # PROJECT_ID = "your-project-id" - location = "us-central1" + location = "global" # Programmatically get an access token credentials, _ = default(scopes=["https://www.googleapis.com/auth/cloud-platform"]) - auth_request = transport.requests.Request() - credentials.refresh(auth_request) + credentials.refresh(google.auth.transport.requests.Request()) # # OpenAI Client client = openai.OpenAI( - base_url=f"https://{location}-aiplatform.googleapis.com/v1beta1/projects/{PROJECT_ID}/locations/{location}/endpoints/openapi", + base_url=f"https://aiplatform.googleapis.com/v1beta1/projects/{PROJECT_ID}/locations/{location}/endpoints/openapi", api_key=credentials.token, ) @@ -68,7 +67,7 @@ def generate_text() -> object: messages.append({"role": "user", "content": "What is the weather in Boston?"}) response = client.chat.completions.create( - model="google/gemini-2.0-flash-001", + model="google/gemini-3.8-flash", messages=messages, tools=tools, ) diff --git a/generative_ai/chat_completions/chat_completions_function_calling_config.py b/generative_ai/chat_completions/chat_completions_function_calling_config.py index 80b00ac993d..e514c2fbabb 100644 --- a/generative_ai/chat_completions/chat_completions_function_calling_config.py +++ b/generative_ai/chat_completions/chat_completions_function_calling_config.py @@ -19,22 +19,21 @@ def generate_text() -> object: # [START generativeaionvertexai_gemini_chat_completions_function_calling_config] + from google.auth import default + import google.auth.transport.requests import openai - from google.auth import default, transport - # TODO(developer): Update & uncomment below line # PROJECT_ID = "your-project-id" - location = "us-central1" + location = "global" # Programmatically get an access token credentials, _ = default(scopes=["https://www.googleapis.com/auth/cloud-platform"]) - auth_request = transport.requests.Request() - credentials.refresh(auth_request) + credentials.refresh(google.auth.transport.requests.Request()) # OpenAI Client client = openai.OpenAI( - base_url=f"https://{location}-aiplatform.googleapis.com/v1beta1/projects/{PROJECT_ID}/locations/{location}/endpoints/openapi", + base_url=f"https://aiplatform.googleapis.com/v1beta1/projects/{PROJECT_ID}/locations/{location}/endpoints/openapi", api_key=credentials.token, ) @@ -68,7 +67,7 @@ def generate_text() -> object: messages.append({"role": "user", "content": "What is the weather in Boston, MA?"}) response = client.chat.completions.create( - model="google/gemini-2.0-flash-001", + model="google/gemini-3.8-flash", messages=messages, tools=tools, tool_choice="auto", diff --git a/generative_ai/chat_completions/chat_completions_non_streaming_image.py b/generative_ai/chat_completions/chat_completions_non_streaming_image.py index 2bfe8cf96fa..5ceaeabc749 100644 --- a/generative_ai/chat_completions/chat_completions_non_streaming_image.py +++ b/generative_ai/chat_completions/chat_completions_non_streaming_image.py @@ -13,7 +13,7 @@ # limitations under the License. -def generate_text(project_id: str, location: str = "us-central1") -> object: +def generate_text(project_id: str, location: str = "global") -> object: # [START generativeaionvertexai_gemini_chat_completions_non_streaming_image] from google.auth import default @@ -23,7 +23,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # TODO(developer): Update and un-comment below lines # project_id = "PROJECT_ID" - # location = "us-central1" + # location = "global" # Programmatically get an access token credentials, _ = default(scopes=["https://www.googleapis.com/auth/cloud-platform"]) @@ -31,12 +31,12 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # OpenAI Client client = openai.OpenAI( - base_url=f"https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", + base_url=f"https://aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", api_key=credentials.token, ) response = client.chat.completions.create( - model="google/gemini-2.0-flash-001", + model="google/gemini-3.8-flash", messages=[ { "role": "user", diff --git a/generative_ai/chat_completions/chat_completions_non_streaming_text.py b/generative_ai/chat_completions/chat_completions_non_streaming_text.py index 20de139d62c..aacfc1d233b 100644 --- a/generative_ai/chat_completions/chat_completions_non_streaming_text.py +++ b/generative_ai/chat_completions/chat_completions_non_streaming_text.py @@ -13,7 +13,7 @@ # limitations under the License. -def generate_text(project_id: str, location: str = "us-central1") -> object: +def generate_text(project_id: str, location: str = "global") -> object: # [START generativeaionvertexai_gemini_chat_completions_non_streaming] from google.auth import default import google.auth.transport.requests @@ -22,7 +22,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # TODO(developer): Update and un-comment below lines # project_id = "PROJECT_ID" - # location = "us-central1" + # location = "global" # Programmatically get an access token credentials, _ = default(scopes=["https://www.googleapis.com/auth/cloud-platform"]) @@ -30,12 +30,12 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # OpenAI Client client = openai.OpenAI( - base_url=f"https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", + base_url=f"https://aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", api_key=credentials.token, ) response = client.chat.completions.create( - model="google/gemini-2.0-flash-001", + model="google/gemini-3.8-flash", messages=[{"role": "user", "content": "Why is the sky blue?"}], ) diff --git a/generative_ai/chat_completions/chat_completions_streaming_image.py b/generative_ai/chat_completions/chat_completions_streaming_image.py index 05630ef15fe..4d2a4cbce76 100644 --- a/generative_ai/chat_completions/chat_completions_streaming_image.py +++ b/generative_ai/chat_completions/chat_completions_streaming_image.py @@ -13,7 +13,7 @@ # limitations under the License. -def generate_text(project_id: str, location: str = "us-central1") -> object: +def generate_text(project_id: str, location: str = "global") -> object: # [START generativeaionvertexai_gemini_chat_completions_streaming_image] from google.auth import default import google.auth.transport.requests @@ -22,7 +22,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # TODO(developer): Update and un-comment below lines # project_id = "PROJECT_ID" - # location = "us-central1" + # location = "global" # Programmatically get an access token credentials, _ = default(scopes=["https://www.googleapis.com/auth/cloud-platform"]) @@ -30,12 +30,12 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # OpenAI Client client = openai.OpenAI( - base_url=f"https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", + base_url=f"https://aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", api_key=credentials.token, ) response = client.chat.completions.create( - model="google/gemini-2.0-flash-001", + model="google/gemini-3.8-flash", messages=[ { "role": "user", diff --git a/generative_ai/chat_completions/chat_completions_streaming_text.py b/generative_ai/chat_completions/chat_completions_streaming_text.py index 42e98809ad9..1b3300daae7 100644 --- a/generative_ai/chat_completions/chat_completions_streaming_text.py +++ b/generative_ai/chat_completions/chat_completions_streaming_text.py @@ -13,7 +13,7 @@ # limitations under the License. -def generate_text(project_id: str, location: str = "us-central1") -> object: +def generate_text(project_id: str, location: str = "global") -> object: # [START generativeaionvertexai_gemini_chat_completions_streaming] from google.auth import default import google.auth.transport.requests @@ -22,7 +22,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # TODO(developer): Update and un-comment below lines # project_id = "PROJECT_ID" - # location = "us-central1" + # location = "global" # Programmatically get an access token credentials, _ = default(scopes=["https://www.googleapis.com/auth/cloud-platform"]) @@ -30,12 +30,12 @@ def generate_text(project_id: str, location: str = "us-central1") -> object: # OpenAI Client client = openai.OpenAI( - base_url=f"https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", + base_url=f"https://aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi", api_key=credentials.token, ) response = client.chat.completions.create( - model="google/gemini-2.0-flash-001", + model="google/gemini-3.8-flash", messages=[{"role": "user", "content": "Why is the sky blue?"}], stream=True, ) diff --git a/generative_ai/chat_completions/chat_completions_test.py b/generative_ai/chat_completions/chat_completions_test.py index 56489b53fcf..29ce4bdf328 100644 --- a/generative_ai/chat_completions/chat_completions_test.py +++ b/generative_ai/chat_completions/chat_completions_test.py @@ -16,6 +16,8 @@ import chat_completions_authentication import chat_completions_credentials_refresher +import chat_completions_function_calling_basic +import chat_completions_function_calling_config import chat_completions_non_streaming_image import chat_completions_non_streaming_text import chat_completions_non_streaming_text_self_deployed @@ -25,7 +27,8 @@ PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") -LOCATION = "us-central1" +LOCATION = "global" +SELF_DEPLOYED_LOCATION = "us-central1" SELF_HOSTED_MODEL_ID = "google/gemma-2-9b-it" ENDPOINT_ID = "6714120476014149632" @@ -62,15 +65,25 @@ def test_credentials_refresher() -> None: assert response +def test_function_calling_basic() -> None: + response = chat_completions_function_calling_basic.generate_text() + assert response + + +def test_function_calling_config() -> None: + response = chat_completions_function_calling_config.generate_text() + assert response + + def test_streaming_text_self_deployed() -> None: response = chat_completions_streaming_text_self_deployed.generate_text( - PROJECT_ID, LOCATION, SELF_HOSTED_MODEL_ID, ENDPOINT_ID + PROJECT_ID, SELF_DEPLOYED_LOCATION, SELF_HOSTED_MODEL_ID, ENDPOINT_ID ) assert response def test_non_streaming_text_self_deployed() -> None: response = chat_completions_non_streaming_text_self_deployed.generate_text( - PROJECT_ID, LOCATION, SELF_HOSTED_MODEL_ID, ENDPOINT_ID + PROJECT_ID, SELF_DEPLOYED_LOCATION, SELF_HOSTED_MODEL_ID, ENDPOINT_ID ) assert response diff --git a/generative_ai/model_garden/claude_3_streaming_example.py b/generative_ai/model_garden/claude_3_streaming_example.py index 6f929e04d91..eedbe868652 100644 --- a/generative_ai/model_garden/claude_3_streaming_example.py +++ b/generative_ai/model_garden/claude_3_streaming_example.py @@ -33,7 +33,7 @@ def generate_text_streaming() -> str: result = [] with client.messages.stream( - model="claude-3-5-sonnet-v2@20241022", + model="claude-sonnet-4-6", max_tokens=1024, messages=[ { diff --git a/generative_ai/model_garden/claude_3_tool_example.py b/generative_ai/model_garden/claude_3_tool_example.py index 8c3ed5a7809..6375b7ead01 100644 --- a/generative_ai/model_garden/claude_3_tool_example.py +++ b/generative_ai/model_garden/claude_3_tool_example.py @@ -29,7 +29,7 @@ def tool_use() -> object: client = AnthropicVertex(project_id=PROJECT_ID, region="us-east5") message = client.messages.create( - model="claude-3-5-sonnet-v2@20241022", + model="claude-sonnet-4-6", max_tokens=1024, tools=[ { diff --git a/generative_ai/model_garden/claude_3_unary_example.py b/generative_ai/model_garden/claude_3_unary_example.py index 4cec43246d6..e30f0ebba7a 100644 --- a/generative_ai/model_garden/claude_3_unary_example.py +++ b/generative_ai/model_garden/claude_3_unary_example.py @@ -30,7 +30,7 @@ def generate_text() -> object: client = AnthropicVertex(project_id=PROJECT_ID, region="us-east5") message = client.messages.create( - model="claude-3-5-sonnet-v2@20241022", + model="claude-sonnet-4-6", max_tokens=1024, messages=[ { diff --git a/generative_ai/model_garden/requirements.txt b/generative_ai/model_garden/requirements.txt index 7ac0ee30a69..7b00d2143c4 100644 --- a/generative_ai/model_garden/requirements.txt +++ b/generative_ai/model_garden/requirements.txt @@ -5,7 +5,7 @@ pillow==12.3.0 google-cloud-aiplatform[full]==1.157.0 sentencepiece==0.2.1 google-auth==2.38.0 -anthropic[vertex]==0.28.0 +anthropic[vertex]==2.2.0 langchain-core==1.4.0 langchain-google-vertexai==3.2.3 numpy<3 diff --git a/generative_ai/rag/create_corpus_example.py b/generative_ai/rag/create_corpus_example.py index f5bec091527..530bc658724 100644 --- a/generative_ai/rag/create_corpus_example.py +++ b/generative_ai/rag/create_corpus_example.py @@ -34,8 +34,9 @@ def create_corpus( # display_name = "test_corpus" # description = "Corpus Description" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") # Configure project-level config backend_config = types.RagVectorDbConfig( diff --git a/generative_ai/rag/create_corpus_feature_store_example.py b/generative_ai/rag/create_corpus_feature_store_example.py index 39f61898361..0fcfdf35475 100644 --- a/generative_ai/rag/create_corpus_feature_store_example.py +++ b/generative_ai/rag/create_corpus_feature_store_example.py @@ -36,8 +36,9 @@ def create_corpus_feature_store( # display_name = "test_corpus" # description = "Corpus Description" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") # Configure embedding model (Optional) backend_config = types.RagVectorDbConfig( diff --git a/generative_ai/rag/create_corpus_pinecone_example.py b/generative_ai/rag/create_corpus_pinecone_example.py index 74a2c6081e5..46471f5a559 100644 --- a/generative_ai/rag/create_corpus_pinecone_example.py +++ b/generative_ai/rag/create_corpus_pinecone_example.py @@ -20,7 +20,6 @@ PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - def create_corpus_pinecone( pinecone_index_name: str, pinecone_api_key_secret_manager_version: str, @@ -38,8 +37,9 @@ def create_corpus_pinecone( # display_name = "test_corpus" # description = "Corpus Description" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") # Configure embedding model (Optional) embedding_model_config = types.RagEmbeddingModelConfig( @@ -51,7 +51,12 @@ def create_corpus_pinecone( # Configure Vector DB vector_db = types.RagVectorDbConfig( pinecone=types.RagVectorDbConfigPinecone( - index_name=pinecone_index_name, + index_name=pinecone_index_name, + ), + api_auth=types.ApiAuth( + api_key_config=types.ApiAuthApiKeyConfig( + api_key_secret_version=pinecone_api_key_secret_manager_version + ) ), rag_embedding_model_config=embedding_model_config, ) diff --git a/generative_ai/rag/create_corpus_vector_search_example.py b/generative_ai/rag/create_corpus_vector_search_example.py index 8f3905adbd1..b60214a8850 100644 --- a/generative_ai/rag/create_corpus_vector_search_example.py +++ b/generative_ai/rag/create_corpus_vector_search_example.py @@ -19,6 +19,7 @@ PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") + def create_corpus_vector_search( vector_search_index_name: str, vector_search_index_endpoint_name: str, @@ -37,8 +38,9 @@ def create_corpus_vector_search( # display_name = "test_corpus" # description = "Corpus Description" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") # Configure embedding model (Optional) embedding_model_config = types.RagEmbeddingModelConfig( diff --git a/generative_ai/rag/create_corpus_vertex_ai_search_example.py b/generative_ai/rag/create_corpus_vertex_ai_search_example.py index 01231e73a16..c73d53ae3c5 100644 --- a/generative_ai/rag/create_corpus_vertex_ai_search_example.py +++ b/generative_ai/rag/create_corpus_vertex_ai_search_example.py @@ -36,8 +36,9 @@ def create_corpus_vertex_ai_search( # display_name = "test_corpus" # description = "Corpus Description" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") # Configure Search vertex_ai_search_config = types.VertexAiSearchConfig( diff --git a/generative_ai/rag/create_corpus_weaviate_example.py b/generative_ai/rag/create_corpus_weaviate_example.py index a12452af2e6..af0de80c9c7 100644 --- a/generative_ai/rag/create_corpus_weaviate_example.py +++ b/generative_ai/rag/create_corpus_weaviate_example.py @@ -40,13 +40,14 @@ def create_corpus_weaviate( # display_name = "test_corpus" # description = "Corpus Description" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") # Configure embedding model (Optional) embedding_model_config = types.RagEmbeddingModelConfig( vertex_prediction_endpoint=types.RagEmbeddingModelConfigVertexPredictionEndpoint( - endpoint="publishers/google/models/text-embedding-004" + endpoint="publishers/google/models/text-embedding-005" ) ) @@ -60,9 +61,14 @@ def create_corpus_weaviate( rag_corpus=types.RagCorpus( display_name=display_name, description=description, - rag_embedding_model_config=embedding_model_config, rag_vector_db_config=types.RagVectorDbConfig( - weaviate=vector_db + weaviate=vector_db, + api_auth=types.ApiAuth( + api_key_config=types.ApiAuthApiKeyConfig( + api_key_secret_version=weaviate_api_key_secret_manager_version + ) + ), + rag_embedding_model_config=embedding_model_config, ), ) ) diff --git a/generative_ai/rag/delete_corpus_example.py b/generative_ai/rag/delete_corpus_example.py index 527126a92a7..1e2131cb5f0 100644 --- a/generative_ai/rag/delete_corpus_example.py +++ b/generative_ai/rag/delete_corpus_example.py @@ -24,21 +24,22 @@ def delete_corpus(corpus_name: str) -> None: # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # corpus_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + # corpus_name = "projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{rag_corpus_id}" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") client.rag.delete_corpus(name=corpus_name) print(f"Corpus {corpus_name} deleted.") # Example response: # Successfully deleted the RagCorpus. - # Corpus projects/[PROJECT_ID]/locations/us-central1/ragCorpora/123456789012345 deleted. + # Corpus projects/[PROJECT_ID]/locations/us-east5/ragCorpora/123456789012345 deleted. # [END generativeaionvertexai_rag_delete_corpus] if __name__ == "__main__": delete_corpus( - "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}" ) diff --git a/generative_ai/rag/delete_file_example.py b/generative_ai/rag/delete_file_example.py index 477f93a97d0..c5bb5127cfa 100644 --- a/generative_ai/rag/delete_file_example.py +++ b/generative_ai/rag/delete_file_example.py @@ -24,21 +24,22 @@ def delete_file(file_name: str) -> None: # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # file_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}/ragFiles/{rag_file_id}" + # file_name = "projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{rag_corpus_id}/ragFiles/{rag_file_id}" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") client.rag.delete_file(name=file_name) print(f"File {file_name} deleted.") # Example response: # Successfully deleted the RagFile. - # File projects/1234567890/locations/us-central1/ragCorpora/1111111111/ragFiles/2222222222 deleted. + # File projects/1234567890/locations/us-east5/ragCorpora/1111111111/ragFiles/2222222222 deleted. # [END generativeaionvertexai_rag_delete_file] if __name__ == "__main__": delete_file( - "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}/ragFiles/{rag_file_id}" + f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}/ragFiles/{{rag_file_id}}" ) diff --git a/generative_ai/rag/generate_content_example.py b/generative_ai/rag/generate_content_example.py index 6bff7cb1910..03c0df5a12f 100644 --- a/generative_ai/rag/generate_content_example.py +++ b/generative_ai/rag/generate_content_example.py @@ -14,7 +14,7 @@ import os -from genai import types as genai_types +from google.genai import types as genai_types PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") @@ -29,7 +29,7 @@ def generate_content_with_rag( # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # corpus_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + # corpus_name = "projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{rag_corpus_id}" rag_retrieval_tool = genai_types.Tool( retrieval=genai_types.Retrieval( @@ -50,14 +50,14 @@ def generate_content_with_rag( ) # Create a GenAI SDK client to make a generate_content request - genai_client = genai.Client(enterprise=True, project=PROJECT_ID, location="us-central1") + genai_client = genai.Client(vertexai=True, project=PROJECT_ID, location="global") response = genai_client.models.generate_content( - model="gemini-2.5-pro", + model="gemini-3.8-flash", contents="Why is the sky blue?", config=genai_types.GenerateContentConfig( tools=[rag_retrieval_tool] - ) + ), ) print(response.text) # Example response: @@ -73,5 +73,5 @@ def generate_content_with_rag( if __name__ == "__main__": generate_content_with_rag( - "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}" ) diff --git a/generative_ai/rag/get_corpus_example.py b/generative_ai/rag/get_corpus_example.py index 2e0a1ae868c..ec13c4641ae 100644 --- a/generative_ai/rag/get_corpus_example.py +++ b/generative_ai/rag/get_corpus_example.py @@ -26,15 +26,16 @@ def get_corpus(corpus_name: str) -> types.RagCorpus: # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # corpus_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + # corpus_name = "projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{rag_corpus_id}" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") corpus = client.rag.get_corpus(name=corpus_name) print(corpus) # Example response: - # RagCorpus(name='projects/[PROJECT_ID]/locations/us-central1/ragCorpora/1234567890', + # RagCorpus(name='projects/[PROJECT_ID]/locations/us-east5/ragCorpora/1234567890', # display_name='test_corpus', description='Corpus Description', # ... @@ -44,5 +45,5 @@ def get_corpus(corpus_name: str) -> types.RagCorpus: if __name__ == "__main__": get_corpus( - corpus_name="projects/your-project-id/locations/us-central1/ragCorpora/[rag_corpus_id]" + corpus_name=f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}" ) diff --git a/generative_ai/rag/get_file_example.py b/generative_ai/rag/get_file_example.py index af64b386f83..7c82a4d452e 100644 --- a/generative_ai/rag/get_file_example.py +++ b/generative_ai/rag/get_file_example.py @@ -26,15 +26,16 @@ def get_file(file_name: str) -> types.RagFile: # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # file_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}/ragFiles/{rag_file_id}" + # file_name = "projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{rag_corpus_id}/ragFiles/{rag_file_id}" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") rag_file = client.rag.get_file(name=file_name) print(rag_file) # Example response: - # RagFile(name='projects/1234567890/locations/us-central1/ragCorpora/11111111111/ragFiles/22222222222', + # RagFile(name='projects/1234567890/locations/us-east5/ragCorpora/11111111111/ragFiles/22222222222', # display_name='file_display_name', description='file description') # [END generativeaionvertexai_rag_get_file] @@ -44,5 +45,5 @@ def get_file(file_name: str) -> types.RagFile: if __name__ == "__main__": get_file( - "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}/ragFiles/{rag_file_id}" + f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}/ragFiles/{{rag_file_id}}" ) diff --git a/generative_ai/rag/import_files_async_example.py b/generative_ai/rag/import_files_async_example.py index 8ca344ce9ee..deb851018e3 100644 --- a/generative_ai/rag/import_files_async_example.py +++ b/generative_ai/rag/import_files_async_example.py @@ -25,6 +25,7 @@ async def import_files_async( corpus_name: str, paths: List[str], ) -> types.ImportRagFilesResponse: + """Asynchronously imports files from Google Cloud Storage into a RAG corpus.""" # [START generativeaionvertexai_rag_import_files_async] import agentplatform @@ -34,34 +35,25 @@ async def import_files_async( # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # corpus_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + # corpus_name = "projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{rag_corpus_id}" + # paths = ["gs://my_bucket/my_files_dir/*"] - # Supports Google Cloud Storage and Google Drive Links - # paths = ["https://drive.google.com/file/d/123", "gs://my_bucket/my_files_dir/*"] - - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") response = await client.aio.rag.import_files( name=corpus_name, import_config=types.ImportRagFilesConfig( - gcs_source=genai_types.GcsSource(uris=[paths[1]]), - google_drive_source=types.GoogleDriveSource( - resource_ids=[ - types.GoogleDriveSourceResourceId( - resource_id=paths[0], - resource_type=types.ResourceType.RESOURCE_TYPE_FILE - ) - ] - ), # optional + gcs_source=genai_types.GcsSource(uris=paths), rag_file_transformation_config=types.RagFileTransformationConfig( rag_file_chunking_config=types.RagFileChunkingConfig( chunk_size=512, chunk_overlap=100, ) - ), # optional - max_embedding_requests_per_min=900, # optional - ) + ), # optional + max_embedding_requests_per_min=900, # optional + ), ) print(f"Imported {response.imported_rag_files_count} files.") @@ -75,11 +67,10 @@ async def import_files_async( if __name__ == "__main__": import asyncio - gdrive_path = "https://drive.google.com/file/1234567890" gcloud_path = "gs://your-bucket-name/file.txt" asyncio.run( import_files_async( - corpus_name="projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}", - paths=[gdrive_path, gcloud_path], + corpus_name=f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}", + paths=[gcloud_path], ) ) diff --git a/generative_ai/rag/import_files_example.py b/generative_ai/rag/import_files_example.py index d2d92192c8a..26e42ed3ec7 100644 --- a/generative_ai/rag/import_files_example.py +++ b/generative_ai/rag/import_files_example.py @@ -24,6 +24,7 @@ def import_files( corpus_name: str, paths: List[str], ) -> types.ImportRagFilesResponse: + """Imports files from Google Cloud Storage into a RAG corpus.""" # [START generativeaionvertexai_rag_import_files] import agentplatform @@ -33,34 +34,25 @@ def import_files( # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # corpus_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + # corpus_name = "projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{rag_corpus_id}" + # paths = ["gs://my_bucket/my_files_dir/*"] - # Supports Google Cloud Storage and Google Drive Links - # paths = ["https://drive.google.com/file/d/123", "gs://my_bucket/my_files_dir/*"] - - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") response = client.rag.import_files( name=corpus_name, import_config=types.ImportRagFilesConfig( - gcs_source=genai_types.GcsSource(uris=[paths[1]]), - google_drive_source=types.GoogleDriveSource( - resource_ids=[ - types.GoogleDriveSourceResourceId( - resource_id=paths[0], - resource_type=types.ResourceType.RESOURCE_TYPE_FILE - ) - ] - ), # optional + gcs_source=genai_types.GcsSource(uris=paths), rag_file_transformation_config=types.RagFileTransformationConfig( rag_file_chunking_config=types.RagFileChunkingConfig( chunk_size=512, chunk_overlap=100, ) - ), # optional - max_embedding_requests_per_min=900, # optional - ) + ), # optional + max_embedding_requests_per_min=900, # optional + ), ) print(f"Imported {response.imported_rag_files_count} files.") @@ -72,9 +64,8 @@ def import_files( if __name__ == "__main__": - gdrive_path = "https://drive.google.com/file/1234567890" gcloud_path = "gs://your-bucket-name/file.txt" import_files( - corpus_name="projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}", - paths=[gdrive_path, gcloud_path], + corpus_name=f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}", + paths=[gcloud_path], ) diff --git a/generative_ai/rag/list_corpora_example.py b/generative_ai/rag/list_corpora_example.py index 1e9ba774384..45a38f65e94 100644 --- a/generative_ai/rag/list_corpora_example.py +++ b/generative_ai/rag/list_corpora_example.py @@ -27,8 +27,9 @@ def list_corpora() -> types.ListRagCorporaResponse: # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") corpora = client.rag.list_corpora() print(corpora) diff --git a/generative_ai/rag/list_files_example.py b/generative_ai/rag/list_files_example.py index 7da8e6f8ac5..af2537120ab 100644 --- a/generative_ai/rag/list_files_example.py +++ b/generative_ai/rag/list_files_example.py @@ -26,10 +26,11 @@ def list_files(corpus_name: str) -> types.ListRagFilesResponse: # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # corpus_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + # corpus_name = "projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{rag_corpus_id}" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-central1") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") files_response = client.rag.list_files(name=corpus_name) for file in files_response.rag_files: @@ -37,13 +38,13 @@ def list_files(corpus_name: str) -> types.ListRagFilesResponse: print(file.name) # Example response: # g-drive_file.txt - # projects/1234567890/locations/us-central1/ragCorpora/111111111111/ragFiles/222222222222 + # projects/1234567890/locations/us-east5/ragCorpora/111111111111/ragFiles/222222222222 # g_cloud_file.txt - # projects/1234567890/locations/us-central1/ragCorpora/111111111111/ragFiles/333333333333 + # projects/1234567890/locations/us-east5/ragCorpora/111111111111/ragFiles/333333333333 # [END generativeaionvertexai_rag_list_files] return files_response if __name__ == "__main__": - list_files("projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}") + list_files(f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}") diff --git a/generative_ai/rag/quickstart_example.py b/generative_ai/rag/quickstart_example.py index b57ae049e9e..ce9bc59e114 100644 --- a/generative_ai/rag/quickstart_example.py +++ b/generative_ai/rag/quickstart_example.py @@ -20,7 +20,7 @@ from google.genai import types as genai_types PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") -MODEL_ID = os.getenv("MODEL_ID") +MODEL_ID = os.getenv("MODEL_ID", "gemini-3.8-flash") def quickstart( @@ -34,18 +34,17 @@ def quickstart( from google import genai from google.genai import types as genai_types - # Create a RAG Corpus, Import Files, and Generate a response # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # MODEL_ID = "gemini-3.5-flash" + # MODEL_ID = "gemini-3.8-flash" # display_name = "test_corpus" # gcs_path = "gs://my_bucket/my_files_dir/*" - # google_drive_path ="https://drive.google.com/file/d/123" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-east4") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") # Configure embedding model, for example "text-embedding-005". embedding_model_config = types.RagEmbeddingModelConfig( @@ -74,9 +73,9 @@ def quickstart( chunk_size=512, chunk_overlap=100, ) - ), # optional - max_embedding_requests_per_min=1000, # optional - ) + ), # optional + max_embedding_requests_per_min=1000, # optional + ), ) # Direct context retrieval @@ -96,8 +95,8 @@ def quickstart( ), query=types.RagQuery( text="What is RAG and why it is helpful?", - rag_retrieval_config=rag_retrieval_config, - ) + rag_retrieval_config=rag_retrieval_config, + ), ) print(response) @@ -121,8 +120,7 @@ def quickstart( # Call generate_content with the tool using the GenAI SDK # Create a GenAI SDK client - genai_client = genai.Client(enterprise=True, project=PROJECT_ID, location="us-east4") - + genai_client = genai.Client(vertexai=True, project=PROJECT_ID, location="global") response = genai_client.models.generate_content( model=MODEL_ID, @@ -142,9 +140,8 @@ def quickstart( if __name__ == "__main__": - gdrive_path = "https://drive.google.com/file/1234567890" gcloud_path = "gs://your-bucket-name/file.txt" quickstart( display_name="test_corpus", - paths=[gdrive_path, gcloud_path], + gcs_path=gcloud_path, ) diff --git a/generative_ai/rag/requirements.txt b/generative_ai/rag/requirements.txt index 567a82bafee..fe0949f2d27 100644 --- a/generative_ai/rag/requirements.txt +++ b/generative_ai/rag/requirements.txt @@ -1 +1,2 @@ -google-cloud-aiplatform==1.157.0 +google-cloud-aiplatform==2.6.0 +google-genai==2.29.0 diff --git a/generative_ai/rag/retrieval_query_example.py b/generative_ai/rag/retrieval_query_example.py index c887298550b..d07ef6e3dac 100644 --- a/generative_ai/rag/retrieval_query_example.py +++ b/generative_ai/rag/retrieval_query_example.py @@ -31,10 +31,11 @@ def retrieval_query( # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # corpus_name = "projects/[PROJECT_ID]/locations/us-central1/ragCorpora/[rag_corpus_id]" + # corpus_name = "projects/[PROJECT_ID]/locations/us-east5/ragCorpora/[rag_corpus_id]" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-east4") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") response = client.rag.retrieve_contexts( vertex_rag_store=genai_types.VertexRagStore( @@ -71,5 +72,5 @@ def retrieval_query( if __name__ == "__main__": retrieval_query( - "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}" ) diff --git a/generative_ai/rag/test_rag_examples.py b/generative_ai/rag/test_rag_examples.py index c35b3c63bba..15368d18df7 100644 --- a/generative_ai/rag/test_rag_examples.py +++ b/generative_ai/rag/test_rag_examples.py @@ -41,7 +41,7 @@ pytest.skip(allow_module_level=True) PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") -LOCATION = "us-central1" +LOCATION = "us-east5" GCS_FILE = "gs://cloud-samples-data/generative-ai/pdf/earnings_statement.pdf" @@ -209,4 +209,4 @@ def test_quickstart() -> None: ) assert response assert response.text - delete_corpus_example.delete_corpus(corpus.name) \ No newline at end of file + delete_corpus_example.delete_corpus(corpus.name) diff --git a/generative_ai/rag/upload_file_example.py b/generative_ai/rag/upload_file_example.py index d3d964d700a..f7db1900c56 100644 --- a/generative_ai/rag/upload_file_example.py +++ b/generative_ai/rag/upload_file_example.py @@ -33,12 +33,13 @@ def upload_file( # TODO(developer): Update and un-comment below lines # PROJECT_ID = "your-project-id" - # corpus_name = "projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}" + # corpus_name = "projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{rag_corpus_id}" # path = "path/to/local/file.txt" # display_name = "file_display_name" - # Initialize Agent Platform client once per session - client = agentplatform.Client(project=PROJECT_ID, location="us-east4") + # Initialize Agent Platform client once per session. + # See https://docs.cloud.google.com/gemini-enterprise-agent-platform/build/rag-engine/rag-overview#supported-regions + client = agentplatform.Client(project=PROJECT_ID, location="us-east5") rag_file = client.rag.upload_file( corpus_name=corpus_name, @@ -46,7 +47,7 @@ def upload_file( display_name=display_name, ) print(rag_file) - # RagFile(name='projects/[PROJECT_ID]/locations/us-central1/ragCorpora/1234567890/ragFiles/09876543', + # RagFile(name='projects/[PROJECT_ID]/locations/us-east5/ragCorpora/1234567890/ragFiles/09876543', # display_name='file_display_name') # [END generativeaionvertexai_rag_upload_file] @@ -55,7 +56,7 @@ def upload_file( if __name__ == "__main__": upload_file( - corpus_name="projects/{PROJECT_ID}/locations/us-central1/ragCorpora/{rag_corpus_id}", + corpus_name=f"projects/{PROJECT_ID}/locations/us-east5/ragCorpora/{{rag_corpus_id}}", path="path/to/file.txt", display_name="file_display_name", description="file description",