googleapis / googleapis/python-genai

embed_content() raises ValueError for multiple Content objects with gemini-embedding-2 on Enterprise

Open
#2,567 7 comments 0 reactions 1 assignee Claimed by @Venkaiahbabuneelam View on GitHub
priority: p2 type: bug
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

#### Environment details

* Programming language: Python
* OS: macOS Tahoe 26.5.1 (25F80)
* Language runtime version: Python 3.10.18
* Package version: google-genai 2.8.0

#### Description

When using `Models.embed_content()` with `gemini-embedding-2` on the Enterprise Agent Platform (`enterprise=True`), the Python SDK raises a client-side `ValueError` when more than one `Content` object is provided in `contents`.

However:

* The method signature accepts `ContentListUnion`.
* The docstring describes `contents` as `list[Content]`.
* The multimodal embeddings documentation states:

> Multiple entries: Sending multiple entries in the contents array returns separate embeddings for each entry.

* The Gemini Enterprise multimodal embeddings documentation also documents multiple entries and up to 6 images per request.
* The exception is raised by the SDK before any request is sent to the backend.

#### Steps to reproduce

```python
import asyncio

from google import genai
from google.genai import types

client = genai.Client(
enterprise=True,
project="PROJECT_ID",
location="global",
)

MODEL = "gemini-embedding-2"

async def main():
image_bytes = open("1.png", "rb").read()

contents = [
types.Content(
parts=[
types.Part.from_bytes(
data=image_bytes,
mime_type="image/png",
)
]
)
for _ in range(6)
]

result = await client.aio.models.embed_content(
model=MODEL,
contents=contents,
)

print(len(result.embeddings))

asyncio.run(main())

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.