text-embeddings-inference 文档

快速导览

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

快速导览

文本嵌入

开始使用 TEI 最简单的方法是使用官方 Docker 容器之一(请参阅支持的模型和硬件以选择合适的容器)。

在确保您的硬件受支持后,如果您计划使用 GPU,请安装 NVIDIA Container Toolkit。您设备上的 NVIDIA 驱动程序需要与 CUDA 12.2 或更高版本兼容。

接下来,按照他们的安装说明安装 Docker。

最后,部署您的模型。假设您想使用 BAAI/bge-large-en-v1.5。以下是您可以执行此操作的方法

model=BAAI/bge-large-en-v1.5
volume=$PWD/data

docker run --gpus all -p 8080:80 -v $volume:/data --pull always ghcr.io/huggingface/text-embeddings-inference:1.6 --model-id $model

我们还建议与 Docker 容器共享卷 (volume=$PWD/data),以避免每次运行都下载权重。

部署模型后,您可以通过发送请求来使用 embed 端点

curl 127.0.0.1:8080/embed \
    -X POST \
    -d '{"inputs":"What is Deep Learning?"}' \
    -H 'Content-Type: application/json'

重排序器

重排序器模型是序列分类交叉编码器模型,具有单个类,用于对查询和文本之间的相似性进行评分。

请参阅 LlamaIndex 团队的这篇博文,了解如何在 RAG 管道中使用重排序器模型来提高下游性能。

假设您想使用 BAAI/bge-reranker-large

model=BAAI/bge-reranker-large
volume=$PWD/data

docker run --gpus all -p 8080:80 -v $volume:/data --pull always ghcr.io/huggingface/text-embeddings-inference:1.6 --model-id $model

部署模型后,您可以使用 rerank 端点对查询和文本列表之间的相似性进行排名

curl 127.0.0.1:8080/rerank \
    -X POST \
    -d '{"query":"What is Deep Learning?", "texts": ["Deep Learning is not...", "Deep learning is..."], "raw_scores": false}' \
    -H 'Content-Type: application/json'

序列分类

您还可以使用经典的序列分类模型,例如 SamLowe/roberta-base-go_emotions

model=SamLowe/roberta-base-go_emotions
volume=$PWD/data

docker run --gpus all -p 8080:80 -v $volume:/data --pull always ghcr.io/huggingface/text-embeddings-inference:1.6 --model-id $model

部署模型后,您可以使用 predict 端点来获取与输入最相关的情绪

curl 127.0.0.1:8080/predict \
    -X POST \
    -d '{"inputs":"I like you."}' \
    -H 'Content-Type: application/json'

批量处理

您可以在一个批次中发送多个输入。例如,对于嵌入

curl 127.0.0.1:8080/embed \
    -X POST \
    -d '{"inputs":["Today is a nice day", "I like you"]}' \
    -H 'Content-Type: application/json'

对于序列分类

curl 127.0.0.1:8080/predict \
    -X POST \
    -d '{"inputs":[["I like you."], ["I hate pineapples"]]}' \
    -H 'Content-Type: application/json'

气隙部署

要在气隙环境部署 Text Embeddings Inference,请先下载权重,然后使用卷将它们挂载到容器中。

例如

# (Optional) create a `models` directory
mkdir models
cd models

# Make sure you have git-lfs installed (https://git-lfs.com)
git lfs install
git clone https://huggingface.co/Alibaba-NLP/gte-base-en-v1.5

# Set the models directory as the volume path
volume=$PWD

# Mount the models directory inside the container with a volume and set the model ID
docker run --gpus all -p 8080:80 -v $volume:/data --pull always ghcr.io/huggingface/text-embeddings-inference:1.6 --model-id /data/gte-base-en-v1.5
< > 在 GitHub 上 更新