lamhieu/lightweight-embeddings
12
Lightweight Embeddings
A multilingual text + image embedding & reranking API. Production-grade, OpenAI-compatible, single Docker image.
docker run --rm -p 7860:7860 ghcr.io/lh0x00/lightweight-embeddings→ API: <http://localhost:7860/docs> · Playground: <http://localhost:7860/>
Why
- One service, ten models — switch via the
modelfield; only the models you actually use are loaded. - OpenAI-compatible —
/v1/embeddings,/v1/rank,/v1/models; supportsencoding_format=base64and Matryoshkadimensions. - Crash-resistant — body size limits, request validation, multi-tier rate limits, adaptive shedding, memory guard.
- Observable — Prometheus
/metrics, structured JSON logs,X-Request-IDpropagation. - Slim — multi-stage
python:3.10-slimimage withjemalloc+HEALTHCHECK.
Models
Usage
# Embed
curl -X POST http://localhost:7860/v1/embeddings \
-H 'Content-Type: application/json' \
-d '{
"model": "multilingual-e5-small",
"input": ["Xin chào", "Hello"],
"encoding_format": "float"
}'
# Rerank
curl -X POST http://localhost:7860/v1/rank \
-H 'Content-Type: application/json' \
-d '{
"model": "multilingual-e5-small",
"queries": "happy person",
"candidates": ["happy dog", "sunny day", "very happy person"]
}'
# Inspect
curl http://localhost:7860/v1/models
curl http://localhost:7860/healthz
curl http://localhost:7860/v1/quota \
-H 'Authorization: Bearer $LWE_ACCESS_TOKEN'Use encoding_format=base64 for ~45% smaller payloads, or dimensions to truncate Matryoshka models.
Quota tiers
CU = model_cost_weight × tokens / 1000 for text, or × n_images for images. Limits surface in X-RateLimit-* headers; 429 and 503 always include Retry-After.
Configuration
All variables are prefixed LWE_. Selected highlights — see `settings.py` for the full list.
Endpoints
Develop
pip install -e ".[dev]"
pytest tests/unit -q
ruff check lightweight_embeddings testsHeavy integration tests are gated behind the integration pytest marker.
License
MIT — see LICENSE.
