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 variableHUGGINGFACEHUB_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 if the input data cannot be parsed to form a valid model.
- 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]