Embeddings server needed for the knowledge base search with the AI-assistant of Baserow.
2.9K
A lightweight, self-contained text embedding microservice for Baserow's AI Assistant features. This service provides fast sentence embeddings using an ONNX export of the model.
This service converts text into dense vector representations (embeddings) that can be used for:
Model: sentence-transformers/all-MiniLM-L6-v2, from its ONNX export optimum/all-MiniLM-L6-v2 at a pinned revision
The service uses a multi-stage Docker build:
There are two images. Both create the same vectors, so they can be swapped without re-embedding.
| Image | Runs on | Platforms | Size |
|---|---|---|---|
baserow/embeddings:1.1.0 | CPU | linux/amd64, linux/arm64 | ~0.6 GB |
baserow/embeddings:1.1.0-gpu | NVIDIA GPU, with CUDA | linux/amd64 | ~2.2 GB |
The CPU image is enough for the AI assistant's knowledge base and for searching. The GPU image is only worth it to embed large volumes, like enabling semantic search on big tables.
docker run -p 127.0.0.1:8080:80 baserow/embeddings:1.1.0
The service will be available at http://localhost:8080.
The host needs an NVIDIA driver of version 525 or newer and the NVIDIA Container Toolkit.
docker run --gpus all -p 127.0.0.1:8080:80 baserow/embeddings:1.1.0-gpu
EMBEDDINGS_DEVICE=cpu to run it without a GPU anyway.BASEROW_EMBEDDINGS_TEXTS_PER_REQUEST to 64 in Baserow, so that its requests fill those batches.Bump the version in the tags, and in the run commands above, for every release. Publish both images with the same version.
CPU image:
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t baserow/embeddings:1.1.0 \
-t baserow/embeddings:latest \
--push .
GPU image, which only supports linux/amd64:
docker buildx build \
--platform linux/amd64 \
--build-arg REQUIREMENTS=requirements-gpu.txt \
-t baserow/embeddings:1.1.0-gpu \
-t baserow/embeddings:latest-gpu \
--push .
CPU image:
docker build -t baserow-embeddings .
docker run -p 127.0.0.1:8080:80 baserow-embeddings
GPU image:
docker build --build-arg REQUIREMENTS=requirements-gpu.txt -t baserow-embeddings-gpu .
docker run --gpus all -p 127.0.0.1:8080:80 baserow-embeddings-gpu
| Environment variable | Description | Default |
|---|---|---|
EMBEDDINGS_NUM_THREADS | Number of CPU threads used for inference, as a positive integer. Requests are processed one at a time, using all threads. | The container's CPU limit rounded up, or all CPUs without a limit. |
EMBEDDINGS_MODEL_DIR | Directory with the model files. Change it only to run the service outside Docker. | /model |
EMBEDDINGS_DEVICE | cpu or gpu. Set cpu to run the GPU image without a GPU. | gpu in the GPU image, otherwise cpu. |
POST /embedGenerate embeddings for one or more texts.
Request:
{
"texts": "Your text here"
}
or for batching:
{
"texts": ["First text", "Second text", "Third text"]
}
Response:
{
"embeddings": [[0.123, -0.456, ...], ...]
}
Texts longer than 512 tokens are truncated.
Errors: 400 with an error message for invalid JSON, a missing texts field, a texts that isn't a string or a list of strings, an empty list or more than 256 texts, and 413 for a body over 1 MiB.
Example:
curl -X POST http://localhost:8080/embed \
-H "Content-Type: application/json" \
-d '{"texts": "What is the capital of France?"}'
GET /healthHealth check endpoint.
Response:
{
"status": "healthy"
}
# From this directory, with Python 3.13 or newer (the image uses 3.14)
python3 -m venv .venv
source .venv/bin/activate
# Install the image's packages, plus huggingface_hub to download the model
pip install --no-deps -r requirements.txt
pip install -c requirements.txt huggingface_hub==2.2.0
# Download model
export EMBEDDINGS_MODEL_DIR="$PWD/model"
python _download_model.py
# Run locally, in a shell where EMBEDDINGS_MODEL_DIR is set
uvicorn app:app --host 127.0.0.1 --port 8080
import json
import urllib.request
request = urllib.request.Request(
"http://localhost:8080/embed",
data=json.dumps({"texts": ["Hello world", "How are you?"]}).encode(),
headers={"Content-Type": "application/json"},
)
with urllib.request.urlopen(request) as response:
embeddings = json.load(response)["embeddings"]
print(f"Generated {len(embeddings)} embeddings of dimension {len(embeddings[0])}")
Baserow's AI Assistant uses this service to search the Baserow documentation:
sync_knowledge_base management command, Baserow splits the docs into chunks and stores their embeddingssearch_user_docs tool embeds the user's question and finds the closest chunks, even without a keyword matchMeasured on an Apple M2 Max with the Helm chart's limits of 1 CPU and 1.5 GiB:
Python 3.14, with every runtime package pinned in requirements.txt, so rebuilds install exactly the same versions. huggingface_hub is only used in the build stage, to download the model.
To update a package, install the new versions of numpy, onnxruntime, starlette and uvicorn into a clean Python 3.14 environment, add tokenizers with --no-deps, and write the output of pip freeze below the comment at the top of requirements.txt. The build stage installs huggingface_hub, pinned in the Dockerfile and above, with -c requirements.txt, so check that it still installs. After a bump, compare a few vectors with the previous image.
requirements-gpu.txt pins the GPU image the same way, with onnxruntime-gpu[cuda,cudnn] instead of onnxruntime, in a linux/amd64 environment. Keep onnxruntime-gpu at the same version as onnxruntime.
This service is part of the Baserow project. See the main repository for license information.
Content type
Image
Digest
sha256:b8d25fa2a…
Size
167.7 MB
Last updated
20 days ago
docker pull baserow/embeddings