huggingface.py — langchain Source File
Architecture documentation for huggingface.py, a python file in the langchain codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 012ca17f_7b56_304b_ccc3_cc98348f8542["huggingface.py"] feec1ec4_6917_867b_d228_b134d0ff8099["typing"] 012ca17f_7b56_304b_ccc3_cc98348f8542 --> feec1ec4_6917_867b_d228_b134d0ff8099 918b8514_ba55_6df2_7254_4598ec160e33["langchain_core.embeddings"] 012ca17f_7b56_304b_ccc3_cc98348f8542 --> 918b8514_ba55_6df2_7254_4598ec160e33 dd5e7909_a646_84f1_497b_cae69735550e["pydantic"] 012ca17f_7b56_304b_ccc3_cc98348f8542 --> dd5e7909_a646_84f1_497b_cae69735550e 1328b9c9_3768_8a4f_9ad2_cb8a80e1d754["langchain_huggingface.utils.import_utils"] 012ca17f_7b56_304b_ccc3_cc98348f8542 --> 1328b9c9_3768_8a4f_9ad2_cb8a80e1d754 a1f5764a_eeb1_9b85_0331_d058a9fa5f52["sentence_transformers"] 012ca17f_7b56_304b_ccc3_cc98348f8542 --> a1f5764a_eeb1_9b85_0331_d058a9fa5f52 61db497a_ac49_b518_5164_84054d9d7056["optimum.intel"] 012ca17f_7b56_304b_ccc3_cc98348f8542 --> 61db497a_ac49_b518_5164_84054d9d7056 style 012ca17f_7b56_304b_ccc3_cc98348f8542 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
from typing import Any
from langchain_core.embeddings import Embeddings
from pydantic import BaseModel, ConfigDict, Field
from langchain_huggingface.utils.import_utils import (
IMPORT_ERROR,
is_ipex_available,
is_optimum_intel_available,
is_optimum_intel_version,
)
_MIN_OPTIMUM_VERSION = "1.22"
class HuggingFaceEmbeddings(BaseModel, Embeddings):
"""HuggingFace sentence_transformers embedding models.
To use, you should have the `sentence_transformers` python package installed.
Example:
```python
from langchain_huggingface 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,
)
```
"""
model_name: str = Field(
default="sentence-transformers/all-mpnet-base-v2", alias="model"
)
"""Model name to use."""
cache_folder: str | None = None
"""Path to store models.
Can be also set by SENTENCE_TRANSFORMERS_HOME environment variable."""
model_kwargs: dict[str, Any] = Field(default_factory=dict)
"""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"""
encode_kwargs: dict[str, Any] = Field(default_factory=dict)
"""Keyword arguments to pass when calling the `encode` method for the documents 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"""
query_encode_kwargs: dict[str, Any] = Field(default_factory=dict)
"""Keyword arguments to pass when calling the `encode` method for the query 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"""
multi_process: bool = False
"""Run encode() on multiple GPUs."""
// ... (113 more lines)
Domain
Subdomains
Classes
Dependencies
- langchain_core.embeddings
- langchain_huggingface.utils.import_utils
- optimum.intel
- pydantic
- sentence_transformers
- typing
Source
Frequently Asked Questions
What does huggingface.py do?
huggingface.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What does huggingface.py depend on?
huggingface.py imports 6 module(s): langchain_core.embeddings, langchain_huggingface.utils.import_utils, optimum.intel, pydantic, sentence_transformers, typing.
Where is huggingface.py in the architecture?
huggingface.py is located at libs/partners/huggingface/langchain_huggingface/embeddings/huggingface.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/partners/huggingface/langchain_huggingface/embeddings).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free