CoolFace
Apppublic

rohadiz/lightweight-embeddings

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

Lightweight Embeddings

A multilingual text + image embedding & reranking API. Production-grade, OpenAI-compatible, single Docker image.

bash
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 model field; only the models you actually use are loaded.
  • OpenAI-compatible/v1/embeddings, /v1/rank, /v1/models; supports encoding_format=base64 and Matryoshka dimensions.
  • Crash-resistant — body size limits, request validation, multi-tier rate limits, adaptive shedding, memory guard.
  • Observable — Prometheus /metrics, structured JSON logs, X-Request-ID propagation.
  • Slim — multi-stage python:3.10-slim image with jemalloc + HEALTHCHECK.

Models

NameKindDimMax tokensCost
multilingual-e5-small (default)text3845121.0
multilingual-e5-basetext7685122.0
multilingual-e5-largetext10245124.0
paraphrase-multilingual-MiniLM-L12-v2text3841280.8
paraphrase-multilingual-mpnet-base-v2text7681282.0
gte-multilingual-basetext76881922.5
bge-m3text102481925.0
snowflake-arctic-embed-l-v2.0text1024 (Matryoshka 256/512/1024)81925.0
embeddinggemma-300mtext768 (Matryoshka 128/256/512/768)20484.0
siglip-base-patch16-256-multilingualimage7686.0

Usage

bash
# 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

TierRPSPer minutePer dayCU/dayConcurrency
anonymous1 (burst 3)302 0002 0002
free (any valid token)5 (burst 20)20050 00050 0008
pro (reserved)30 (burst 100)configurableconfigurable1 000 00032

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.

VariableDefaultPurpose
LWE_ACCESS_TOKENunsetBearer token enabling the free tier
LWE_MODELS_PRELOADmultilingual-e5-smallCSV / * / none — which models to load on boot
LWE_DEVICEautoauto · cpu · cuda
LWE_LOG_JSONfalseSwitch logs to structured JSON
LWE_CORS_ORIGINS*CSV of allowed origins
LWE_MAX_BODY_BYTES2097152Hard request body cap
LWE_CONCURRENCY_GLOBAL64Total concurrent requests
LWE_CONCURRENCY_PER_MODEL16Per-model concurrency
LWE_REDIS_URL / LWE_REDIS_TOKENunsetUpstash Redis for analytics persistence

Endpoints

MethodPathDescription
POST/v1/embeddingsGenerate text or image embeddings
POST/v1/rankCosine + softmax reranking
GET/v1/modelsList registered models
GET/v1/statsUsage analytics (token-gated)
GET/v1/quotaCaller's current rate-limit state
GET/healthzLiveness
GET/readyzReadiness (model loaded, memory OK)
GET/metricsPrometheus metrics

Develop

bash
pip install -e ".[dev]"
pytest tests/unit -q
ruff check lightweight_embeddings tests

Heavy integration tests are gated behind the integration pytest marker.

License

MIT — see LICENSE.