Skip to content

fix(py): embedders always receive an options dict - #6668

Merged
huangjeff5 merged 1 commit into
mainfrom
fix/py-embed-eval-options-dict
Oct 29, 2026
Merged

huangjeff5 merged 1 commit into
mainfrom
fix/py-embed-eval-options-dict

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Embedders now always receive their options as a dict. When the caller leaves config unset or passes config=None, the plugin gets {}, not None. This reverts the sub-decision from #6569 that passed None through, bringing embedders into alignment with models.

Evaluators originally included in this PR were removed because evaluators are excluded from the 1.0 cut and removed in #6947.

Stack

  1. fix(py): embedders always receive an options dict #6668: Embedder fns always get options as a dict, never None. (this PR)
  2. feat(py)!: one config class per action; typed options for embedders #6714: Annotate a config class to get a typed instance instead.
  3. feat(py)!: config pipeline: definition defaults, one merge, None is a value #6712: The values are filled the same way from every entry point.

Decisions

  • One rule for untyped actions: request.config on models and request.options on embedders are always a dict. Plugins can safely call req.options.get(...) without defensive req.options or {} guarding.
  • Normalized at the wire boundary: EmbedRequest.options defaults to {} and coerces None to {} during validation so direct Dev UI and CLI runs behave identically to ai.embed().
  • Same input validation as generate: ai.embed(config=...) accepts mappings and BaseModels (which serialize to set fields), while invalid non-mapping inputs raise INVALID_ARGUMENT.

Tests

  • Verified ai.embed and ai.embed_many pass {} when config is omitted or None.
  • Tested EmbedRequest wire parsing converts options: null to {}.

@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 updates the embedder and evaluator options handling to return and pass an empty dictionary ({}) instead of None when no configuration is provided, ensuring consistent dictionary types. Review feedback suggests simplifying a ternary check in _evaluator.py using req.options or {} directly, and using the dictionary union operator | instead of unpacking in _aio.py for better readability.

@huangjeff5
huangjeff5 requested a review from apascal07 October 8, 2026 06:41

@apascal07 apascal07 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The in-repo plugins and samples still follow the None contract this PR removes: request.options or {} in google-genai _embedder.py (158, 203, 391) and openai _openai_plugin.py:572, and options: dict | None = None in samples/evaluators/src/main.py, genkit_evaluators/plugin.py and _evaluators/_evaluation.py.

@huangjeff5
huangjeff5 force-pushed the fix/py-embed-eval-options-dict branch from 894add5 to 890b095 Compare October 9, 2026 06:58
@huangjeff5

Copy link
Copy Markdown
Contributor Author

@apascal07 on the plugins and samples: cleaned up in b238ee4. The google-genai _embedder.py (version overlay, multimodal dimension), OpenAI embed dimensions, genkit_evaluators, the Vertex evaluator fn and samples/evaluators now take options: dict with no None guard. I kept if request.options: in _genkit_to_googleai_cfg, because there an empty dict means "send no EmbedContentConfig"; it isn't a None guard.

Defaults from the declared config_schema are a follow-up; the design is in the _aio.py thread.

@huangjeff5

Copy link
Copy Markdown
Contributor Author

@apascal07 re the review body: handled in b238ee4. google-genai _embedder.py and openai _openai_plugin.py read request.options directly now (no or {}), and the evaluator fns in genkit-evaluators, the google-genai evaluators and samples/evaluators take options: dict[str, Any] without the None default. The evaluator parts drop out entirely once #6947 lands.

Reverts evaluator changes from this PR because evaluators are excluded from
the 1.0 cut and will be removed in #6947. Only embedders receive the options-dict
guarantee here.
@huangjeff5
huangjeff5 force-pushed the fix/py-embed-eval-options-dict branch from de3fd25 to 30862a5 Compare October 29, 2026 18:21
@huangjeff5

Copy link
Copy Markdown
Contributor Author

Reverted evaluator-related changes from this PR. Evaluators are excluded from the 1.0 cut and will be removed in #6947, so this PR now strictly covers the embedder options dict guarantee.

@huangjeff5 huangjeff5 changed the title fix(py): embedders and evaluators always receive an options dict fix(py): embedders always receive an options dict Oct 29, 2026
@huangjeff5

Copy link
Copy Markdown
Contributor Author

@apascal07 Reverted the evaluator changes from this PR since evaluators are excluded from the 1.0 cut and being removed in #6947. This PR now strictly scopes the empty-dict options guarantee to embedders.

@huangjeff5
huangjeff5 merged commit a396b21 into main Oct 29, 2026
27 checks passed
@huangjeff5
huangjeff5 deleted the fix/py-embed-eval-options-dict branch October 29, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants