跳到主要内容
Hugging Face 文本嵌入推理 (TEI) 是一个用于部署和提供开源文本嵌入和序列分类模型的工具包。TEI 能够为最流行的模型提供高性能的提取,包括 FlagEmbeddingEmberGTEE5
要在 LangChain 中使用它,首先安装 huggingface-hub
pip install -U huggingface-hub
然后使用 TEI 暴露一个嵌入模型。例如,使用 Docker,您可以如下提供 BAAI/bge-large-en-v1.5
model=BAAI/bge-large-en-v1.5
revision=refs/pr/5
volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run

docker run --gpus all -p 8080:80 -v $volume:/data --pull always ghcr.io/huggingface/text-embeddings-inference:0.6 --model-id $model --revision $revision
Docker 用法可能因底层硬件而异。例如,要在 Intel Gaudi/Gaudi2 硬件上提供模型,请参阅 tei-gaudi 仓库 以获取相关的 docker 运行命令。 最后,实例化客户端并嵌入您的文本。
from langchain_huggingface.embeddings import HuggingFaceEndpointEmbeddings
embeddings = HuggingFaceEndpointEmbeddings(model="https://:8080")
text = "What is deep learning?"
query_result = embeddings.embed_query(text)
query_result[:3]
[0.018113142, 0.00302585, -0.049911194]
doc_result = embeddings.embed_documents([text])
doc_result[0][:3]
[0.018113142, 0.00302585, -0.049911194]

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.