Offline CPU reranker sidecar for the pattern MCP servers — Hugging Face TEI
(CPU, candle backend) with Alibaba-NLP/gte-reranker-modernbert-base
(149M params, 8k context, English) baked into the image as safetensors.
No downloads, no API keys at runtime. Same model repo as the -gpu lane.
┌────────────────────────────────────────────────────────────────┐
│ architecture-pattern-mcp / agent-pattern-mcp │
| design-pattern-mcp / blockchain-pattern-mcp |
│ ───────── HTTP /rerank ─────────► │
│ │
│ ┌───────────────────────────────┐ │
│ │ pattern-tei-rerank-cpu │ ◄── pattern-tei-infra │
│ │ gte-reranker-modernbert-base │ │
│ │ :8080 (TEI, CPU) │ │
│ └───────────────────────────────┘ │
└────────────────────────────────────────────────────────────────┘
This image is the reranker only. It contains no MCP server, no embedder,
and no LLM client. The MCP servers (olk/architecture-pattern-mcp, olk/design-pattern-mcp, olk/agent-pattern-mcp, olk/blockchain-pattern-mcp) reach it via
the shared Docker network pattern-tei-shared at the DNS name
pattern-tei-rerank (see the pattern-tei-infra stack).
Runtime base is ghcr.io/huggingface/text-embeddings-inference:cpu-1.9,
but the router binary is not stock: it is self-built from TEI v1.9.4
plus unmerged upstream PR #884
with the CPU candle feature set candle,http
(see Startup and --warmup-tokens below).
Pinned invariants: --model-id /data/reranker-model --dtype float32
(candle backend; sequence-classification models take no --pooling flag).
No GPU machinery anywhere in this build: no nvcc, no CUDA_COMPUTE_CAP,
no compute-cap match patch (that check is compiled in only with the cuda
feature), no entrypoint bypass (the cpu base has no per-arch dispatcher —
it execs the router directly), and no USE_FLASH_ATTENTION (no flash kernel
is compiled and the CPU load path never consults it). Weights live at
/data/reranker-model; never mount over /data (a named volume would hide
later image updates).
Alibaba-NLP/gte-reranker-modernbert-base — English, 149M params, 8k context, Apache 2.0 (fp32 model.safetensors baked in, same repo as the -gpu lane)v1.9.4 + PR #884 on :8080 (candle/CPU, float32)POST /rerank (raw TEI) · GET /health · GET /infoHF_HUB_OFFLINE=1MAX_CONCURRENT_REQUESTS=64, MAX_BATCH_TOKENS=16384, MAX_CLIENT_BATCH_SIZE=48, AUTO_TRUNCATE=true, WARMUP_TOKENS=0, PROMETHEUS_PORT=0 (metrics not exposed)MAX_BATCH_TOKENS=8192 (shared with the GPU lane — the overlay swaps images, not tunables; see Configuration)No config.json patching is needed: max_position_embeddings=8192 is at or
below every MAX_BATCH_TOKENS this image runs with, so TEI accepts the model
config without the warmup warning that affects larger-context models.
The stack's CPU lane (docker-compose.cpu.yml overlay) swaps in the -cpu
pair and drops the base file's CDI GPU reservation via deploy: !reset {}
(Compose !reset tag — needs Compose v2.24+; without it the stack would not
start on a GPU-less host). The overlay changes images, not tunables: every
TEI_RERANK_* default below is identical on both lanes.
--warmup-tokensWhy this image carries a custom router build instead of stock cpu-1.9:
cpu-1.9 has no --warmup-tokens / WARMUP_TOKENS flag. It
always runs a synthetic warmup pass of min(max_input_length, max_batch_tokens)
tokens before serving. Measured cost for this 149M model: ~78 s of an ~81 s
cold start — warmup is the boot time.MAX_BATCH_TOKENS (upstream
issue #819),
which caps throughput to buy back startup time.--warmup-tokens / WARMUP_TOKENS.
This image builds the router from TEI v1.9.4 + PR #884 (pinned SHA 5806bdc)
and sets WARMUP_TOKENS=0 (skip the synthetic pass) by default, so the
container is ready in seconds (weight load only).Semantics of WARMUP_TOKENS (this image only — stock TEI ignores the variable):
| Value | Behaviour |
|---|---|
0 (default) | Skip the synthetic warmup pass |
N > 0 | Warm with N tokens instead of the full default |
N > MAX_BATCH_TOKENS | Rejected at startup |
All tunables are environment variables (clap fallbacks; CLI flags win).
Image defaults are overridable per container, e.g.
docker run -e WARMUP_TOKENS=512 …, or in the stack via the
TEI_RERANK_* compose variables (compose overrides image ENV):
| Variable | Image default | Stack default | Notes |
|---|---|---|---|
WARMUP_TOKENS (TEI_RERANK_WARMUP_TOKENS) | 0 | 0 | Skip (0) / shrink (N) the warmup pass. Custom-build flag, see above |
MAX_CONCURRENT_REQUESTS (TEI_RERANK_MAX_CONCURRENT_REQUESTS) | 64 | 64 | Must be ≥ texts per rerank request. TEI consumes one queue slot per text |
MAX_CLIENT_BATCH_SIZE (TEI_RERANK_MAX_CLIENT_BATCH_SIZE) | 48 | 48 | Must be ≥ the MCP client's RERANKER_MAX_BATCH_SIZE (default 48). Binding invariant: max_batch_size ≤ min(MAX_CLIENT_BATCH_SIZE, MAX_CONCURRENT_REQUESTS) |
MAX_BATCH_TOKENS (TEI_RERANK_MAX_BATCH_TOKENS) | 16384 | 8192 | Shared with the GPU lane (the overlay swaps images, not tunables). The 8192 exists as the GPU lane's CUDA OOM guard: the no-flash f32 cross-encoder needs ~3.2 GB transient attention per 8k-token pair; a 16384-token batch of two long pairs overflows an 11 GB card shared with the embedder (CUDA_ERROR_OUT_OF_MEMORY → consumer ERR_008) |
AUTO_TRUNCATE (TEI_RERANK_AUTO_TRUNCATE) | true | true | Keep on: requirement strings can exceed model input length |
PORT (TEI_RERANK_PORT) | 8080 | 8080 | If changed, update RERANKER_BASE_URL on the MCP side and the stack healthcheck URL (hardcoded to http://127.0.0.1:8080/health in docker-compose.yml) |
PROMETHEUS_PORT (TEI_RERANK_PROMETHEUS_PORT) | 0 | 0 | Disabled; /metrics never exposed |
HOSTNAME (TEI_RERANK_HOSTNAME) | 0.0.0.0 | 0.0.0.0 | Informational: Docker injects its own HOSTNAME at runtime, which TEI rejects as non-IP and falls back to 0.0.0.0 |
The MCP consumer chunks its fused candidate pool into requests of
RERANKER_MAX_BATCH_SIZE (default 48, config.json → RERANKER_MAX_BATCH_SIZE)
against http://pattern-tei-rerank:8080, with keep_retrieval_score preserving
the stage-1 fusion score alongside the cross-encoder logit.
docker compose version;
v2.24+ for the !reset merge tag in the CPU overlay)Part of the pattern-tei-infra stack
(recommended — shared Docker network pattern-tei-shared, DNS name pattern-tei-rerank).
The CPU lane adds the overlay file (-f docker-compose.cpu.yml, or make docker-up-cpu):
git clone https://github.com/olk/pattern-tei-infra.git && cd pattern-tei-infra
# Registry deploy: pin BOTH CPU images in .env so up/pull reuse them
# (defaults are local build names, not pullable refs).
# systemd ignores the repo .env — install the same lines plus
# COMPOSE_FILE=docker-compose.yml:docker-compose.cpu.yml in
# /etc/pattern-tei-infra/.env (the unit's WorkingDirectory), or a
# post-reboot start falls back to the unpullable local names.
printf '%s\n' \
'TEI_IMAGE_CPU=olkowa/pattern-tei-embed-cpu:1.2.0' \
'TEI_RERANK_IMAGE_CPU=olkowa/pattern-tei-rerank-cpu:1.2.0' > .env
docker compose -f docker-compose.yml -f docker-compose.cpu.yml up -d
# ... or build locally first: make docker-build-tei-cpu && <same up command>
Or standalone (no MCP consumer):
docker run -d --name pattern-tei-rerank -p 8080:8080 \
olkowa/pattern-tei-rerank-cpu:1.2.0
curl -fsS http://localhost:8080/health
Mirrored on GHCR at
ghcr.io/olk/pattern-tei-rerank-cpu. The lane is part of the image name, never the tag (:1.2.0/:latestexist per lane). GPU counterpart:olkowa/pattern-tei-rerank-gpu(same model repo).
Nothing to configure — no env vars, no model download, no HF token.
Cold start is seconds (WARMUP_TOKENS=0); expect ~80 s only if you
explicitly set a large WARMUP_TOKENS.
# Update (registry deploy — requires TEI_IMAGE_CPU + TEI_RERANK_IMAGE_CPU in .env,
# or in /etc/pattern-tei-infra/.env under systemd; otherwise compose tries
# to pull the local build names)
docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml pull
# Logs
docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml logs -f pattern-tei-rerank
# Health
docker inspect --format '{{.State.Health.Status}}' pattern-tei-rerank
# Re-enable a warmup pass (e.g. to smooth first-request latency)
TEI_RERANK_WARMUP_TOKENS=512 docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml up -d pattern-tei-rerank
# Restore the image batch default (the stack's 8192 is the GPU lane's CUDA OOM
# guard; the CPU overlay swaps images, not tunables)
TEI_RERANK_MAX_BATCH_TOKENS=16384 docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml up -d pattern-tei-rerank
# Pin a version (both images — the stack always runs the pair)
TEI_IMAGE_CPU=olkowa/pattern-tei-embed-cpu:1.2.0 \
TEI_RERANK_IMAGE_CPU=olkowa/pattern-tei-rerank-cpu:1.2.0 \
docker compose -f pattern-tei-infra/docker-compose.yml -f pattern-tei-infra/docker-compose.cpu.yml up -d
Healthcheck: GET /health, 60 s start_period. No /data mounts — weights
are baked in; drop stale named volumes from older deploys
(docker volume rm pattern-tei-infra_tei-rerank-data).
docker pull olkowa/pattern-tei-rerank-cpu:latest