Class TextEmbeddingModel (1.38.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.

Parameters
Name Description
model_id str

Identifier of a Vertex LLM. Example: "text-bison@001"

endpoint_name typing.Optional[str]

Vertex Endpoint resource name for the model

from_pretrained

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

Loads a _ModelGardenModel.

Parameter
Name Description
model_name str

Name of the model.

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.TextEmbeddingInput]],
    *,
    auto_truncate: bool = True
) -> typing.List[vertexai.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.

get_embeddings_async

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

Asynchronously 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.