GoogleGenAIVectorizer.embed_many fails on gemini-embedding-2 for batches of more than one input

Aperta
#886 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

@pcbeingused33 ci sta già lavorando.

Dal 2/12/2026.

  • #892 di @pcbeingused33 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Start with redisvl/utils/vectorize/googlegenai.py, especially _embed_many, _aembed_many, and _embeddings_from_response; the issue also specifies mocked sync and async tests. Check the open pull request #892 before taking this on. Done means batches send one Content per input and return one vector per input for both models.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

GoogleGenAIVectorizer.embed_many() and aembed_many() fail on gemini-embedding-2 whenever a batch holds more than one string. The model merges every entry in a contents list into one vector, so the vectorizer gets one embedding back for N inputs and raises.

Reproduction

from redisvl.utils.vectorize import GoogleGenAIVectorizer

vz = GoogleGenAIVectorizer(model="gemini-embedding-2", api_config={"api_key": "..."})
vz.embed_many(["The cat sat on the mat.", "Paris is in France."])
# ValueError: Google GenAI API returned 1 embedding(s) for 2 input(s).

embed() and aembed() with a single string are unaffected, as is gemini-embedding-001.

Cause

_embed_many and _aembed_many send each batch as contents=batch, a list of strings (redisvl/utils/vectorize/googlegenai.py:336 and :376). _embeddings_from_response then checks that the count matches.

The API treats a list of strings differently per model. We measured this on the Gemini API on 2026-12-02 with google-genai 1.75.0:

contents for three inputs gemini-embedding-001 gemini-embedding-2
["a", "b", "c"] 3 vectors 1 vector
[Content(parts=[a]), Content(parts=[b]), Content(parts=[c])] 3 vectors 3 vectors

Google's embeddings docs describe the same thing: on gemini-embedding-2, several parts in one request are aggregated into one embedding.

Fix

Wrap each input in its own types.Content in _embed_many and _aembed_many. This gives one vector per input on both models, and for gemini-embedding-001 it keeps the current one-vector-per-string result.

Tests

  • A unit test with a mocked client asserting that each batch is sent as one Content per input, sync and async.
  • An integration test, marked as an API test, running embed_many on gemini-embedding-2 with more than one input.

We have not checked the Vertex AI backend. It uses the same embed_content call, so it is expected to behave the same.

Lingua principale
Python
Stelle
435
Fork
123
Merge medio
8g 1h
PR unite (30g)
39

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di redis/redis-vl-python

Tutte le issue di redis/redis-vl-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.