# Text Embeddings Inference serve

> **About this page**
>
> - Task definition version: `swaleio/tei-serve@1.10.0`
> - Summary: Serves an embedding or reranker model over HTTP with Text Embeddings Inference, as a runner task.
> - Published: 2026-12-01, the latest version
> - Page: https://hub.swale.io/swaleio/tei-serve/v/1.10.0
> - Latest version's copy: https://hub.swale.io/swaleio/tei-serve.md
> - Versions: https://hub.swale.io/swaleio/tei-serve/versions
> - Index of Swale Hub: https://hub.swale.io/llms.txt
>
> The YAML block below is the task definition's frontmatter, which declares its inputs, outputs and container, and its readme follows. Both are the text of the account that published this task definition, not Swale's.

```yaml
name: Text Embeddings Inference serve
description: Serves an embedding or reranker model over HTTP with Text Embeddings Inference, as a runner task.
category: machine-learning
inputs:
  model:
    description: Model to serve — a Hugging Face Hub repo id (e.g. BAAI/bge-small-en-v1.5) or a full local directory path inside the container (e.g. a directory produced by swaleio/hf-download). A repo id is downloaded from the Hub at startup; a local path skips the download.
    required: true
  port:
    description: TCP port the server listens on. Defaults to 8080; pass a different value to serve elsewhere, and point every consumer URL at the same port.
    default: "8080"
  token:
    description: Hugging Face access token for gated or private Hub models (pass a secret). Omit for public models or local model directories.
    default: ""
exec:
  # docker.io/swaleio/tei:1.10.0
  image: docker.io/swaleio/tei@sha256:4c234582db34231cd1fa95d653f3b9306eb65a968d9533189ceb9cf1f8c7c43e
  env:
    HF_TOKEN: ${{inputs.token}}
  args:
    - "--model-id"
    - ${{inputs.model}}
    - "--hostname"
    - "0.0.0.0"
    - "--port"
    - ${{inputs.port}}
```

# Text Embeddings Inference serve

Starts Hugging Face's
[Text Embeddings Inference](https://huggingface.co/docs/text-embeddings-inference)
(TEI) server for an embedding, reranker or sequence-classification model. It
answers on:

- `POST /embed`, with `{"inputs": ["text", ...]}`, returning one vector per
  input;
- `POST /v1/embeddings`, the OpenAI-compatible form, with
  `{"input": ["text", ...], "model": "<any name>"}`;
- `POST /rerank`, with `{"query": "...", "texts": ["...", ...]}`, for reranker
  models;
- `GET /health`, which returns `200` once the model is loaded.

`model` accepts a Hub repo id, downloaded into the task's home directory when
the server starts, or the full path of a local model directory, such as one
`swaleio/hf-download` fetched. TEI supports the BERT, XLM-RoBERTa, ModernBERT,
GTE, Nomic, Qwen3 and other embedding architectures; a model's Hub page shows
the `text-embeddings-inference` tag when TEI can serve it.

This is a **runner** task: it serves requests indefinitely and never exits on
its own. Its lifetime is bounded by its own `terminate_on` list — the platform
terminates the runner when the tasks listed there complete. A workflow that
starts this task without wiring `terminate_on` never finishes.

## Inputs

| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| `model` | yes | — | Hub repo id (e.g. `BAAI/bge-small-en-v1.5`) or a full local model directory path (e.g. `${{env.WORKFLOW_STORAGE}}/bge` from `swaleio/hf-download`). A local path skips the Hub download. |
| `port` | no | `8080` | Port the server listens on. Consumers combine it with the runner's ip-address, so every consumer URL must use the same port. |
| `token` | no | — | HF access token for gated/private Hub models (pass a secret); delivered to the server as `HF_TOKEN` via the definition's `exec.env`. Unneeded for public models or local directories. |

## Outputs

None. Runner tasks are long-lived pods terminated via `terminate_on` and get no
output-tracking sidecar, so this task declares no outputs. Consumers read the
server's responses over HTTP instead.

## Compute

**GPU required.** The image holds TEI's CUDA builds for the A100 and H100 and
picks the one for the GPU it finds; it does not start on a CPU compute type.
Embedding models are small, so any GPU compute type fits them; the GPU's
throughput is what the server is for.

## Runner lifecycle and consumers

- **Termination**: the runner's own `terminate_on` lists its consumers. When
  every task in that list completes, the platform terminates the runner.
- **Address**: consumers reach the server at `${{tasks.<id>.ip-address}}` on
  the server's port — `8080` unless the step passed `port`.
- **Ordering**: every consumer MUST list the runner in its own `start_on` —
  the address only exists once the runner task has started.
- **Readiness**: the address is available at pod start, which is *before* the
  model is loaded. Consumers poll `GET /health` until it returns `200`, with
  `swaleio/http-request` and `retry: "360"`, `retry_delay: "5"`: a check every
  5 seconds for up to 30 minutes.

## Example

Serve a small English embedding model, wait for it to load, embed two
sentences, and let the request's finish terminate the server.
[BAAI/bge-small-en-v1.5](https://huggingface.co/BAAI/bge-small-en-v1.5) is MIT.

```yaml
name: TEI serve example
compute_type: cpu-4
entry_point: main

blocks:
  main:
    tasks:
      serve:
        name: Serve embeddings
        uses: swaleio/tei-serve
        compute_type: a100-1
        terminate_on: [embed]
        args:
          model: BAAI/bge-small-en-v1.5

      wait_ready:
        name: Wait for server
        uses: swaleio/http-request
        start_on: [serve]
        args:
          url: http://${{tasks.serve.ip-address}}:8080/health
          retry: "360"
          retry_delay: "5"
          expected_status: "200"

      embed:
        name: Embed
        uses: swaleio/http-request
        start_on: [wait_ready]
        args:
          url: http://${{tasks.serve.ip-address}}:8080/embed
          method: POST
          headers: |
            Content-Type: application/json
          body: '{"inputs":["Swale runs workflows.","Embeddings map text to vectors."]}'
          expected_status: "200"
          response_path: ${{env.WORKFLOW_STORAGE}}/embeddings.json
```

Later tasks read the vectors at `${{env.WORKFLOW_STORAGE}}/embeddings.json`.

---

For the workflow syntax these examples use, see the
[workflow definition reference](https://docs.swale.io/reference/workflow-definition-syntax)
in the [Swale documentation](https://docs.swale.io).

Licensed under the [MIT License](https://github.com/swaleio/task-definitions/blob/main/LICENSE).
