Skip to content

feat(k8s): serve a cross-encoder rerank route on TEI #4970

Open

Description

@dan-petty

Update 2026-11-26 (infra move): the TEI manifests and the gateway entry go to dan-petty/homelab.

This issue keeps the ADR in docs/adr/ and the rerank call in the gateway smoke check of k8s/README.md (#4885). deploy-stack lists the llm files in MANIFESTS_BY_STACK, so a new manifest file also needs a line there. The environment checks of devops ci for these files are gone.

Follow-up: dan-petty/homelab#283.


Problem or Motivation

The LiteLLM gateway has no rerank route, and no manifest names a reranker. Ollama has no rerank endpoint (ollama#3368, open since 2024-03).

On the 62-query project eval set of #4961, the cross-encoder BAAI/bge-reranker-v2-m3 lifts nDCG@10 from 0.386 (current path) to 0.514 over the current pool (B1, p 0.002) and to 0.567 over the hybrid pool (B2, p < 0.001). Over the hybrid pool alone, its gain is +0.105 on the 42 natural-language queries (p 0.017) and +0.224 on census questions (p 0.002), but only +0.053 over all queries (p 0.10). The trial #4968 confirms this with the scores that TEI serves before this route is built.

A cross-encoder of this size needs a GPU. One rerank of 50 candidates of about 190 tokens is about 5.8 TFLOP (303M non-embedding parameters x 2 x 9,500 tokens). On a workstation CPU, it took 1,730 to 1,890 CPU-seconds. On TEI 1.9.4 on an RTX 3090, it took p50 220 ms and p95 245 ms, with 1.4 GiB VRAM at idle and 1.9 GiB at peak.

TEI does not support the Pascal embed GPUs (cc 6.1) or the Volta GPUs (cc 7.0), so it shares an Ampere GPU with the 48 GiB chat tier.

Proposed Solution & Architectural Design

Add a TEI 1.9.4 Deployment in namespace llm, managed by Argo CD from k8s/llm:

  • image ghcr.io/huggingface/text-embeddings-inference:86-1.9.4, pinned by digest;
  • BAAI/bge-reranker-v2-m3 at revision 953dc6f6, float16, --max-batch-tokens 16384, and the truncation length that test(k8s): trial TEI quality and load on a cluster GPU #4968 sets;
  • one replica on <ampere-node>, on the GPU with the larger 7-day headroom, with the GPU selection that the 48 GiB tier uses;
  • the restricted Pod Security level and uid 1000 (the trial showed that this works), a PVC for the model cache (warm start 2 to 3 s, cold start 77 to 112 s), HF_HUB_DISABLE_TELEMETRY=1;
  • a NetworkPolicy that admits only the gateway and Prometheus, and a PodMonitor for the te_* metrics;
  • an alert on the GPU memory of the shared GPU.

Add a LiteLLM model_list entry: model_name: bge-reranker-v2-m3, model: huggingface/BAAI/bge-reranker-v2-m3, api_base the TEI Service, model_info.mode: rerank. LiteLLM posts {query, texts, raw_scores} to <api_base>/rerank. Clients call POST /v1/rerank with the Cohere shape {model, query, documents, top_n} and read results[].index and results[].relevance_score.

Add one rerank call to the gateway smoke calls (#4885).

Record the choice in an ADR: TEI, and why not Infinity (v3 license fails; v2 cannot load Qwen3 and counts characters as tokens), Ollama (no rerank endpoint) or llama.cpp llama-server (the latency that #4968 measured on a P6000).

Stop rule: if the stop test of #4968 fails (the reranked arm does not beat the fused arm on the natural-language queries with p < 0.05), do not build this route. Return this issue to New with the evidence.

Target Subsystem

docs/adr/ and the gateway smoke check in devops-cli. The TEI manifests, the gateway entry and the alerts are in dan-petty/homelab.

Existing Tool Considered

Hugging Face Text Embeddings Inference 1.9.4 (Apache-2.0), with the reranker model BAAI/bge-reranker-v2-m3 (Apache-2.0). LiteLLM's huggingface/ rerank provider. Argo CD, DCGM and Prometheus. No code is added to the CLI. Estimated cost: about 0.25M tokens and 4 hours.

Acceptance criteria

  • Argo CD shows the TEI application Synced and Healthy. The image is pinned by digest and the model by revision.
  • POST <gateway>/v1/rerank with model bge-reranker-v2-m3 and 50 documents returns 50 results with relevance_score.
  • Over 100 gateway calls with 50 candidates of at most 2,400 characters, p95 <= 500 ms.
  • The TEI pod VRAM peak is at most 2.5 GiB, and the 48 GiB chat tier has 0 OOM restarts in the 7 days after rollout (DCGM, kubectl).
  • Prometheus has te_request_count for the pod.
  • The gateway smoke calls include one rerank call.
  • The ADR is merged.

Dependencies

#4968 (the GPU trial and its stop test).

Source: #4961

Alternatives check of 2026-11-27: in-use.
The item already names this tool.
Tool: huggingface/text-embeddings-inference (https://github.com/huggingface/text-embeddings-inference), Apache-2.0, last activity 2026-11-25, maintained.
Reason: Web searches were unhelpful, but the tool facts confirm TEI is an open, maintained server that already serves cross-encoder rerank scores and te_* metrics; the issue itself names it as the tool in use, so only the ADR and smoke call remain.

Covers:

  • Serves cross-encoder rerank scores over HTTP for a reranker model
  • Loads BAAI/bge-reranker-v2-m3, pinned by revision and dtype
  • Exposes te_* Prometheus metrics for request and batch counts
  • Ships a CUDA image that a Deployment can pin by digest

Lacks:

  • No gateway route; needs the LiteLLM model_list rerank entry
  • No Cohere /v1/rerank shape; serves /rerank with raw_scores
  • No GPU node placement, model-cache PVC, NetworkPolicy or PodMonitor
  • No support for Pascal or Volta GPUs, so an Ampere GPU is shared

Proposed design

Problem statement

The LiteLLM gateway has no rerank route, and retrieval cannot use a cross-encoder. The infra move puts the TEI manifests and the gateway entry in dan-petty/homelab#283. This issue keeps the ADR in docs/adr/ and the rerank call in the gateway smoke check of k8s/README.md.

Acceptance criteria

Requirement: ADR records reranker choice

The change SHALL add an accepted MADR record that chooses TEI and rejects Infinity, Ollama and llama.cpp.

Scenario: ADR record check

  • WHEN uv run devops docs generate and uv run devops ci test tests/invariants/test_adr_records.py run on the change branch.
  • THEN The index of docs/adr/README.md holds the new row. The test exits 0 for the new record with status: accepted and issue: 4970.

Requirement: Gateway smoke rerank call

The gateway smoke calls in k8s/README.md SHALL include one POST /rerank call with 50 documents and SHALL list six calls in total.

Scenario: Documented smoke calls

  • WHEN uv run devops ci --check --only docs runs on the change branch, and rg -n "POST /rerank" k8s/README.md reads the smoke section.
  • THEN The command exits 0. The smoke section lists six calls, and one call is POST /rerank with model bge-reranker-v2-m3 and 50 documents.

Requirement: Pending a person after the merge

The pull request SHALL merge only after its required checks pass and a person approves it.

Scenario: Person merge

  • WHEN The pull request is ready and its required checks pass.
  • THEN A person merges it, and the ADR and smoke call are on the default branch.

Existing Tool Considered

Hugging Face Text Embeddings Inference (TEI) 1.9.4, Apache-2.0, maintained. The alternatives check of 2026-11-21 in the issue body records verdict in-use and lists what TEI covers and lacks. This change adds the ADR and the gateway smoke rerank call. The TEI manifests and the LiteLLM entry are in dan-petty/homelab#283. The estimated cost is about 0.25M tokens and 4 hours.

Key questions

  • Which reranker server and model does the ADR record?: Use Hugging Face Text Embeddings Inference 1.9.4 with BAAI/bge-reranker-v2-m3 at revision 953dc6f6. The alternatives check of 2026-11-21 in the issue body records TEI as in-use and lists what it covers and lacks. This change adds the ADR and the smoke call; the manifests and gateway entry are in dan-petty/homelab#283. (best practice) [sources: docs/adr/README.md, k8s/README.md:186]
    • Chosen: Text Embeddings Inference 1.9.4. Open, Apache-2.0 and maintained; serves cross-encoder rerank scores and Prometheus metrics; the alternatives check records it in-use.
    • Rejected: Infinity. Its v3 license fails, and v2 cannot load Qwen3 or count tokens correctly.
    • Rejected: Ollama. It has no rerank endpoint (ollama#3368).
    • Rejected: llama.cpp llama-server. The trial measured too much latency on a P6000.
  • Where do the TEI manifests and the LiteLLM gateway entry live after the infra move?: They go to dan-petty/homelab#283. This issue keeps only the ADR in docs/adr/ and the rerank call in the gateway smoke check of k8s/README.md. [sources: k8s/README.md:1, CONTEXT.md]
  • Where do the gateway smoke calls live, and what does the change add?: They live in the "Smoke check after a gateway upgrade" section of k8s/README.md, which lists five calls. The change adds one POST /rerank call with model bge-reranker-v2-m3 and 50 documents, and changes the count to six. [sources: k8s/README.md:186, k8s/README.md:188, k8s/README.md:210]
  • Which command proves the ADR record?: uv run devops docs generate writes the index row in docs/adr/README.md, and uv run devops ci test tests/invariants/test_adr_records.py checks the record. The ADR is accepted and names issue 4970. [sources: docs/adr/README.md, tests/invariants/test_adr_records.py]
  • What does the issue body say about the MANIFESTS_BY_STACK line for the new TEI manifest?: The issue body says that a new llm manifest file also needs a line in MANIFESTS_BY_STACK. The TEI manifest file is in dan-petty/homelab#283. This issue keeps the ADR and the smoke call. [sources: src/devops_cli/commands/k8s/stack_lifecycle.py, k8s/README.md:1]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4968

Activity

  1. added
    source/agent
    on Nov 12, 2026
  2. added
    type/feature
    scope/k8s
    status/new
    value/high
    effort/medium
    on Nov 12, 2026
  3. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 12, 2026
  5. added
    priority/p2-medium
    and removed
    priority/p2-medium
    on Nov 12, 2026
  6. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: Searches found no tool that covers the rerank need better than the one the issue already names: Hugging Face Text Embeddings Inference, an open (Apache-2.0), maintained server whose rerank endpoint serves cross-encoder scores such as BAAI/bge-reranker-v2-m3, at exactly the 1.9.4 release the issue pins. What remains is project glue (Kubernetes manifests, LiteLLM model_list entry, alert, smoke call, ADR), not a missing tool, so the issue is already built on the right existing tool.

    The item already names this tool.

    Tool: huggingface/text-embeddings-inference (https://github.com/huggingface/text-embeddings-inference)

    • License: Apache-2.0
    • Last activity: 2026-11-15
    • Maintained: yes

    Covers:

    • Serves cross-encoder rerank scores over HTTP (/rerank) for reranker models such as BAAI/bge-reranker-v2-m3, which the trial test(k8s): trial TEI quality and load on a cluster GPU #4968 already ran against TEI
    • Open source under Apache-2.0, not archived, with a recent release v1.9.4, the version the issue pins by digest
    • Runs as a GPU container image that fits the single-replica Deployment, PVC model cache and restricted Pod Security level the issue describes
    • Exposes Prometheus te_* metrics, so the PodMonitor and alert in the issue can read them

    Lacks:

    • The project-side work itself: Argo CD-managed Deployment, Service, PVC, NetworkPolicy and PodMonitor in k8s/llm
    • The LiteLLM model_list entry and /v1/rerank gateway route with the Cohere request/response shape
    • The GPU-memory alert, the added gateway smoke call and the ADR recording the choice over Infinity, Ollama and llama.cpp
    • The stop test and GPU-sharing decision from test(k8s): trial TEI quality and load on a cluster GPU #4968, which TEI does not answer
    • TEI has no rerank support on Pascal (cc 6.1) or Volta (cc 7.0), so the GPU placement stays a project decision

    Tools considered:

    Searches run:

    • Text Embeddings Inference rerank endpoint cross-encoder, results: 5
    • LiteLLM rerank huggingface provider /v1/rerank, results: 5
    • huggingface text-embeddings-inference /rerank API docs, results: 5
    • text-embeddings-inference reranker bge-reranker-v2-m3 sequence classification, results: 5
    • "text-embeddings-inference" rerank, results: 5

    Sources:

    Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.

  7. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Owner question: Who accepts and merges the ADR? (a person decides)

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  8. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Owner question: See the first point of Open questions in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  9. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor

    Answer (a documented fact, not a decision for a person): docs/adr/README.md, section Approval, lines 36-40, gives the steps.

    1. An agent writes the record with status: proposed and decision-makers: [owner] in a draft pull request.
    2. When the checks pass, the agent sets status: accepted and body-hash, and marks the pull request ready.
    3. The owner merges the pull request. The merge accepts the record. If the owner refuses the record, the pull request closes with no merge.

    The record goes in the pull request of this item, with the TEI manifests. This question does not hold the item from Ready. The item still waits on #4968 and its stop test.

  10. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/k8ssource/agentstatus/newtype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions