Skip to main content
本页面涵盖了 LangChain 与Hugging Face Hub and libraries like transformers, sentence transformers, and datasets.

聊天模型

ChatHuggingFace

我们可以使用 Hugging Face LLM classes or directly use the ChatHuggingFace class. 查看使用示例.

大语言模型 (LLM)

HuggingFaceEndpoint

我们可以使用 HuggingFaceEndpoint class to run open source models via serverless Inference Providers or via dedicated Inference Endpoints. 查看使用示例.

HuggingFacePipeline

我们可以使用 HuggingFacePipeline class to run open source models locally. 查看使用示例.

向量嵌入模型

HuggingFaceEmbeddings

我们可以使用 HuggingFaceEmbeddings class to run open source embedding models locally. 查看使用示例.

HuggingFaceEndpointEmbeddings

我们可以使用 HuggingFaceEndpointEmbeddings class to run open source embedding models via a dedicated Inference Endpoint. 查看使用示例.

Text Embeddings Inference (TEI)

For self-hosted production serving of Sentence Transformers models, Hugging Face publishes Text Embeddings Inference, a dedicated inference server with batching and GPU support. Point LangChain at a TEI deployment via HuggingFaceEndpointEmbeddings or see the dedicated TEI integration guide.

BGE embedding models

BGE models on Hugging Face are a strong open-source embedding family from the Beijing Academy of Artificial Intelligence (BAAI).
BGE models are Sentence Transformers models, so use HuggingFaceEmbeddings with encode_kwargs={"normalize_embeddings": True}. 查看使用示例.

Legacy embedding classes

The following classes from langchain-community predate langchain-huggingface. Prefer HuggingFaceEmbeddings or HuggingFaceEndpointEmbeddings for new projects:
  • HuggingFaceInferenceAPIEmbeddings (langchain_community.embeddings): deprecated since langchain-community==0.2.2 in favor of HuggingFaceEndpointEmbeddings from langchain-huggingface, which covers both Inference Providers (provider="hf-inference" etc.) and dedicated Inference Endpoints.
  • HuggingFaceInstructEmbeddings (langchain_community.embeddings): use HuggingFaceEmbeddings with a modern instruction-aware model and encode_kwargs={"prompt": ...}. See Instructor embeddings.
  • HuggingFaceBgeEmbeddings (langchain_community.embeddings): use HuggingFaceEmbeddings with encode_kwargs={"normalize_embeddings": True}, and set query_encode_kwargs={"prompt": "..."} when the model needs a query prefix (e.g., the older BAAI/bge-*-en-v1.5 family). See BGE on Hugging Face.

文档加载器

Hugging Face dataset

Hugging Face Hub is home to over 75,000 datasets in more than 100 languages that 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 speech recognition, and image classification.
我们需要安装 datasets Python 包.
查看使用示例.

Hugging Face model loader

Load model information from Hugging Face Hub, including README content. This loader interfaces with the Hugging Face Models API to fetch and load model metadata and README files. The API allows you to search and filter models based on specific criteria such as model tags, authors, and more.

Image captions

它使用 the Hugging Face models to generate image captions. 我们需要安装几个 Python 包。
查看使用示例.

工具

Hugging Face hub tools

Hugging Face Tools support text I/O and are loaded 使用 load_huggingface_tool function.
我们需要安装几个 Python 包。
查看使用示例.

Hugging Face Text-to-Speech model inference.

It 是一个封装器 around OpenAI Text-to-Speech API.