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

オープン
#886 コメント 0 件 リアクション 0 件 担当者 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時間
マージ済み PR(30日)
39

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

redis/redis-vl-python のほかの issue

redis/redis-vl-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。