Files
lincodex/.agents/standards/ml.md
T

2.0 KiB

ML service standard

The ML service is a separate Python HTTP service. It serves health and readiness routes and one model-backed endpoint, POST /v1/embeddings, with pinned embedding models whose files are verified against the lock files in ml/model/ (baked into the image, or local files on a GPU host). Every route except health and readiness requires the shared bearer token. Ordinary tests use the deterministic fake encoder; the real models run only in the marked slow tests.

Keep the service contract in api/ml/. The Go client uses backend/codegen/ogen-ml.yml and is consumed under backend/internal/adapter/secondary/ml/api/. Python model generation belongs to ml/codegen/pyproject.toml: datamodel-code-generator produces Pydantic v2 models from api/ml/openapi.bundle.yml in ml/src/lincodex_ml/api/models.py. Keep generator dependencies in ml/pyproject.toml and uv.lock; the codegen pyproject contains tool settings only. Health/readiness handlers import generated models instead of maintaining duplicate transport schemas.

Use make -C ml generate to bundle the contract and generate models. The root generation target passes API_PREPARED=1 after preparing the shared bundle. Use make -C ml check-generated to detect drift with the generator's --check mode without rewriting output. Do not edit generated models manually.

Readiness must describe whether the required model or inference runtime is available. Return not-ready while it is unavailable. Do not invent a successful result or label a fixture as a model response.

When inference is added, validate structured output, bound input and output size, apply timeouts, and preserve model and schema versions. Avoid logging resume text, contact details, credentials, or full prompts. Treat document contents and model output as untrusted data.

Use uv with the checked-in lockfile. Keep ordinary lint, type checks, and tests independent of external model downloads and GPU access. Model quality evaluation is a separate, reproducible task with documented data and limits.

All source comments and docstrings are in English.