Skip to content

Migrate VertexAIEmbeddings to use google-genai SDK #430

@datasherlock

Description

@datasherlock

The current implementation of the VertexAIEmbeddings class, found in the provided code snippet, uses the deprecated vertexai SDK for Google's Generative AI models.

To ensure compatibility, access to the latest features, and adherence to Google's recommended library usage, this component should be migrated to use the google-genai Python SDK.

The specific parts of the code that use the legacy SDK are the imports and calls related to TextEmbeddingModel and TextEmbeddingInput:

try:
    from vertexai.language_models import TextEmbeddingInput, TextEmbeddingModel
except (ImportError, AttributeError):
    TextEmbeddingModel = TextEmbeddingInput = None  # type: ignore[misc, assignment]

# ... inside VertexAIEmbeddings __init__
self.model = TextEmbeddingModel.from_pretrained(model)

# ... inside VertexAIEmbeddings _embed_query
inputs: list[str | TextEmbeddingInput] = [
    TextEmbeddingInput(text, task_type)
]
embeddings = self.model.get_embeddings(inputs, **kwargs)

Action Items:

  1. Update the dependency to use google-genai instead of or alongside vertexai.
  2. Modify the VertexAIEmbeddings class to use the corresponding methods and classes from google-genai (e.g., client.models.generate_embeddings).
  3. Ensure the migration follows the official guide provided by Google for the SDK deprecation.

Reference:
The migration guide for the Vertex AI SDK deprecation can be found here:
https://cloud.google.com/vertex-ai/generative-ai/docs/deprecations/genai-vertexai-sdk.md

from vertexai.language_models import TextEmbeddingInput, TextEmbeddingModel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions