GoogleGenAIVectorizer.embed_many fails on gemini-embedding-2 for batches of more than one input
维护者通常 4 天内回复
评估
- 难度
- 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
Contentper input, sync and async. - An integration test, marked as an API test, running
embed_manyongemini-embedding-2with 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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
redis/redis-vl-python 的其他 Issue
-
SearchIndex.drop_keys does not validate cluster hash-tag co-location (inconsistent with drop_documents)可能已有人在做 @Hashim1999164 于 47 天前认领。 未关闭bug good first issue index
难度 2/5 1-3 小时 新手友好度 78/100
redis/redis-vl-python#601 · 2 条评论 ·
维护者通常 4 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
redis/redis-vl-python#889 ·
维护者通常 4 天内回复
-
Add image embedding to the Cohere vectorizer (Embed v4 and v5)可能已有人在做 @rahulsjha 于 1 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 58/100
redis/redis-vl-python#888 · 2 条评论 ·
维护者通常 4 天内回复
-
难度 5/5 一周以上 新手友好度 38/100
redis/redis-vl-python#887 ·
维护者通常 4 天内回复
-
难度 4/5 3-5 天 新手友好度 52/100
redis/redis-vl-python#885 ·
维护者通常 4 天内回复
查看 redis/redis-vl-python 的全部 Issue
相似的 Issue
-
resource-submission validation-passed
难度 1/5 1 小时以内 新手友好度 68/100
hesreallyhim/awesome-claude-code#3875 · 1 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 77/100
bvis/aegis-hass#725 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 67/100
datasektionen/cashflow#468 ·
-
dont call alembic upgrade until we check whether or not the cache DB has an alembic version stamp未关闭
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.x可能已有人在做 @NimaVaziri 今天认领。 未关闭Pytorch
难度 2/5 1-3 小时 新手友好度 78/100
NVIDIA/TensorRT-LLM#23406 ·
维护者通常 1 天内回复