HUB
Sign inSign up

olkowa/pattern-tei-embed-cpu

By olkowa

•Updated 6 days ago

Image
0

60

olkowa/pattern-tei-embed-cpu repository overview

⁠pattern-tei-embed-cpu

Offline CPU embedding sidecar for the pattern MCP servers — Hugging Face TEI (CPU, candle backend) with Qwen/Qwen3-Embedding-0.6B⁠ (BF16 safetensors, served as float32) baked into the image. No downloads, no API keys at runtime. Same model repo as the -gpu lane — the dense cache is shared, so switching lanes never forces a re-embed.

┌────────────────────────────────────────────────────────────┐
│  architecture-pattern-mcp / agent-pattern-mcp              │
|  design-pattern-mcp / blockchain-pattern-mcp               |
│        ────── HTTP /v1/embeddings ──────►                  │
│                                                            │
│      ┌────────────────────────────┐                        │
│      │   pattern-tei-embed-cpu    │ ◄── pattern-tei-infra  │
│      │Qwen3-Emb-0.6B (safetensors)│                        │
│      │     :8080 (TEI, CPU)       │                        │
│      └────────────────────────────┘                        │
└────────────────────────────────────────────────────────────┘

⁠Architecture

This image is the embedder only. It contains no MCP server, no reranker, 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-embed (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 serving parameters (image ENV, surfaced so CMD stays exec-form): POOLING=last-token, DTYPE=float32. CMD carries only --model-id /data/embedding-model.

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/embedding-model; never mount over /data (a named volume would hide later image updates).

The trade-off for sharing the GPU lane's model repo: candle-on-CPU caps max_batch_requests at 4 for this model (the retired ORT/ONNX build doubled that to 8), so consumers size their client batch to 4 against this lane — larger batches still work but split into sequential sub-batches inside one HTTP request, which risks the client timeout on long ones.

⁠What you get

  • Model: 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 -gpu lane)
  • Serving: TEI router v1.9.4 + PR #884 on :8080 (candle/CPU, last-token pooling — Qwen3's training mode, TEI default cls would be silently wrong — float32)
  • Endpoints: POST /v1/embeddings (OpenAI-compat, what the MCP client uses) · POST /embed (raw) · GET /health · GET /info
  • Fully offline: weights baked in at build time, runs with HF_HUB_OFFLINE=1
  • Tuned defaults: MAX_CONCURRENT_REQUESTS=32, MAX_BATCH_TOKENS=8192, MAX_CLIENT_BATCH_SIZE=32, AUTO_TRUNCATE=true, WARMUP_TOKENS=0, PROMETHEUS_PORT=0 (metrics not exposed)
  • Image: linux/amd64, CPU-only (no CUDA base) · Runs: on amd64 Linux hosts; no GPU required

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).

⁠CPU lane

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_* default below is identical on both lanes.

⁠Startup and --warmup-tokens

Why this image carries a custom router build instead of stock cpu-1.9:

  • Stock TEI 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 0.6B model on a 32-core host: ~131 s of ~142 s total startup — warmup is the boot time.
  • The only workaround on stock TEI is lowering MAX_BATCH_TOKENS (upstream issue #819⁠), which caps throughput to buy back startup time.
  • Upstream PR #884⁠ (open/unmerged) adds --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):

ValueBehaviour
0 (default)Skip the synthetic warmup pass
N > 0Warm with N tokens instead of the full default
N > MAX_BATCH_TOKENSRejected 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.

⁠Configuration

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):

VariableDefaultNotes
WARMUP_TOKENS (TEI_WARMUP_TOKENS)0Skip (0) / shrink (N) the warmup pass. Custom-build flag, see above
MAX_BATCH_TOKENS (TEI_MAX_BATCH_TOKENS)8192Upstream default is 16384; 8192 caps the native 32k context (patched config.json) to the served 8k
MAX_CONCURRENT_REQUESTS (TEI_MAX_CONCURRENT_REQUESTS)32Upstream default 512; 32 is the tuned serving cap
MAX_CLIENT_BATCH_SIZE (TEI_MAX_CLIENT_BATCH_SIZE)32Must 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)trueKeep on: client requirement strings can reach ~100 000 chars
PORT (TEI_PORT)8080If 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)0Disabled; /metrics never exposed
HOSTNAME (TEI_HOSTNAME)0.0.0.0Informational: 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, 4 on this lane — candle-on-CPU caps max_batch_requests at 4; the GPU default is 8) ≤ MAX_CLIENT_BATCH_SIZE ≤ MAX_CONCURRENT_REQUESTS.

⁠Prerequisites

  • Docker 24+ with compose plugin v2.24+ (docker compose version; v2.24+ for the !reset merge tag in the CPU overlay)
  • Disk: several GB free (weights + CPU base, no CUDA payload)
  • CPU-only: no GPU required; amd64 Linux host (images are single-arch — no arm64 manifest, emulation aside)

⁠Quick start

Part of the pattern-tei-infra⁠ stack (recommended — shared Docker network pattern-tei-shared, DNS name pattern-tei-embed). 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-embed -p 8080:8080 \
  olkowa/pattern-tei-embed-cpu:1.2.0
curl -fsS http://localhost:8080/health

Restore the full warmup for comparison:

docker run -d --name pattern-tei-embed -p 8080:8080 \
  -e WARMUP_TOKENS=8192 olkowa/pattern-tei-embed-cpu:1.2.0

Mirrored on GHCR at ghcr.io/olk/pattern-tei-embed-cpu. The lane is part of the image name, never the tag (:1.2.0 / :latest exist per lane). GPU counterpart: olkowa/pattern-tei-embed-gpu (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. Remember the client batch of 4 on this lane (see Configuration⁠).

⁠Operations

# 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-embed

# Health
docker inspect --format '{{.State.Health.Status}}' pattern-tei-embed

# 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, 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).

Tag summary
Recent tags
Content type
Image
Digest
sha256:241063d76…
Size
1.3 GB
Last updated
6 days ago
docker pull olkowa/pattern-tei-embed-cpu:latest