HuggingFaceEndpointEmbeddings#

class langchain_huggingface.embeddings.huggingface_endpoint.HuggingFaceEndpointEmbeddings[source]#

Bases: BaseModel, Embeddings

HuggingFaceHub embedding models.

To use, you should have the huggingface_hub python package installed, and the environment variable HUGGINGFACEHUB_API_TOKEN set with your API token, or pass it as a named parameter to the constructor.

Example

from langchain_huggingface import HuggingFaceEndpointEmbeddings
model = "sentence-transformers/all-mpnet-base-v2"
hf = HuggingFaceEndpointEmbeddings(
    model=model,
    task="feature-extraction",
    huggingfacehub_api_token="my-api-key",
)

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

param huggingfacehub_api_token: str | None [Optional]#
param model: str | None = None#

Model name to use.

param model_kwargs: dict | None = None#

Keyword arguments to pass to the model.

param provider: str | None = None#

Name of the provider to use for inference with the model specified in repo_id. e.g. “sambanova”. if not specified, defaults to HF Inference API. available providers can be found in the [huggingface_hub documentation](https://huggingface.co/docs/huggingface_hub/guides/inference#supported-providers-and-tasks).

param repo_id: str | None = None#

Huggingfacehub repository id, for backward compatibility.

param task: str | None = 'feature-extraction'#

Task to call the model with.

async aembed_documents(
texts: list[str],
) list[list[float]][source]#

Async Call to HuggingFaceHub’s embedding endpoint for embedding search docs.

Parameters:

texts (list[str]) – The list of texts to embed.

Returns:

List of embeddings, one for each text.

Return type:

list[list[float]]

async aembed_query(
text: str,
) list[float][source]#

Async Call to HuggingFaceHub’s embedding endpoint for embedding query text.

Parameters:

text (str) – The text to embed.

Returns:

Embeddings for the text.

Return type:

list[float]

embed_documents(
texts: list[str],
) list[list[float]][source]#

Call out to HuggingFaceHub’s embedding endpoint for embedding search docs.

Parameters:

texts (list[str]) – The list of texts to embed.

Returns:

List of embeddings, one for each text.

Return type:

list[list[float]]

embed_query(
text: str,
) list[float][source]#

Call out to HuggingFaceHub’s embedding endpoint for embedding query text.

Parameters:

text (str) – The text to embed.

Returns:

Embeddings for the text.

Return type:

list[float]