Deploy SentenceTransformers embedding models to a ray cluster
Project description
Ray Embedding Service
ray-embedding packages everything needed to expose SentenceTransformers models through an OpenAI-compatible API that runs on a Ray Serve cluster. It provides:
- A FastAPI-based
ModelRouterthat rate-limits requests, shards large batches, and fans out work to autoscaled replicas. - An
EmbeddingModeldeployment that loads any Hugging Face transformer compatible withsentence-transformers, handles Matryoshka truncation, and periodically checks the health of the underlying GPU via CUDA health checks. - A
NodeRecyclersupervisor that watches for unhealthy replicas, warns colocated peers, and recycles the underlying worker node safely.
This library is designed for the embedding-models Ray cluster, but can be embedded in any Serve app with similar requirements. See the reference Serve configuration for production defaults.
Architecture
The deployment is organised into three building blocks: API ingress, model replicas, and the recycler that ties health reporting to infrastructure level actions.
- Clients call the router using standard OpenAI embedding verbs.
- The router batches, normalises paths, and invokes the selected embedding replica.
- Each replica registers itself with the recycler, reports GPU/CUDA failures, and warns other colocated replicas about failed nodes.
- When a node is marked unhealthy, the recycler informs every colocated replica/router (except the reporter), waits one recycle cycle for graceful shutdown, then issues an SSH stop to the worker’s Docker runtime.
Failure & Recycling Workflow
When a replica hits a CUDA error (or any fatal condition), the recycler coordinates a graceful drain so clients experience deterministic errors while Ray’s autoscaler replaces the failed node.
- The router dispatches a batch and receives an exception from a replica.
- The replica reports the failure; the recycler immediately pings all other replicas and the router on that node to start failing their health checks.
- During the next recycle cycle, the node is terminated via SSH after the replicas have had a chance to flush in-flight work.
Quickstart
- Install dependencies
pip install -r requirements.txt pip install -r requirements-build.txt # optional, for packaging
- Package & upload models (optional) – store SentenceTransformers-compatible checkpoints accessible to your Ray cluster.
- Deploy to Ray Serve
ray pipeline submit serve-config.yaml
Updateserve-config.yamlto point at your models, GPU sizing, and SSH credentials for the recycler.
Local Development
- Create a virtual environment and install the package in editable mode:
pip install -e .[dev](seepyproject.tomlfor extras). - Run lint/test tools of your choice; as a quick syntax check you can execute
python -m compileall ray_embedding. - Update docs/Serve configs and regenerate diagrams as needed (see below).
Diagram Sources
High-resolution PNGs live under docs/diagrams so Bitbucket renders them inline. To edit them:
# Edit the .mmd files under docs/diagrams
npx -y @mermaid-js/mermaid-cli@8.13.10 -i docs/diagrams/architecture.mmd -o docs/diagrams/architecture.png -w 1920
npx -y @mermaid-js/mermaid-cli@8.13.10 -i docs/diagrams/failure_workflow.mmd -o docs/diagrams/failure_workflow.png -w 1920
Supported Backends
- pytorch-gpu
- pytorch-cpu
Planned Backends
- onnx-gpu
- onnx-cpu
- openvino-cpu
- fastembed-onnx-cpu
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ray_embedding-0.15.0.tar.gz.
File metadata
- Download URL: ray_embedding-0.15.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
198b309316a83e1eed7551d5f1df80b03f496bcfe27e9908caf1361fe5821273
|
|
| MD5 |
4fbb7fd3d3ecd2f6985b89c73794ba88
|
|
| BLAKE2b-256 |
5ae61211b91466f7534f01b54eef04f1b1ff612d7dd481b8daef17397dd08076
|
File details
Details for the file ray_embedding-0.15.0-py3-none-any.whl.
File metadata
- Download URL: ray_embedding-0.15.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7884187e6364a01b8b35835a3a726db99a2ac4208d70ba54bb644b48835b48ae
|
|
| MD5 |
dae8895804cbea9734e719063c9e03aa
|
|
| BLAKE2b-256 |
d246e73c3ac052bbb3eadebe3a415f2631e3abd8852393bf4f809358a471e99b
|