Hugging Face Text Embeddings Inference (TEI) is a toolkit for deploying and serving open-source text embeddings and sequence classification models.TEI serves an OpenAI-compatibleTEIenables high-performance extraction for the most popular models, includingFlagEmbedding,Ember,GTEandE5.
/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
Installlangchain-openai:
Deploy a model with TEI
Expose an embedding model using TEI. For instance, using Docker, you can servesentence-transformers/all-MiniLM-L6-v2 as follows:
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
InstantiateOpenAIEmbeddings 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.Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

