HuggingFaceEmbeddings#
- class langchain_community.embeddings.huggingface.HuggingFaceEmbeddings[source]#
Bases:
BaseModel
,Embeddings
Deprecated since version 0.2.2: Use
langchain_huggingface.HuggingFaceEmbeddings
instead.HuggingFace sentence_transformers embedding models.
To use, you should have the
sentence_transformers
python package installed.Example
from langchain_community.embeddings import HuggingFaceEmbeddings model_name = "sentence-transformers/all-mpnet-base-v2" model_kwargs = {'device': 'cpu'} encode_kwargs = {'normalize_embeddings': False} hf = HuggingFaceEmbeddings( model_name=model_name, model_kwargs=model_kwargs, encode_kwargs=encode_kwargs )
Initialize the sentence_transformer.
- param cache_folder: str | None = None#
Path to store models. Can be also set by SENTENCE_TRANSFORMERS_HOME environment variable.
- param encode_kwargs: Dict[str, Any] [Optional]#
Keyword arguments to pass when calling the encode method of the Sentence Transformer model, such as prompt_name, prompt, batch_size, precision, normalize_embeddings, and more. See also the Sentence Transformer documentation: https://sbert.net/docs/package_reference/SentenceTransformer.html#sentence_transformers.SentenceTransformer.encode
- param model_kwargs: Dict[str, Any] [Optional]#
Keyword arguments to pass to the Sentence Transformer model, such as device, prompts, default_prompt_name, revision, trust_remote_code, or token. See also the Sentence Transformer documentation: https://sbert.net/docs/package_reference/SentenceTransformer.html#sentence_transformers.SentenceTransformer
- param model_name: str = 'sentence-transformers/all-mpnet-base-v2'#
Model name to use.
- param multi_process: bool = False#
Run encode() on multiple GPUs.
- param show_progress: bool = False#
Whether to show a progress bar.
- async aembed_documents(texts: List[str]) List[List[float]] #
Asynchronous Embed search docs.
- Parameters:
texts (List[str]) – List of text to embed.
- Returns:
List of embeddings.
- Return type:
List[List[float]]
- async aembed_query(text: str) List[float] #
Asynchronous Embed query text.
- Parameters:
text (str) – Text to embed.
- Returns:
Embedding.
- Return type:
List[float]
Examples using HuggingFaceEmbeddings