Skip to content

Commit c19ec88

Browse files
authored
feat(genai/embeddings/multimodal): Add genai multimodal embedding image sample (#14511)
* feat: add multimodal embedding image example and update location to global * refactor: update embed_content return type hint to types.EmbedContentResponse * added eof * chore: add newline to end of multimodal embedding image sample * chore: update multimodal embedding image code snippet tags to aiplatform_genai prefix
1 parent 4dbc521 commit c19ec88

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START aiplatform_genai_multimodal_embedding_image]
16+
from google import genai
17+
from google.genai import types
18+
19+
20+
def embed_content() -> types.EmbedContentResponse:
21+
client = genai.Client()
22+
23+
content = types.Content(
24+
parts=[
25+
types.Part.from_uri(
26+
file_uri="gs://cloud-samples-data/vertex-ai/llm/prompts/landmark1.png",
27+
mime_type="image/png",
28+
),
29+
types.Part.from_text(text="Colosseum"),
30+
],
31+
)
32+
33+
response = client.models.embed_content(
34+
model="gemini-embedding-2",
35+
contents=[content],
36+
config=types.EmbedContentConfig(
37+
output_dimensionality=1408,
38+
),
39+
)
40+
print(response)
41+
# Example response:
42+
# embeddings=[ContentEmbedding(values=[-0.0123147098, 0.0727171078, ...])]
43+
return response
44+
45+
46+
# [END aiplatform_genai_multimodal_embedding_image]
47+

genai/embeddings/test_embeddings_examples.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import code_retrieval_example
2222
import embeddings_docretrieval_with_txt
2323
import model_tuning_example
24+
import multimodal_embedding_image
2425
import multimodal_embedding_video
2526

2627
os.environ["GOOGLE_GENAI_USE_ENTERPRISE"] = "True"
@@ -38,11 +39,17 @@ def test_code_retrieval_example() -> None:
3839
response = code_retrieval_example.embed_test()
3940
assert response
4041

42+
4143
def test_model_tuning_example() -> None:
4244
response = model_tuning_example.tune_embedding_model()
4345
assert response
4446

4547

48+
def test_multimodal_embedding_image() -> None:
49+
response = multimodal_embedding_image.embed_content()
50+
assert response
51+
52+
4653
def test_multimodal_embedding_video() -> None:
4754
response = multimodal_embedding_video.embed_content()
4855
assert response

0 commit comments

Comments
 (0)