Skip to content

fix(py/plugins/google-genai): camelCase embedder options and request chunking - #6302

Merged
cabljac merged 2 commits into
mainfrom
fix/py-google-genai-embedder-options-batching
Oct 15, 2026
Merged

cabljac merged 2 commits into
mainfrom
fix/py-google-genai-embedder-options-batching

Conversation

@hilariie

@hilariie hilariie commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6187

Summary

Embedder settings now have a typed config class (EmbeddingConfig), exported from the package root.

  • You can pass it, or a plain dict, to GoogleAI.embedding() and VertexAI.embedding(). ai.embed(config=...) takes a dict.

  • Keys work in snake_case or camelCase, so task_type and taskType both work. If you pass both spellings, camelCase wins.

  • A typo or a bad value now raises an INVALID_ARGUMENT error that names the key, instead of being silently ignored.

  • task_type suggests the known task types in your editor but still accepts any string.

  • mime_type and auto_truncate only work on Vertex AI. On the Gemini API they are dropped with a warning.

  • Settings on the ref and settings passed to ai.embed() merge per key, and the call’s value wins whichever spelling either side uses.

Large requests are now split into batches the API accepts:

  • 100 documents per call on the Gemini API

  • 250 per call on Vertex text-embedding models

  • 1 per call on Vertex gemini-* models

Up to 10 batches run at once, and results come back in input order. If one batch fails, the batches that haven’t started are cancelled. If you cancel the call, the requests in flight are cancelled too.

Vertex multimodal embedding now accepts several documents by sending one request per document. Before, it rejected more than one.

Verification

Checked that the per-call value reaches the API for every mix of spellings on both backends. Checked that batching, ordering, failure handling and cancellation behave on Python 3.10 and 3.12.

@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 structured configuration schemas (EmbeddingConfigSchema and VertexEmbeddingConfigSchema) using Pydantic for Google GenAI and Vertex AI embedders. It also implements batching for text embedding requests and updates multimodal embedding to process multiple documents sequentially rather than rejecting them. The feedback recommends executing both text embedding batches and multimodal embedding requests concurrently using asyncio.gather with a semaphore to reduce latency, which also requires importing asyncio.

@cabljac cabljac 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.

The :predict request_dict assertions and the reverse-completion ordering test are the right shape. One fix, rest inline.

_run_bounded doesn't cancel its children when the outer generate() is cancelled. asyncio.wait doesn't propagate, so on abort or timeout the in-flight calls keep running and billing. The FIRST_EXCEPTION path is fine, it's just the outer-cancel case. BaseException handler, cancel pending, gather with return_exceptions, re-raise. Floor is 3.10 so no TaskGroup. Or drop the concurrency, which #6187 doesn't ask for anyway, and it goes away.

One that can't anchor inline: google.py:533 still types config as dict[str, object] while this PR exports the two schemas, so passing a typed instance is a pyright error even though _parse_options handles it. The dict typing predates this (#6104), the mismatch doesn't.

Also, not this PR: Go batches gemini-embedding-001 at 250 (embedder.go:35) against the Vertex doc's "each request can only include a single input text". Your 1 is right, Go's wrong.

#6187

@hilariie

Copy link
Copy Markdown
Contributor Author

Resolved all comments in a256a5a

@hilariie
hilariie requested a review from cabljac September 14, 2026 16:39

@cabljac cabljac 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.

The cancellation fix and its test are right, and the dropped-option warning is what I was after. One item from the last round is still open, it wasn't inline-anchored so easy to miss. Two nits inline.

google.py:533 still types config as dict[str, object] | None. Passing an EmbeddingConfigSchema instance is a pyright error even though _parse_options accepts it. EmbedderRef.config is Any, so widening to EmbeddingConfigSchema | dict[str, object] | None is enough. Same type on family_embedder_ref in _model_refs.py:110.

#6187

@hilariie

Copy link
Copy Markdown
Contributor Author

Sorry, missed that one last round. Done in 429d8781b: embedding() and family_embedder_ref take EmbeddingConfigSchema | dict[str, object] | None, with a test passing an instance through.

@cabljac cabljac 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.

The cancellation handling and the reverse-completion ordering tests hold up well, and every point from the last round is either done or declined for a sound reason. One thing to dig into, which is on me, then a couple of small ones.

The typed config widening I asked for type-checks but crashes on first use: Ai.embed() does {**embedder.config} and a BaseModel is not a mapping. With a fake key, GoogleAI.embedding('gemini-embedding-001', config=EmbeddingConfigSchema(task_type=...)) raises TypeError: 'EmbeddingConfigSchema' object is not a mapping before any network call (with version= set it fails one line earlier on item assignment). Two options: normalise in core embed() with model_dump(exclude_none=True), or dump to a dict inside family_embedder_ref. Which would you prefer? Either way it needs a test that goes through ai.embed, not just ref.config is config.

@hilariie
hilariie force-pushed the fix/py-google-genai-embedder-options-batching branch from 429d878 to ef594c1 Compare September 22, 2026 17:16
@hilariie

Copy link
Copy Markdown
Contributor Author

Went with the plugin-local dump in dac44f45d, with a test through ai.embed() asserting task type, dimensionality and version reach the SDK call. Snake_case keys keep per-call options winning in either spelling, since camelCase only wins when both are present.

@cabljac cabljac 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.

Approved, the cancellation handling and the chunk-content assertions both hold up really well. One thing worth a look inline.

@hilariie
hilariie force-pushed the fix/py-google-genai-embedder-options-batching branch from ef594c1 to 9b89574 Compare October 13, 2026 08:53
@hilariie

Copy link
Copy Markdown
Contributor Author

I rebased this onto main as two commits, since a lot changed underneath. 1aee987 is the approved change updated to the current conventions: one exported EmbeddingConfig, no enums, and unknown keys now raise like the other config classes do. 9b89574 is the fix for your open comment.

@cabljac
cabljac requested a review from huangjeff5 October 14, 2026 08:22
@huangjeff5

Copy link
Copy Markdown
Contributor

Fine to land as-is. One heads-up so "camelCase wins" doesn't get documented as a contract.

Today core merges ref config and call config as raw dicts, so {'task_type': ...} from the ref and {'taskType': ...} from the call both reach _parse_options, and _camel_case_key_wins is what makes the call win. #6712 moves that into core: overlay_config folds each layer to the key the action's config class accepts before merging, so the two spellings become one slot and the last layer wins. Separately, #6697's GenkitConfig treats both spellings in one input as an error, so neither silently wins. That's the convention I'd like embedder config to land on too, which is easy once core does the folding.

Once those land I'll do a follow-up in the plugin, nothing needed from you here:

  • register the embedder with config_schema=EmbeddingConfig so core folds and validates at the action boundary
  • drop _camel_case_key_wins and the snake_case dump in family_embedder_ref; GoogleAI.embedding() returns EmbedderRef[EmbeddingConfig] holding the instance
  • EmbeddingConfig subclasses GenkitConfig
  • the Vertex-only drop warning goes through genkit.plugin_api.get_logger (feat(py)!: plugin helpers live on genkit.plugin_api; plugins log through genkit.get_logger #6764) so it reaches the Dev UI

The per-call-wins behavior and the per-backend Dev UI schema stay the same from the caller's side.

@cabljac
cabljac merged commit 59ba69c into main Oct 15, 2026
27 checks passed
@cabljac
cabljac deleted the fix/py-google-genai-embedder-options-batching branch October 15, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(py/plugins/google-genai): embedder options are snake_case only and requests are unbatched

3 participants