Skip to content

feat(genai/embeddings): migrate lower dimension embeddings to genai - #14512

Draft
XrossFox wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
XrossFox:vertex-to-genai-vision-models-embeddings-low
Draft

feat(genai/embeddings): migrate lower dimension embeddings to genai#14512
XrossFox wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
XrossFox:vertex-to-genai-vision-models-embeddings-low

Conversation

@XrossFox

Copy link
Copy Markdown
Contributor

Description

Migrates the sample for generating multimodal embeddings with lower dimensionality to use the new google-genai SDK and adds the
corresponding test.

Fixes b/546128628

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

 Migrates the sample for generating multimodal embeddings with lower dimensionality to use the new `google-genai` SDK and adds the
 corresponding test.
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Aug 14, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new script generate_embeddings_with_lower_dimension.py along with its corresponding test to demonstrate generating multimodal embeddings with custom lower dimensionality using the google-genai SDK. The review feedback highlights two critical runtime issues in the new script: the genai.Client should be initialized with vertexai=True instead of enterprise=True, and the text part should be created by instantiating Part directly rather than using the non-existent from_text classmethod.

Comment on lines +37 to +41
client = genai.Client(
enterprise=True,
project=PROJECT_ID,
location=LOCATION_ID,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The google-genai SDK uses the vertexai parameter to initialize the client for Vertex AI, rather than enterprise. Using enterprise=True will result in a TypeError at runtime.

Suggested change
client = genai.Client(
enterprise=True,
project=PROJECT_ID,
location=LOCATION_ID,
)
client = genai.Client(
vertexai=True,
project=PROJECT_ID,
location=LOCATION_ID,
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not, tested locally.

mime_type="image/png",
)

text_part = genai.types.Part.from_text(text=CONTEXTUAL_TEXT)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The google-genai SDK's Part class does not have a from_text classmethod. To create a text part, you should instantiate Part directly with the text parameter.

Suggested change
text_part = genai.types.Part.from_text(text=CONTEXTUAL_TEXT)
text_part = genai.types.Part(text=CONTEXTUAL_TEXT)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it does.

@XrossFox

Copy link
Copy Markdown
Contributor Author

Tested locally:

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant