Skip to content

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

@Prabindas001

Description

@Prabindas001

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

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())

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions