Skip to content

embed_content has different behavior with and without vertex AI #2165

@arnaud-secondlayer

Description

@arnaud-secondlayer

Today embed_content does behave differently depending on how the client was created (with API_KEY or vertex ai) for gemini-embedding-2-preview". The issue for vertex AI is we cannot get embeddings of multiple texts with a single requests, we need a request per text.
Is it a behavior you're planning to keep, or do you plan to update at some point?

import os

import google.auth
import vertexai
from google import genai

contents = ["The dog is cute", "The cat is cute"]

api_client = genai.Client(api_key="XXXXX")
embeddings = api_client.models.embed_content(model="gemini-embedding-2-preview", contents=contents).embeddings
assert len(embeddings) == 2


_, project = google.auth.default()
vertexai.init(project=project, location="us-central1")
vertex_ai_client = genai.Client(vertexai=True, project=project, location="us-central1")
embeddings = vertex_ai_client.models.embed_content(model="gemini-embedding-2-preview", contents=contents).embeddings
assert len(embeddings) == 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p3Desirable enhancement or fix. May not be included in next release.type: questionRequest for information or clarification. Not an issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions