HuggingFaceEndpointEmbeddings Class — langchain Architecture
Architecture documentation for the HuggingFaceEndpointEmbeddings class in huggingface_endpoint.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 3e578245_e691_a97e_a094_2b8fa981436a["HuggingFaceEndpointEmbeddings"] b1e4f760_c634_d3bf_ca9a_db7ab899cc4a["Embeddings"] 3e578245_e691_a97e_a094_2b8fa981436a -->|extends| b1e4f760_c634_d3bf_ca9a_db7ab899cc4a c4ce05a5_9880_dac7_9b75_ecf4c13b1db3["huggingface_endpoint.py"] 3e578245_e691_a97e_a094_2b8fa981436a -->|defined in| c4ce05a5_9880_dac7_9b75_ecf4c13b1db3 c582e38a_8544_dd68_2820_a5ffc6911877["validate_environment()"] 3e578245_e691_a97e_a094_2b8fa981436a -->|method| c582e38a_8544_dd68_2820_a5ffc6911877 bcc591c5_13d4_9230_07fe_b338b9fa9f55["embed_documents()"] 3e578245_e691_a97e_a094_2b8fa981436a -->|method| bcc591c5_13d4_9230_07fe_b338b9fa9f55 ca4be2a2_8892_c4d4_558c_825b2ba70690["aembed_documents()"] 3e578245_e691_a97e_a094_2b8fa981436a -->|method| ca4be2a2_8892_c4d4_558c_825b2ba70690 4ef55f39_d22f_e607_6c86_d27f1631763f["embed_query()"] 3e578245_e691_a97e_a094_2b8fa981436a -->|method| 4ef55f39_d22f_e607_6c86_d27f1631763f 7181a716_5760_c945_1c07_6223a3095f9d["aembed_query()"] 3e578245_e691_a97e_a094_2b8fa981436a -->|method| 7181a716_5760_c945_1c07_6223a3095f9d
Relationship Graph
Source Code
libs/partners/huggingface/langchain_huggingface/embeddings/huggingface_endpoint.py lines 15–172
class HuggingFaceEndpointEmbeddings(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:
```python
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",
)
```
"""
client: Any = None
async_client: Any = None
model: str | None = None
"""Model name to use."""
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)."""
repo_id: str | None = None
"""Huggingfacehub repository id, for backward compatibility."""
task: str | None = "feature-extraction"
"""Task to call the model with."""
model_kwargs: dict | None = None
"""Keyword arguments to pass to the model."""
huggingfacehub_api_token: str | None = Field(
default_factory=from_env("HUGGINGFACEHUB_API_TOKEN", default=None)
)
model_config = ConfigDict(
extra="forbid",
protected_namespaces=(),
)
@model_validator(mode="after")
def validate_environment(self) -> Self:
"""Validate that api key and python package exists in environment."""
huggingfacehub_api_token = self.huggingfacehub_api_token or os.getenv(
"HF_TOKEN"
)
try:
from huggingface_hub import ( # type: ignore[import]
AsyncInferenceClient,
InferenceClient,
)
if self.model:
self.repo_id = self.model
elif self.repo_id:
self.model = self.repo_id
else:
self.model = DEFAULT_MODEL
self.repo_id = DEFAULT_MODEL
client = InferenceClient(
model=self.model,
token=huggingfacehub_api_token,
provider=self.provider, # type: ignore[arg-type]
)
async_client = AsyncInferenceClient(
model=self.model,
token=huggingfacehub_api_token,
provider=self.provider, # type: ignore[arg-type]
Extends
Source
Frequently Asked Questions
What is the HuggingFaceEndpointEmbeddings class?
HuggingFaceEndpointEmbeddings is a class in the langchain codebase, defined in libs/partners/huggingface/langchain_huggingface/embeddings/huggingface_endpoint.py.
Where is HuggingFaceEndpointEmbeddings defined?
HuggingFaceEndpointEmbeddings is defined in libs/partners/huggingface/langchain_huggingface/embeddings/huggingface_endpoint.py at line 15.
What does HuggingFaceEndpointEmbeddings extend?
HuggingFaceEndpointEmbeddings extends Embeddings.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free