Lightweight FastAPI wrapper that exposes any sentence-transformers model over HTTP for easy embedding generation.
- Install the package from PyPI (Python 3.13+):
pip install stserve
- Launch the server with the default MiniLM model (choose your preferred runner):
stserve # or via uvx uvx stserve - Request embeddings from another terminal:
curl -X POST http://127.0.0.1:8501/embed \ -H "Content-Type: application/json" \ -d '{"texts": ["hello world", "how are you?"]}'
--model: sentence-transformers model name or local path (defaults toall-MiniLM-L6-v2).--device: target Torch device; auto-detects CUDA.--batch-size: batches encode calls for throughput.--normalize: toggles L2 normalization on embeddings.--show-progress: prints encode progress in the server logs.--host/--port: Uvicorn bind address (defaults127.0.0.1:8501).
Example with GPU and normalization:
uvx stserve --model sentence-transformers/all-MiniLM-L12-v2 --device cuda --normalizePOST /embed: Body{ "texts": [str, ...] }→{ "embeddings": [[float, ...], ...] }.GET /health: Returns current configuration (model, device, batch size, etc.).
- The CLI entry point is
stserve.app:main. - Embedding work happens in a thread pool so the event loop stays responsive.
- CUDA usage requires PyTorch with GPU support.