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

Abierto
#886 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

@pcbeingused33 ya está trabajando en esto.

Desde el 2/12/2026.

  • #892 de @pcbeingused33 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
435
Forks
123
Merge medio
8 d 1 h
PR fusionados (30 d)
39

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de redis/redis-vl-python

Todos los issues de redis/redis-vl-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.