fix: force batch_size=1 for gemini-embedding-2 models#1474
Open
Maanik23 wants to merge 1 commit into
Open
Conversation
The gemini-embedding-2 and gemini-embedding-2-preview models do not support batching via embed_content(contents=[...]). They treat the list as parts of a single document and return only one embedding vector regardless of how many strings are passed. This caused create_batch() to silently return fewer vectors than inputs, leading to ValueError in downstream zip(..., strict=True) calls during entity deduplication. Fix: - Extend the existing batch_size=1 special case (already applied to gemini-embedding-001) to cover the -2 and -2-preview models. - Add a defensive length-mismatch check in create_batch() that triggers the per-item fallback path when the API returns fewer embeddings than requested. Closes getzep#1467
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
GeminiEmbedder.create_batch()silently returning fewer vectors than inputs when usinggemini-embedding-2-previeworgemini-embedding-2models.Closes #1467
Problem
The
gemini-embedding-2*models do not support batching viaembed_content(contents=[...]). They treat the list as parts of a single document and return only one embedding vector regardless of how many strings are passed.This caused
create_batch()to silently return fewer vectors than inputs, leading toValueErrorin downstreamzip(..., strict=True)calls during entity deduplication (e.g. in_semantic_candidate_search).Fix
Extend the
batch_size=1special case — the same defense already applied togemini-embedding-001is now applied to the-2and-2-previewmodels. This ensures each input is sent individually, matching the API's actual behavior.Add a defensive length-mismatch check — if a future model (or misconfiguration) causes the API to return fewer embeddings than requested,
create_batch()now detects this and triggers the existing per-item fallback path instead of silently returning partial results.Tests
Added 6 new tests covering:
gemini-embedding-2-previewdefaults tobatch_size=1gemini-embedding-2defaults tobatch_size=1gemini-embedding-001still defaults tobatch_size=1(existing behavior)batch_sizeoverrides model-specific default