From ab9b1e2fe1cf7e09478258b27b65fd315b4f1ba7 Mon Sep 17 00:00:00 2001 From: Kevin Gordillo Date: Fri, 14 Aug 2026 21:11:55 +0000 Subject: [PATCH 1/5] feat: add multimodal embedding image example and update location to global --- .../embeddings/multimodal_embedding_image.py | 46 +++++++++++++++++++ genai/embeddings/test_embeddings_examples.py | 9 +++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 genai/embeddings/multimodal_embedding_image.py diff --git a/genai/embeddings/multimodal_embedding_image.py b/genai/embeddings/multimodal_embedding_image.py new file mode 100644 index 0000000000..7e04bc7be0 --- /dev/null +++ b/genai/embeddings/multimodal_embedding_image.py @@ -0,0 +1,46 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START googlegenaisdk_multimodal_embedding_image] +from google import genai +from google.genai import types + + +def embed_content() -> object: + client = genai.Client() + + content = types.Content( + parts=[ + types.Part.from_uri( + file_uri="gs://cloud-samples-data/vertex-ai/llm/prompts/landmark1.png", + mime_type="image/png", + ), + types.Part.from_text(text="Colosseum"), + ], + ) + + response = client.models.embed_content( + model="gemini-embedding-2", + contents=[content], + config=types.EmbedContentConfig( + output_dimensionality=1408, + ), + ) + print(response) + # Example response: + # embeddings=[ContentEmbedding(values=[-0.0123147098, 0.0727171078, ...])] + return response + + +# [END googlegenaisdk_multimodal_embedding_image] \ No newline at end of file diff --git a/genai/embeddings/test_embeddings_examples.py b/genai/embeddings/test_embeddings_examples.py index a6afaa0070..36adf4577d 100644 --- a/genai/embeddings/test_embeddings_examples.py +++ b/genai/embeddings/test_embeddings_examples.py @@ -21,9 +21,10 @@ import code_retrieval_example import embeddings_docretrieval_with_txt import model_tuning_example +import multimodal_embedding_image os.environ["GOOGLE_GENAI_USE_ENTERPRISE"] = "True" -os.environ["GOOGLE_CLOUD_LOCATION"] = "us-central1" +os.environ["GOOGLE_CLOUD_LOCATION"] = "global" # The project name is included in the CICD pipeline # os.environ['GOOGLE_CLOUD_PROJECT'] = "add-your-project-name" @@ -37,6 +38,12 @@ def test_code_retrieval_example() -> None: response = code_retrieval_example.embed_test() assert response + def test_model_tuning_example() -> None: response = model_tuning_example.tune_embedding_model() assert response + + +def test_multimodal_embedding_image() -> None: + response = multimodal_embedding_image.embed_content() + assert response From aca41e551f65c10f1d8006237ab3acceb57354a0 Mon Sep 17 00:00:00 2001 From: Kevin Gordillo Date: Fri, 14 Aug 2026 21:31:55 +0000 Subject: [PATCH 2/5] refactor: update embed_content return type hint to types.EmbedContentResponse --- genai/embeddings/multimodal_embedding_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/embeddings/multimodal_embedding_image.py b/genai/embeddings/multimodal_embedding_image.py index 7e04bc7be0..7eaf63aa8f 100644 --- a/genai/embeddings/multimodal_embedding_image.py +++ b/genai/embeddings/multimodal_embedding_image.py @@ -17,7 +17,7 @@ from google.genai import types -def embed_content() -> object: +def embed_content() -> types.EmbedContentResponse: client = genai.Client() content = types.Content( From 58f7f476402400c330a326faded1c4055d7569c8 Mon Sep 17 00:00:00 2001 From: Kevin Gordillo Date: Mon, 17 Aug 2026 20:18:56 +0000 Subject: [PATCH 3/5] added eof --- genai/embeddings/multimodal_embedding_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/embeddings/multimodal_embedding_image.py b/genai/embeddings/multimodal_embedding_image.py index 7eaf63aa8f..e5c5a26e96 100644 --- a/genai/embeddings/multimodal_embedding_image.py +++ b/genai/embeddings/multimodal_embedding_image.py @@ -43,4 +43,4 @@ def embed_content() -> types.EmbedContentResponse: return response -# [END googlegenaisdk_multimodal_embedding_image] \ No newline at end of file +# [END googlegenaisdk_multimodal_embedding_image] From 5a012b9dd0cb57e11859304c9d3b715ced7a2b9e Mon Sep 17 00:00:00 2001 From: Kevin Gordillo Date: Mon, 17 Aug 2026 20:21:32 +0000 Subject: [PATCH 4/5] chore: add newline to end of multimodal embedding image sample --- genai/embeddings/multimodal_embedding_image.py | 1 + 1 file changed, 1 insertion(+) diff --git a/genai/embeddings/multimodal_embedding_image.py b/genai/embeddings/multimodal_embedding_image.py index e5c5a26e96..5acc7e6e11 100644 --- a/genai/embeddings/multimodal_embedding_image.py +++ b/genai/embeddings/multimodal_embedding_image.py @@ -44,3 +44,4 @@ def embed_content() -> types.EmbedContentResponse: # [END googlegenaisdk_multimodal_embedding_image] + From a0722d2b5d663ac917ac6b0cdf0f36443799fc11 Mon Sep 17 00:00:00 2001 From: Kevin Gordillo Date: Mon, 17 Aug 2026 22:15:27 +0000 Subject: [PATCH 5/5] chore: update multimodal embedding image code snippet tags to aiplatform_genai prefix --- genai/embeddings/multimodal_embedding_image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genai/embeddings/multimodal_embedding_image.py b/genai/embeddings/multimodal_embedding_image.py index 5acc7e6e11..5444f768bc 100644 --- a/genai/embeddings/multimodal_embedding_image.py +++ b/genai/embeddings/multimodal_embedding_image.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START googlegenaisdk_multimodal_embedding_image] +# [START aiplatform_genai_multimodal_embedding_image] from google import genai from google.genai import types @@ -43,5 +43,5 @@ def embed_content() -> types.EmbedContentResponse: return response -# [END googlegenaisdk_multimodal_embedding_image] +# [END aiplatform_genai_multimodal_embedding_image]