From 6668a0788a2e5009a9da74a9de78bbc97558b30c Mon Sep 17 00:00:00 2001 From: Kevin Gordillo Date: Tue, 18 Aug 2026 22:43:35 +0000 Subject: [PATCH 1/3] refactor: remove legacy multimodal embedding image and video examples and their corresponding tests --- .../embeddings/multimodal_image_example.py | 57 ----------------- .../embeddings/multimodal_video_example.py | 64 ------------------- .../embeddings/test_embeddings_examples.py | 15 ----- 3 files changed, 136 deletions(-) delete mode 100644 generative_ai/embeddings/multimodal_image_example.py delete mode 100644 generative_ai/embeddings/multimodal_video_example.py diff --git a/generative_ai/embeddings/multimodal_image_example.py b/generative_ai/embeddings/multimodal_image_example.py deleted file mode 100644 index 84549f16baf..00000000000 --- a/generative_ai/embeddings/multimodal_image_example.py +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright 2024 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. - -import os - -from vertexai.vision_models import MultiModalEmbeddingResponse - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def get_image_text_embeddings() -> MultiModalEmbeddingResponse: - """Example of how to generate multimodal embeddings from image and text. - - Read more @ https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-multimodal-embeddings#text-image-embedding - """ - # [START generativeaionvertexai_multimodal_embedding_image] - import vertexai - from vertexai.vision_models import Image, MultiModalEmbeddingModel - - # TODO(developer): Update & uncomment line below - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = MultiModalEmbeddingModel.from_pretrained("multimodalembedding@001") - image = Image.load_from_file( - "gs://cloud-samples-data/vertex-ai/llm/prompts/landmark1.png" - ) - - embeddings = model.get_embeddings( - image=image, - contextual_text="Colosseum", - dimension=1408, - ) - print(f"Image Embedding: {embeddings.image_embedding}") - print(f"Text Embedding: {embeddings.text_embedding}") - # Example response: - # Image Embedding: [-0.0123147098, 0.0727171078, ...] - # Text Embedding: [0.00230263756, 0.0278981831, ...] - - # [END generativeaionvertexai_multimodal_embedding_image] - - return embeddings - - -if __name__ == "__main__": - get_image_text_embeddings() diff --git a/generative_ai/embeddings/multimodal_video_example.py b/generative_ai/embeddings/multimodal_video_example.py deleted file mode 100644 index df9dcd31c1f..00000000000 --- a/generative_ai/embeddings/multimodal_video_example.py +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright 2024 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. -import os - -from vertexai.vision_models import MultiModalEmbeddingResponse - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def get_video_embeddings() -> MultiModalEmbeddingResponse: - """Example of how to use the multimodal embedding model to get embeddings only for video content. - - Read more at https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-multimodal-embeddings#vid-embedding - """ - # [START generativeaionvertexai_multimodal_embedding_video] - import vertexai - - from vertexai.vision_models import MultiModalEmbeddingModel, Video - from vertexai.vision_models import VideoSegmentConfig - - # TODO(developer): Update & uncomment line below - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = MultiModalEmbeddingModel.from_pretrained("multimodalembedding@001") - - embeddings = model.get_embeddings( - video=Video.load_from_file( - "gs://cloud-samples-data/vertex-ai-vision/highway_vehicles.mp4" - ), - video_segment_config=VideoSegmentConfig(end_offset_sec=1), - ) - - # Video Embeddings are segmented based on the video_segment_config. - print("Video Embeddings:") - for video_embedding in embeddings.video_embeddings: - print( - f"Video Segment: {video_embedding.start_offset_sec} - {video_embedding.end_offset_sec}" - ) - print(f"Embedding: {video_embedding.embedding}") - - # Example response: - # Video Embeddings: - # Video Segment: 0.0 - 1.0 - # Embedding: [-0.0206376351, 0.0123456789, ...] - - # [END generativeaionvertexai_multimodal_embedding_video] - - return embeddings - - -if __name__ == "__main__": - get_video_embeddings() diff --git a/generative_ai/embeddings/test_embeddings_examples.py b/generative_ai/embeddings/test_embeddings_examples.py index b430b978e2c..24daddd91b3 100644 --- a/generative_ai/embeddings/test_embeddings_examples.py +++ b/generative_ai/embeddings/test_embeddings_examples.py @@ -48,21 +48,6 @@ def test_multimodal_embedding_image_video_text() -> None: assert embeddings.text_embedding is not None -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10) -def test_multimodal_embedding_video() -> None: - embeddings = multimodal_video_example.get_video_embeddings() - assert embeddings is not None - assert embeddings.video_embeddings is not None - - -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10) -def test_multimodal_embedding_image() -> None: - embeddings = multimodal_image_example.get_image_text_embeddings() - assert embeddings is not None - assert embeddings.image_embedding is not None - assert embeddings.text_embedding is not None - - @backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10) def test_generate_embeddings_with_lower_dimension() -> None: embeddings = ( From 5294b5ea255af656b5cd85d8e1419076cd3afa51 Mon Sep 17 00:00:00 2001 From: Kevin Gordillo Date: Wed, 19 Aug 2026 15:26:19 +0000 Subject: [PATCH 2/3] test: remove imports for multimodal image and video embedding examples --- generative_ai/embeddings/test_embeddings_examples.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/generative_ai/embeddings/test_embeddings_examples.py b/generative_ai/embeddings/test_embeddings_examples.py index 24daddd91b3..0424e8942aa 100644 --- a/generative_ai/embeddings/test_embeddings_examples.py +++ b/generative_ai/embeddings/test_embeddings_examples.py @@ -29,8 +29,6 @@ import generate_embeddings_with_lower_dimension import model_tuning_example import multimodal_example -import multimodal_image_example -import multimodal_video_example @backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10) From aa4fcdafa618bbbbe75ac65af2c27407227990ff Mon Sep 17 00:00:00 2001 From: Kevin Gordillo Date: Wed, 19 Aug 2026 15:34:00 +0000 Subject: [PATCH 3/3] refactor: clean up imports and reformat batch prediction job call in embedding tests --- .../embeddings/test_embeddings_examples.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/generative_ai/embeddings/test_embeddings_examples.py b/generative_ai/embeddings/test_embeddings_examples.py index 0424e8942aa..46eeddec881 100644 --- a/generative_ai/embeddings/test_embeddings_examples.py +++ b/generative_ai/embeddings/test_embeddings_examples.py @@ -14,26 +14,23 @@ import os import backoff - -from google.api_core.exceptions import FailedPrecondition, ResourceExhausted - -import google.auth - -from google.cloud import aiplatform -from google.cloud.aiplatform import initializer as aiplatform_init - - import batch_example import code_retrieval_example import document_retrieval_example import generate_embeddings_with_lower_dimension +from google.api_core.exceptions import FailedPrecondition, ResourceExhausted +import google.auth +from google.cloud import aiplatform +from google.cloud.aiplatform import initializer as aiplatform_init import model_tuning_example import multimodal_example @backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10) def test_embed_text_batch() -> None: - batch_prediction_job = batch_example.embed_text_batch("gs://python-docs-samples-tests/") + batch_prediction_job = batch_example.embed_text_batch( + "gs://python-docs-samples-tests/" + ) assert batch_prediction_job