Skip to content

Conversation

@MengqinShen
Copy link
Contributor

@MengqinShen MengqinShen commented Dec 17, 2025

This is to solve the issue #3952.

CHANGELOG:

  1. Update define_embedder usages in google.py, plugin_api.py
  2. Also update the relevant test files

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @MengqinShen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a more structured approach to defining embedder metadata within the Genkit framework. By modifying the define_embedder function to accept an EmbedderOptions object, it centralizes and standardizes how embedder properties like labels, dimensions, and supported input types are configured. This change impacts the core registry and its integration with various plugins, ensuring consistency and improved clarity in embedder definitions.

Highlights

  • Refactored define_embedder signature: The define_embedder function in _registry.py now accepts an optional metadata dictionary directly, in addition to the existing options parameter. The internal handling of embedder_meta has been adjusted to incorporate this new metadata parameter.
  • Standardized Embedder Configuration: Calls to ai.define_embedder across Google GenAI and Ollama plugins have been updated to pass embedder-specific information (like label, dimensions, and supported input types) via an EmbedderOptions object, rather than a generic metadata dictionary. This promotes a more structured and type-safe way of defining embedder properties.
  • Updated Test Assertions: Corresponding test files for Google GenAI and Ollama plugins have been modified to reflect the changes in the define_embedder function's signature, now asserting calls with the EmbedderOptions object.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@MengqinShen MengqinShen changed the title fix(py): update define_embedder in google plugin_api and other releva… fix(py): update define_embedder in google plugin_api and other test files Dec 17, 2025
Copy link
Contributor

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

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 refactors the define_embedder function in genkit/ai/_registry.py to accept an explicit metadata parameter and streamlines its internal handling. The primary change involves transitioning how embedder configuration is passed from a raw metadata dictionary to a structured EmbedderOptions object across the Google GenAI and Ollama plugins. This required updating the initialize and _resolve_embedder methods in google.py and plugin_api.py to construct and pass EmbedderOptions containing details like label, dimensions, supports, and config_schema. Corresponding unit tests in test_google_plugin.py and test_plugin_api.py were updated to reflect this new EmbedderOptions usage. Review comments suggested a more concise dictionary initialization using metadata or {} in _registry.py and recommended unpacking the supports dictionary more robustly in the Google plugin tests to handle future EmbedderSupports field additions.

@MengqinShen MengqinShen marked this pull request as ready for review December 17, 2025 07:44
@yesudeep
Copy link
Contributor

/gemini review

@yesudeep yesudeep merged commit b2151f7 into main Dec 17, 2025
10 checks passed
@yesudeep yesudeep deleted the elisa/fix/embedder-plugin-bug-in-genkit-dev-ui branch December 17, 2025 12:57
Copy link
Contributor

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

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 updates the define_embedder function signature and its usage across various plugins, centralizing embedder configurations into an EmbedderOptions object. The changes are logical and consistently applied. My review focuses on improving the robustness of the associated tests to ensure they accurately reflect the implementation's behavior, especially in edge cases. I've provided specific suggestions to align the test logic with the production code.

Comment on lines +248 to 252
options = EmbedderOptions(
label=info.get('label'),
supports=EmbedderSupports(**info.get('supports', {})),
dimensions=info.get('dimensions'),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for constructing EmbedderOptions, specifically for the supports field, diverges from the implementation in google.py. The implementation results in supports=None if the supports dictionary is missing or empty, while this test would create an EmbedderSupports object with default values. This discrepancy could lead to the test failing incorrectly if default_embedder_info changes its return value in the future. To ensure consistency and robustness, the test should replicate the implementation's logic.

Suggested change
options = EmbedderOptions(
label=info.get('label'),
supports=EmbedderSupports(**info.get('supports', {})),
dimensions=info.get('dimensions'),
)
options = EmbedderOptions(
label=info.get('label'),
supports=EmbedderSupports(**s) if (s := info.get('supports')) else None,
dimensions=info.get('dimensions'),
)

Comment on lines +658 to 662
options = EmbedderOptions(
label=info.get('label'),
supports=EmbedderSupports(**info.get('supports', {})),
dimensions=info.get('dimensions'),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to a previous comment, the logic for constructing EmbedderOptions here is inconsistent with the implementation in google.py. The implementation sets supports to None if the supports data is missing or empty, but this test creates an EmbedderSupports object with default values. This should be aligned to ensure the test is accurate and robust against future changes.

Suggested change
options = EmbedderOptions(
label=info.get('label'),
supports=EmbedderSupports(**info.get('supports', {})),
dimensions=info.get('dimensions'),
)
options = EmbedderOptions(
label=info.get('label'),
supports=EmbedderSupports(**s) if (s := info.get('supports')) else None,
dimensions=info.get('dimensions'),
)

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

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants