PLACEHOLDER: Migrate code retrieval example for embeddings to genai. - #14475
PLACEHOLDER: Migrate code retrieval example for embeddings to genai.#14475XrossFox wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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]: |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
|
|
||
| # Index Source Code | ||
| for line in SOURCE_CODE: | ||
| config = genai.types.EmbedContentConfig( |
There was a problem hiding this comment.
|
|
||
| # Embed Search Prompts | ||
| for line in QUERY_LINES: | ||
| config = genai.types.EmbedContentConfig( |
Description
Fixes #
Checklist
Testing
Compliance & Style
Post-Approval Actions