Skip to main content
Hugging Face Text Embeddings Inference (TEI) is a toolkit for deploying and serving open-source text embeddings and sequence classification models. TEI enables high-performance extraction for the most popular models, including FlagEmbedding, Ember, GTE and E5.
TEI serves an OpenAI-compatible /v1/embeddings endpoint, so you can consume a TEI deployment from LangChain with OpenAIEmbeddings from the langchain-openai package.
Earlier versions of this guide used HuggingFaceEndpointEmbeddings(model="http://localhost:8080"). langchain-huggingface no longer accepts a URL for model and raises `model` must be a HuggingFace repo ID, not a URL.. Point OpenAIEmbeddings at the TEI server instead, as shown below.

Setup

Install langchain-openai:

Deploy a model with TEI

Expose an embedding model using TEI. For instance, using Docker, you can serve sentence-transformers/all-MiniLM-L6-v2 as follows:
To serve on CPU-only hardware, use the cpu-1.9 image and drop the --gpus all flag. Docker usage varies with the underlying hardware. For example, to serve the model on Intel Gaudi/Gaudi2 hardware, refer to the tei-gaudi repository for the relevant docker run command.

Embed text

Instantiate OpenAIEmbeddings against the TEI server:
Set check_embedding_ctx_length=False. Without it, OpenAIEmbeddings tokenizes input with tiktoken and sends token IDs, which TEI does not accept. The flag sends raw text instead. If you start TEI with an API key, pass the same value as api_key.
Then embed your texts: