Hugging Face
All functionality related toHugging Face Hub and libraries liketransformers,sentence transformers, anddatasets.
Hugging Face is an AI platform with all major open source models, datasets, MCPs, and demos.It supplies model inference locally and via serverlessInference Providers.
You can useInference Providers to run open source models like DeepSeek R1 on scalable serverless infrastructure.
Installation
Most of the Hugging Face integrations are available in thelangchain-huggingface
package.
pip install langchain-huggingface
Chat models
ChatHuggingFace
We can use theHugging Face
LLM classes or directly use theChatHuggingFace
class.
See ausage example.
from langchain_huggingfaceimport ChatHuggingFace
LLMs
HuggingFaceEndpoint
We can use theHuggingFaceEndpoint
class to run open source models via serverlessInference Providers or via dedicatedInference Endpoints.
See ausage example.
from langchain_huggingfaceimport HuggingFaceEndpoint
HuggingFacePipeline
We can use theHuggingFacePipeline
class to run open source models locally.
See ausage example.
from langchain_huggingfaceimport HuggingFacePipeline
Embedding Models
HuggingFaceEmbeddings
We can use theHuggingFaceEmbeddings
class to run open source embedding models locally.
See ausage example.
from langchain_huggingfaceimport HuggingFaceEmbeddings
HuggingFaceEndpointEmbeddings
We can use theHuggingFaceEndpointEmbeddings
class to run open source embedding models via a dedicatedInference Endpoint.
See ausage example.
from langchain_huggingfaceimport HuggingFaceEndpointEmbeddings
HuggingFaceInferenceAPIEmbeddings
We can use theHuggingFaceInferenceAPIEmbeddings
class to run open source embedding models viaInference Providers.
See ausage example.
from langchain_community.embeddingsimport HuggingFaceInferenceAPIEmbeddings
HuggingFaceInstructEmbeddings
We can use theHuggingFaceInstructEmbeddings
class to run open source embedding models locally.
See ausage example.
from langchain_community.embeddingsimport HuggingFaceInstructEmbeddings
HuggingFaceBgeEmbeddings
BGE models on the HuggingFace are one ofthe best open-source embedding models.BGE model is created by theBeijing Academy of Artificial Intelligence (BAAI).
BAAI
is a private non-profit organization engaged in AI research and development.
See ausage example.
from langchain_community.embeddingsimport HuggingFaceBgeEmbeddings
Document Loaders
Hugging Face dataset
Hugging Face Hub is home to over 75,000datasets in more than 100 languagesthat can be used for a broad range of tasks across NLP, Computer Vision, and Audio.They used for a diverse range of tasks such as translation, automatic speechrecognition, and image classification.
We need to installdatasets
python package.
pip install datasets
See ausage example.
from langchain_community.document_loaders.hugging_face_datasetimport HuggingFaceDatasetLoader
Hugging Face model loader
Load model information from
Hugging Face Hub
, including README content.This loader interfaces with the
Hugging Face Models API
to fetchand load model metadata and README files.The API allows you to search and filter models based onspecific criteria such as model tags, authors, and more.
from langchain_community.document_loadersimport HuggingFaceModelLoader
Image captions
It uses the Hugging Face models to generate image captions.
We need to install several python packages.
pip install transformers pillow
See ausage example.
from langchain_community.document_loadersimport ImageCaptionLoader
Tools
Hugging Face Hub Tools
Hugging Face Toolssupport text I/O and are loaded using the
load_huggingface_tool
function.
We need to install several python packages.
pip install transformers huggingface_hub
See ausage example.
from langchain_community.agent_toolkits.load_toolsimport load_huggingface_tool
Hugging Face Text-to-Speech Model Inference.
It is a wrapper around
OpenAI Text-to-Speech API
.
from langchain_community.tools.audioimport HuggingFaceTextToSpeechModelInference