> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sglang.io/llms.txt
> Use this file to discover all available pages before exploring further.

# ModernBERT-base

> Serve ModernBERT-base on one NVIDIA GPU and get a normalized vector for each input text.

[ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base) is a 149M-parameter bidirectional encoder trained on English text and code. SGLang serves the base checkpoint through `/v1/embeddings`. Each input can contain up to 8,192 tokens, including special tokens.

## Start the server

Use an [SGLang installation](https://docs.sglang.io/docs/get-started/install.md) that includes ModernBERT support on a Linux machine with one NVIDIA CUDA GPU. The checkpoint is public. This command uses FP16 and the Triton attention backend. It disables prefix caching and chunked prefill so that each token can attend to the full input in the global attention layers.

```bash theme={null}
sglang serve \
  --model-path answerdotai/ModernBERT-base \
  --dtype float16 \
  --attention-backend triton \
  --disable-radix-cache \
  --chunked-prefill-size -1
```

## Embed a batch of texts

From another terminal, send two inputs in one request. The example prints each input's index, vector dimension and L2 norm so you can check the response without printing 1,536 floats.

```python theme={null}
import json
import math
from urllib.request import Request, urlopen

payload = {
    "model": "answerdotai/ModernBERT-base",
    "input": ["The file was saved.", "The file could not be opened."],
    "encoding_format": "float",
}
request = Request(
    "http://127.0.0.1:30000/v1/embeddings",
    data=json.dumps(payload).encode(),
    headers={"Content-Type": "application/json"},
)
with urlopen(request) as response:
    embeddings = json.load(response)["data"]

for item in embeddings:
    vector = item["embedding"]
    print(item["index"], len(vector), round(math.sqrt(sum(x * x for x in vector)), 3))
```

Expect indices 0 and 1, each with 768 dimensions and a norm close to 1. SGLang takes the last token's hidden state for each input and L2-normalizes it. Use the same pooling and normalization when comparing against a Transformers reference.

The base checkpoint was pretrained with masked language modeling. For semantic search, evaluate retrieval quality on your own queries and documents. A retrieval-tuned checkpoint can use a different pooling rule.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.