Repository navigation
fix(py/plugins/google-genai): camelCase embedder options and request chunking - #6302
Conversation
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
Resolved all comments in a256a5a |
cabljac
left a comment
There was a problem hiding this comment.
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.
|
Sorry, missed that one last round. Done in |
cabljac
left a comment
There was a problem hiding this comment.
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.
429d878 to
ef594c1
Compare
|
Went with the plugin-local dump in |
cabljac
left a comment
There was a problem hiding this comment.
Approved, the cancellation handling and the chunk-content assertions both hold up really well. One thing worth a look inline.
ef594c1 to
9b89574
Compare
|
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 Once those land I'll do a follow-up in the plugin, nothing needed from you here:
The per-call-wins behavior and the per-backend Dev UI schema stay the same from the caller's side. |
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.