Layer 3 Stateless NLI Worker — A high-throughput, latency-optimized model service for grounding & faithfulness validation.
This service runs the cross-encoder/nli-deberta-v3-base Natural Language Inference (NLI) model to perform sentence-pair classification. It serves as a stateless backend inference microservice (Model-as-a-Service) for evaluating the grounding of LLM completions against retrieved RAG context.
8009.8 pairs/pass, adjustable via NLI_BATCH_SIZE) for optimal GPU/CPU throughput.400 tokens using the model tokenizer, performing a max-entailment aggregation across chunks.GET/POST /healthz
Response:
{
"status": "ok",
"model": "nli-deberta-v3-base",
"device": "cpu"
}
POST /nli
Request Body:
{
"context": "The Eiffel Tower is located in Paris, France. It was built in 1889.",
"sentences": [
"The Eiffel Tower is in Paris.",
"It was built in 2020."
],
"temperature": 1.5
}
Response:
{
"results": [
{
"sentence": "The Eiffel Tower is in Paris.",
"label": "entailment",
"probabilities": {
"entailment": 0.965,
"neutral": 0.030,
"contradiction": 0.005
}
},
{
"sentence": "It was built in 2020.",
"label": "contradiction",
"probabilities": {
"entailment": 0.002,
"neutral": 0.008,
"contradiction": 0.990
}
}
],
"faithfulness_score": 0.5,
"flagged_sentences": [
"It was built in 2020."
]
}
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest tests/ -v
uvicorn api.rest.v1.app:app --host 0.0.0.0 --port 8009
docker build -f build/Dockerfile -t chiefj/nli-worker:latest .
This produces a lightweight image of 229 MB.
To avoid downloading model weights on every container start, mount a persistent host Hugging Face cache directory:
docker run -d \
--name nli-worker \
-p 8009:8009 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
chiefj/nli-worker:latest
Content type
Image
Digest
sha256:297973468…
Size
73.8 MB
Last updated
4 months ago
docker pull chiefj/nli-worker