Skip to content

PLACEHOLDER: Migrate code retrieval example for embeddings to genai. - #14475

Draft
XrossFox wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
XrossFox:vertex-to-genai-language-models
Draft

PLACEHOLDER: Migrate code retrieval example for embeddings to genai.#14475
XrossFox wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
XrossFox:vertex-to-genai-language-models

Conversation

@XrossFox

@XrossFox XrossFox commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #

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

@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Aug 4, 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 example script, code_retrieval_example.py, demonstrating how to use the Google GenAI SDK for code retrieval embeddings. The feedback highlights a few areas for improvement: correcting the return type annotation of the embed_test function to return response objects instead of config objects, removing an unused and unsupported DIMENSIONALITY constant, and ensuring consistent usage of the imported types module instead of referencing genai.types directly.

]


def embed_test() -> tuple[types.EmbedContentConfig, types.EmbedContentConfig]:

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.

high

The return type annotation for embed_test is incorrect. It specifies types.EmbedContentConfig as the tuple elements, but the function actually returns the response objects (types.EmbedContentResponse) returned by client.models.embed_content.

Suggested change
def embed_test() -> tuple[types.EmbedContentConfig, types.EmbedContentConfig]:
def embed_test() -> tuple[types.EmbedContentResponse, types.EmbedContentResponse]:

PROJECT_ID = os.getenv("PROJECT_ID")
LOCATION_ID = os.getenv("LOCATION_ID", "us-central1")
MODEL_NAME = os.getenv("MODEL_NAME", "gemini-embedding-001")
DIMENSIONALITY = 3072

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.

medium

The constant DIMENSIONALITY is defined but never used in the code. Additionally, the default model gemini-embedding-001 does not support custom output dimensionality (it has a fixed dimension of 768). This unused constant should be removed to avoid confusion.


# Index Source Code
for line in SOURCE_CODE:
config = genai.types.EmbedContentConfig(

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.

medium

Use the imported types module directly instead of prefixing with genai.types to maintain consistency with the import on line 20 and the return type annotation on line 39.

Suggested change
config = genai.types.EmbedContentConfig(
config = types.EmbedContentConfig(


# Embed Search Prompts
for line in QUERY_LINES:
config = genai.types.EmbedContentConfig(

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.

medium

Use the imported types module directly instead of prefixing with genai.types to maintain consistency with the import on line 20.

Suggested change
config = genai.types.EmbedContentConfig(
config = types.EmbedContentConfig(

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