For RAG on your own servers, it’s best to offload embeddings and the reranker into a separate lightweight service: Text Embeddings Inference (TEI) from Hugging Face or Infinity. Both expose an OpenAI-compatible /v1/embeddings endpoint and /rerank, run in Docker, and can serve models with hundreds of millions of parameters on a single modest GPU or even on a CPU. If you already have vLLM or llama-server running, they can also provide embeddings, but a separate service is easier to scale for batch indexing.
Prepared by AI Studio by Vladimir Lomtev on November 16, 2026, for teams building document search and RAG without external APIs. We relied on Text Embeddings Inference README (latest release on GitHub: v1.9.4 from September 15, 2026) and Infinity README with server version v3. The commands were checked for syntax, but we did not run them on a specific GPU ourselves.
Contents
- Why You Need a Separate Service
- How Much Work the Reranker Does: A Calculation
- Text Embeddings Inference
- Infinity v3
- If You Already Have vLLM or llama-server
- Comparison of Options
- How to Connect It from Your Application
- Common Mistakes
- How to Check Quality and Speed
- Frequently Asked Questions
Why You Need a Separate Service
A RAG system uses three models: the embeddings model turns documents and queries into vectors, the reranker reorders the retrieved chunks, and the LLM writes the answer. How such a system works is covered in the article “RAG System for Business”.
Embeddings and rerankers have a different workload than an LLM:
- Indexing — one-time or overnight batches of thousands or millions of chunks. Throughput matters.
- Search — one short question per user request. Latency matters.
- Reranking — pairs of “question + chunk” for each candidate. For one query, that’s dozens of pairs.
If you keep everything on the LLM server, overnight indexing will compete with answer generation. A separate service can be scaled and updated independently, and embeddings models themselves are small: the TEI table of popular models includes sizes from 308 million to 7.57 billion parameters.
How Much Work the Reranker Does: A Calculation
A reranker is a cross-encoder: it reads the question and the chunk together and outputs a relevance score. A simple example: search returned 50 candidates at 300 tokens each, and the question is 30 tokens long. The reranker needs to process 50 × (300 + 30) = 16,500 tokens for a single query. That is slightly above the TEI default value --max-batch-tokens (16,384), which means one user query can take up almost the entire batch.
The practical takeaway: the number of candidates sent to reranking is the main lever for latency. If you cut the number of candidates from 50 to 20, you reduce the reranker’s workload by 2.5x. When you need a reranker and when you don’t is covered in the article “Reranker in RAG: When You Need One”.
Text Embeddings Inference
TEI is Hugging Face’s server for embeddings models, rerankers, and classifiers. On GPU, you need NVIDIA Container Toolkit and a driver compatible with CUDA 12.2 or newer. Images are built for different architectures:
| Hardware | Image |
|---|---|
| CPU x86_64 | ghcr.io/huggingface/text-embeddings-inference:cpu-1.9 |
| Ampere 8.6 (A10, A40) | ghcr.io/huggingface/text-embeddings-inference:86-1.9 |
| Ada Lovelace (RTX 4000) | ghcr.io/huggingface/text-embeddings-inference:89-1.9 |
| Hopper (H100) | ghcr.io/huggingface/text-embeddings-inference:hopper-1.9 |
| Universal CUDA | ghcr.io/huggingface/text-embeddings-inference:cuda-1.9 |
Launching the embeddings model:
docker run --gpus all -p 127.0.0.1:8080:80 -v /srv/tei-data:/data \
ghcr.io/huggingface/text-embeddings-inference:cuda-1.9 \
--model-id Qwen/Qwen3-Embedding-0.6B \
--api-key "$TEI_API_KEY" \
--max-batch-tokens 16384 \
--max-client-batch-size 64
The reranker is launched in a separate container on a different port:
docker run --gpus all -p 127.0.0.1:8081:80 -v /srv/tei-data:/data \
ghcr.io/huggingface/text-embeddings-inference:cuda-1.9 \
--model-id BAAI/bge-reranker-v2-m3 \
--api-key "$TEI_API_KEY"
Key parameters from the README:
--max-batch-tokens— total number of tokens in a batch, default 16,384; the README calls it one of the main hardware-utilization parameters and recommends setting it as high as possible until the model becomes compute-bound;--max-client-batch-size— how many inputs a client can send in one request, default 32;--auto-truncate— truncates inputs that are too long, enabled by default;--api-key— without it, the server responds to any request;--pooling— overrides the token-vector pooling method if the model configuration doesn’t suit it.
Endpoints: /embed and OpenAI-compatible /v1/embeddings for embeddings, /rerank for the reranker.
Infinity v3
Infinity — a server for embeddings, reranking, and classification. In October 2026, the server-side v3 release came out, written in Rust with LibTorch; the earlier Python version is available as v2. According to the README, v3 requires an NVIDIA GPU with Ampere architecture (SM80) or newer and the NVIDIA Container Toolkit:
docker run --rm --gpus all -p 127.0.0.1:8000:8000 -v infinity-cache:/data \
ghcr.io/michaelfeil/infinity_v3:nvidia-3.0.0 \
--model-id intfloat/multilingual-e5-large-instruct \
--torch-device cuda --dtype bfloat16 \
--hostname 0.0.0.0 --port 8000
README highlights: by default, all visible GPUs are used, and each one runs a full copy of the model; embeddings are served through /v1/embeddings, reranking through /rerank, and it also supports classification, SPLADE sparse vectors, and token vectors for late interaction; /health reports readiness after loading and warmup. The authors recommend pinning the image version or digest.
If you already have vLLM or llama-server
vLLM supports embedding models and rerankers as pooling models, while llama-server from llama.cpp serves /v1/embeddings , and /reranking for GGUF models. This is useful if you want one server type for everything. But for embeddings, you typically run a separate instance with its own model, so the simplicity gain is usually small.
Option comparison
| TEI | Infinity v3 | vLLM / llama-server | |
|---|---|---|---|
| Purpose | Embeddings, rerankers, classifiers | Embeddings, reranking, classification, SPLADE | Primarily generation |
| CPU | Yes, separate image | Not according to the v3 README (NVIDIA SM80+) | llama-server — yes |
OpenAI /v1/embeddings |
Yes | Yes | Yes |
| Reranking | /rerank |
/rerank |
Available |
| Batch tuning | --max-batch-tokens and more |
v3 settings | Engine settings |
How to connect from your app
import os
import requests
from openai import OpenAI
emb = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key=os.environ["TEI_API_KEY"])
vectors = emb.embeddings.create(
model="Qwen/Qwen3-Embedding-0.6B",
input=["Order approval workflow for a supply contract", "Return deadlines for goods"],
).data
rerank = requests.post(
"http://127.0.0.1:8081/rerank",
headers={"Authorization": "Bearer " + os.environ["TEI_API_KEY"]},
json={"query": "How many days do I have to return it?",
"texts": ["Returns are possible within 14 days.", "Delivery takes 3 days."]},
timeout=30,
)
print(len(vectors), rerank.json())
The values in the sample texts are hypothetical.
Common mistakes
- Using different models for indexing and search. Vectors from different models are not compatible. If you change the embedding model, reindex the entire database.
- Silent truncation. With
--auto-truncatea long segment is silently truncated, and its ending does not make it into the vector. Match chunk size to the model’s maximum length; for chunking, see the article “Document Chunking for RAG”. - Instructions and prefixes. Some models expect different prefixes or instructions for the query and the document. Check the model card.
- Too many candidates for the reranker. Latency increases in proportion to the number of pairs.
- Service without a key. By default, TEI responds to everyone; set
--api-keyand close the port.
How to check quality and speed
- Collect 50–200 real user questions with labeled correct passages.
- Measure search recall: for what share of questions the correct passage appears in the top 5, 10, and 20 results, with and without the reranker.
- Compare 2–3 embedding models; how to choose candidates is described in the embedding model selection checklist.
- Measure search latency with reranking at different candidate counts.
- Measure indexing speed on a document batch close to your real production volume.
Frequently asked questions
Do I need a GPU for embeddings? For small models and moderate volume, the TEI CPU image is enough. A GPU pays off for large indexing jobs and when strict latency requirements matter.
Can embeddings and the reranker run on the same GPU as the LLM? Yes, if you have enough memory, but overnight indexing will compete with user responses. Limit it by time or move it to a separate GPU.
Which model should I choose for Russian? Multilingual models from the TEI table, such as Qwen3-Embedding or multilingual-e5, are reasonable candidates, but the choice should be based on a recall test using your own documents.
How Vladimir Lomtev’s AI Studio Helps with Search for RAG
Vladimir Lomtev’s AI Studio builds RAG systems and enterprise knowledge bases on company servers. For the search layer, that means:
- select embedding and reranker models by testing them on your documents and questions;
- deploy TEI or Infinity with keys, monitoring, and pinned versions;
- configure indexing, document chunking, and the number of candidates for reranking;
- integrate search with the LLM and enterprise systems.
The first step is to choose one document base and 50 typical questions for it, then record what share of correct answers you consider sufficient. Discuss the project.
Bottom line: a lightweight standalone search service
Embedding and reranking are usually better moved out of the LLM server into a separate TEI or Infinity service: it is lightweight, scales with indexing, and does not interfere with generation. Pin the image version, set the key, limit the number of reranking candidates, and choose models based on search recall on your own documents.



