feat(ml): fuse two embedding models and protect the ML service with a token

This commit is contained in:
shira committed 2026-10-11 14:40:52 +03:00
1 parent bc00d6901f
commit b24e5ff906
63 files changed
+2287 -276

No files matched your search

+13 -8
View File
@@ -24,24 +24,28 @@ COPY ml/.python-version ml/pyproject.toml ml/uv.lock ./ml/
COPY ml/src ./ml/src
RUN uv sync --project ml --python /usr/local/bin/python --locked --no-dev --no-editable
# The model files are fetched once, at build time, from the pinned revision
# The model files are fetched once, at build time, from the pinned revisions
# and verified against the SHA-256 of the lock file. Only safetensors weights,
# configs, and the tokenizer are fetched: no remote code, no pickle weights.
FROM base AS model
COPY ml/src/lincodex_ml/model_files.py /tmp/model_files.py
COPY ml/model/giga-embeddings-480m.lock.json /tmp/model.lock.json
RUN python /tmp/model_files.py fetch --lock /tmp/model.lock.json --out /opt/lincodex/model \
&& rm /tmp/model_files.py /tmp/model.lock.json
COPY ml/model/giga-embeddings-480m.lock.json ml/model/qwen3-embedding-0.6b.lock.json /tmp/locks/
RUN python /tmp/model_files.py fetch --lock /tmp/locks/giga-embeddings-480m.lock.json --out /opt/lincodex/models/giga-480m \
&& python /tmp/model_files.py fetch --lock /tmp/locks/qwen3-embedding-0.6b.lock.json --out /opt/lincodex/models/qwen3-0.6b \
&& rm -r /tmp/model_files.py /tmp/locks
FROM base
ENV PATH="/opt/venv/bin:${PATH}" \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
ML_EMBEDDER=giga \
ML_MODEL_DIR=/opt/lincodex/model \
ML_EMBEDDER=giga,qwen3 \
ML_GIGA_MODEL_DIR=/opt/lincodex/models/giga-480m \
ML_QWEN3_MODEL_DIR=/opt/lincodex/models/qwen3-0.6b \
ML_TORCH_THREADS=4 \
ML_LISTEN_HOST=0.0.0.0 \
ML_LISTEN_PORT=8000 \
HF_HUB_OFFLINE=1 \
TRANSFORMERS_OFFLINE=1 \
HF_HUB_DISABLE_TELEMETRY=1
@@ -55,7 +59,7 @@ RUN python -m pip uninstall --yes pip \
COPY --from=build --chown=lincodex:lincodex /opt/venv /opt/venv
# Read-only for the service user: root owns the weights.
COPY --from=model /opt/lincodex/model /opt/lincodex/model
COPY --from=model /opt/lincodex/models /opt/lincodex/models
USER 10001:10001
EXPOSE 8000
@@ -63,4 +67,5 @@ EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2)"]
CMD ["uvicorn", "lincodex_ml.main:app", "--host", "0.0.0.0", "--port", "8000"]
# The entry point refuses to listen on 0.0.0.0 without ML_SERVICE_TOKEN.
CMD ["python", "-m", "lincodex_ml.serve"]