HuggingFaceHubEmbeddings#

class langchain_community.embeddings.huggingface_hub.HuggingFaceHubEmbeddings[source]#

Bases: BaseModel, Embeddings

Deprecated since version 0.2.2: Use :class:`~langchain_huggingface.HuggingFaceEndpointEmbeddings` instead.

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_community.embeddings import HuggingFaceHubEmbeddings
model = "sentence-transformers/all-mpnet-base-v2"
hf = HuggingFaceHubEmbeddings(
    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 = None#
param model: str | None = None#

Model name to use.

param model_kwargs: dict | None = None#

Keyword arguments to pass to the model.

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]

Examples using HuggingFaceHubEmbeddings