Class TextEmbeddingModel (1.31.1)

TextEmbeddingModel(model_id: str, endpoint_name: typing.Optional[str] = None)

TextEmbeddingModel class calculates embeddings for the given texts.

Examples::

# Getting embedding:
model = TextEmbeddingModel.from_pretrained("textembedding-gecko@001")
embeddings = model.get_embeddings(["What is life?"])
for embedding in embeddings:
    vector = embedding.values
    print(len(vector))

Methods

TextEmbeddingModel

TextEmbeddingModel(model_id: str, endpoint_name: typing.Optional[str] = None)

Creates a LanguageModel.

This constructor should not be called directly. Use LanguageModel.from_pretrained(model_name=...) instead.

from_pretrained

from_pretrained(model_name: str) -> vertexai._model_garden._model_garden_models.T

Loads a _ModelGardenModel.

Exceptions
Type Description
ValueError If model_name is unknown.
ValueError If model does not support this class.

get_embeddings

get_embeddings(
    texts: typing.List[
        typing.Union[str, vertexai.language_models._language_models.TextEmbeddingInput]
    ],
    *,
    auto_truncate: bool = True
) -> typing.List[vertexai.language_models._language_models.TextEmbedding]

Calculates embeddings for the given texts.

Parameters
Name Description
texts str

A list of texts or TextEmbeddingInput objects to embed.

auto_truncate bool

Whether to automatically truncate long texts. Default: True.