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

未关闭
#886 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

@pcbeingused33 已经在做这个了。

开始于 2026年12月2日。

  • #892 来自 @pcbeingused33 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
435
派生
123
平均合并
8 天 1 小时
30 天内合并 PR
39

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

redis/redis-vl-python 的其他 Issue

查看 redis/redis-vl-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。