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

Đang mở
#886 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

@pcbeingused33 đang làm issue này rồi.

Từ ngày 2/12/2026.

  • #892 của @pcbeingused33 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
machine-learning

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
435
Fork
123
Merge trung bình
8 ngày 1 giờ
Pull request đã merge (30 ngày)
39

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của redis/redis-vl-python

Tất cả issue của redis/redis-vl-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.