Offline CUDA embedding sidecar for the pattern MCP servers — Hugging Face TEI
(CUDA, candle backend) with Qwen/Qwen3-Embedding-0.6B
(safetensors, BF16 weights served as float32) baked into the image. No downloads, no API keys at runtime.
┌────────────────────────────────────────────────────────────┐
│ architecture-pattern-mcp / agent-pattern-mcp │
| design-pattern-mcp / blockchain-pattern-mcp |
│ ────── HTTP /v1/embeddings ──────► │
│ │
│ ┌────────────────────────────┐ │
│ │ pattern-tei-embed-gpu │ ◄── pattern-tei-infra │
│ │Qwen3-Emb-0.6B (safetensors)│ │
│ │ :8080 (TEI, CUDA sm≥61) │ │
│ └────────────────────────────┘ │
└────────────────────────────────────────────────────────────┘
This image is the embedder only. It contains no MCP server, no reranker,
and no LLM client. The MCP servers (architecture-pattern-mcp, design-pattern-mcp, agent-pattern-mcp, blockchain-pattern-mcp) reach it via
the shared Docker network pattern-tei-shared at the DNS name
pattern-tei-embed (see the pattern-tei-infra stack).
Runtime base is ghcr.io/huggingface/text-embeddings-inference:cuda-1.9
(CUDA 12.9 user-mode libraries, reused as-is), but the router binary is
not stock: it is self-built from TEI v1.9.4 plus unmerged upstream PR
#884
with the non-flash CUDA feature set candle-cuda-volta,static-linking,http
(see Startup and --warmup-tokens and
SM coverage below).
Pinned serving parameters (image ENV, surfaced so CMD stays exec-form):
POOLING=last-token, DTYPE=float32, USE_FLASH_ATTENTION=False
(no flash kernel compiled). CMD carries only
--model-id /data/embedding-model.
The stock arch dispatcher is bypassed: ENTRYPOINT is a minimal
entrypoint-cuda.sh that gates on nvidia-smi (refuses to start without
CUDA — no silent CPU path) and execs the rebuilt router. Weights live at
/data/embedding-model; never mount over /data (a named volume would hide
later image updates).
Why safetensors, not ONNX: candle cannot load ONNX. The retired ORT build
served the community ONNX export (onnx-community/Qwen3-Embedding-0.6B-ONNX);
this build serves the same model's safetensors release through candle. The
in-image path and the consumers' model string are unchanged, but the vectors
are not bit-identical to the ORT ones, so consumers regenerated their dense
cache once at migration. Both -gpu and -cpu lanes now serve this same
repo, so the cache is shared and switching lanes never forces a re-embed.
Qwen/Qwen3-Embedding-0.6B — 0.6B params, served at 8k (native 32k, capped at build time), Apache 2.0
(BF16 model.safetensors baked in at /data/embedding-model, served as float32, same repo as the -cpu lane)v1.9.4 + PR #884 on :8080 (candle/CUDA,
last-token pooling — Qwen3's training mode, TEI default cls would be
silently wrong — float32 serving dtype: the weights are BF16, and Pascal has no bf16 and a 1/64-rate fp16 path)POST /v1/embeddings (OpenAI-compat, what the MCP client uses) ·
POST /embed (raw) · GET /health · GET /infoHF_HUB_OFFLINE=1MAX_CONCURRENT_REQUESTS=32, MAX_BATCH_TOKENS=8192, MAX_CLIENT_BATCH_SIZE=32, AUTO_TRUNCATE=true, WARMUP_TOKENS=0, PROMETHEUS_PORT=0 (metrics not exposed)config.json is patched at build time: max_position_embeddings 32768 →
8192, capping the native 32k context to the served 8k (MAX_BATCH_TOKENS=8192).
Stock cuda-1.9 serves compute capability 75+ only. This build targets
CUDA_COMPUTE_CAP=61 (Pascal floor, nvcc --gpu-architecture=sm_61):
/entrypoint.sh
arch dispatcher (bypassed, see above) and TEI's own
backends/candle/src/compute_cap.rs match table (patched with a
(runtime, 61) if runtime >= 61 => true arm).cuobjdump (assembles for sm_89); sm_61
is the only hardware tested so far. First model load on a newer card pays
a one-time JIT compile.CUDA_COMPUTE_CAP at build time drops older cards — it never adds
newer ones. No GPU is needed at build time (nvcc cross-compiles).--warmup-tokensWhy this image carries a custom router build instead of stock cuda-1.9:
cuda-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 0.6B model: ~131 s —
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 + one-time PTX JIT 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 |
When rebasing to a newer TEI tag, bump TEI_SOURCE_VERSION and TEI_PR884_SHA
together — and drop the patch once the PR merges upstream.
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_* compose variables (compose overrides image ENV):
| Variable | Default | Notes |
|---|---|---|
WARMUP_TOKENS (TEI_WARMUP_TOKENS) | 0 | Skip (0) / shrink (N) the warmup pass. Custom-build flag, see above |
MAX_BATCH_TOKENS (TEI_MAX_BATCH_TOKENS) | 8192 | Upstream default is 16384; 8192 caps the native 32k context (patched config.json) to the served 8k |
MAX_CONCURRENT_REQUESTS (TEI_MAX_CONCURRENT_REQUESTS) | 32 | Upstream default 512; 32 is the tuned serving cap |
MAX_CLIENT_BATCH_SIZE (TEI_MAX_CLIENT_BATCH_SIZE) | 32 | Must be ≥ client's EMBEDDER_BATCH_SIZE, else TEI returns HTTP 429 no permits available (one semaphore permit per input, not per request) |
AUTO_TRUNCATE (TEI_AUTO_TRUNCATE) | true | Keep on: client requirement strings can reach ~100 000 chars |
USE_FLASH_ATTENTION | False | Pinned: this build has no flash kernel (stock CUDA base defaults it to True) |
PORT (TEI_PORT) | 8080 | If changed, update EMBEDDER_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_PROMETHEUS_PORT) | 0 | Disabled; /metrics never exposed |
HOSTNAME (TEI_HOSTNAME) | 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 |
Keep the invariant EMBEDDER_BATCH_SIZE (client, 8 on this lane)
≤ MAX_CLIENT_BATCH_SIZE ≤ MAX_CONCURRENT_REQUESTS.
Note for CPU-lane switchers: candle-on-CPU caps this model's
max_batch_requests at 4, so consumers size their client batch to 4 against
the -cpu lane (larger batches still work but split into sequential
sub-batches inside one HTTP request). The GPU default of 8 stands here.
docker compose version)nvidia-smi -L; the stack reserves nvidia.com/gpu=all). sm_60 and below
unsupported. The container refuses to start without CUDA (nvidia-smi gate)cuda-compat LD_LIBRARY_PATH
fallback branch, so an older host driver has no fallback pathPart of the pattern-tei-infra stack
(recommended — shared Docker network pattern-tei-shared, DNS name pattern-tei-embed):
git clone https://github.com/olk/pattern-tei-infra.git && cd pattern-tei-infra
# Registry deploy: pin BOTH images in .env so up/pull reuse them
# (defaults are local build names, not pullable refs).
# systemd ignores the repo .env — install the same two lines 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=olkowa/pattern-tei-embed-gpu:1.2.0' \
'TEI_RERANK_IMAGE=olkowa/pattern-tei-rerank-gpu:1.2.0' > .env
docker compose up -d
# ... or build locally first: make docker-build-tei && docker compose up -d
Or standalone (no MCP consumer — needs GPU access):
docker run -d --name pattern-tei-embed --gpus all -p 8080:8080 \
olkowa/pattern-tei-embed-gpu:1.2.0
curl -fsS http://localhost:8080/health
Restore the full warmup for comparison:
docker run -d --name pattern-tei-embed --gpus all -p 8080:8080 \
-e WARMUP_TOKENS=8192 olkowa/pattern-tei-embed-gpu:1.2.0
Mirrored on GHCR at
ghcr.io/olk/pattern-tei-embed-gpu. The lane is part of the image name, never the tag (:1.2.0/:latestexist per lane). CPU counterpart:olkowa/pattern-tei-embed-cpu(same model repo, shared dense cache).
Nothing to configure — no env vars, no model download, no HF token.
Cold start is seconds (WARMUP_TOKENS=0); expect ~2 min only if you
explicitly set a large WARMUP_TOKENS. First start on a >sm_61 card adds a
one-time PTX JIT compile.
# Update (registry deploy — requires TEI_IMAGE + TEI_RERANK_IMAGE 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 pull
# Logs
docker compose -f pattern-tei-infra/docker-compose.yml logs -f pattern-tei-embed
# Health
docker inspect --format '{{.State.Health.Status}}' pattern-tei-embed
# Pin a version (both images — the stack always runs the pair)
TEI_IMAGE=olkowa/pattern-tei-embed-gpu:1.2.0 \
TEI_RERANK_IMAGE=olkowa/pattern-tei-rerank-gpu:1.2.0 \
docker compose -f pattern-tei-infra/docker-compose.yml up -d
Healthcheck: GET /health, 120 s start_period. No /data mounts — weights
are baked in; drop stale named volumes from older deploys
(docker volume rm pattern-tei-infra_tei-embed-data).
docker pull olkowa/pattern-tei-embed-gpu:latest