From 4dbc521f4a5e8d85669eabab1f7cc4df18e4cbc4 Mon Sep 17 00:00:00 2001 From: Kevin Gordillo Date: Tue, 18 Aug 2026 09:43:12 -0600 Subject: [PATCH] feat(genai/embeddings/multimodal): Add multimodal video embedding example (#14514) * feat: add multimodal video embedding example and update test configuration to use global location * Update genai/embeddings/multimodal_embedding_video.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * chore: update snippet tags for multimodal video embedding to aiplatform_genai_multimodal_embedding_video --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .../embeddings/multimodal_embedding_video.py | 43 +++++++++++++++++++ genai/embeddings/test_embeddings_examples.py | 8 +++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 genai/embeddings/multimodal_embedding_video.py diff --git a/genai/embeddings/multimodal_embedding_video.py b/genai/embeddings/multimodal_embedding_video.py new file mode 100644 index 0000000000..27ecf72218 --- /dev/null +++ b/genai/embeddings/multimodal_embedding_video.py @@ -0,0 +1,43 @@ +# 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 aiplatform_genai_multimodal_embedding_video] +from google import genai +from google.genai import types + + +def embed_content() -> types.EmbedContentResponse: + client = genai.Client() + + part = types.Part( + file_data=types.FileData( + file_uri="gs://cloud-samples-data/vertex-ai-vision/highway_vehicles.mp4", + mime_type="video/mp4", + ), + video_metadata=types.VideoMetadata(end_offset="1s"), + ) + + content = types.Content(parts=[part]) + + response = client.models.embed_content( + model="gemini-embedding-2", + contents=[content], + ) + print(response) + # Example response: + # embeddings=[ContentEmbedding(values=[-0.0123147098, 0.0727171078, ...])] + return response + + +# [END aiplatform_genai_multimodal_embedding_video] diff --git a/genai/embeddings/test_embeddings_examples.py b/genai/embeddings/test_embeddings_examples.py index a6afaa0070..90f3aa875e 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_video 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" @@ -40,3 +41,8 @@ def test_code_retrieval_example() -> None: def test_model_tuning_example() -> None: response = model_tuning_example.tune_embedding_model() assert response + + +def test_multimodal_embedding_video() -> None: + response = multimodal_embedding_video.embed_content() + assert response