Skip to content

feat(contamination): add offline ONNX embedding backend - #18

Merged
FreakyAdy merged 11 commits into
masterfrom
feat/onnx-semantic-backend
Oct 17, 2026
Merged

FreakyAdy merged 11 commits into
masterfrom
feat/onnx-semantic-backend

Conversation

@FreakyAdy

Copy link
Copy Markdown
Owner

Closes #5

Summary

Adds OnnxRuntimeBackend for local transformer embeddings without requiring PyTorch. It accepts an explicit ONNX model path and a matching local tokenizer directory, loads tokenizer assets with local_files_only=True, and supports both sentence-level embeddings and token-level hidden states with attention-mask mean pooling.

SemanticDetector now supports an ordered fallback_backends chain. If a configured backend fails, it tries the next backend; if all configured backends fail, it logs the failures and uses the lightweight TF-IDF fallback. Existing Sentence Transformers behavior remains the default. The ONNX backend is exported from evalguard.contamination and uses the new optional onnx extra (onnxruntime + transformers, no explicit PyTorch dependency).

Coverage

  • Attention-mask mean pooling ignores padding tokens
  • Direct sentence-embedding outputs are accepted
  • Empty batches avoid loading optional dependencies
  • Missing local models fail with a clear path error
  • Fallback order and TF-IDF final fallback
  • Invalid thresholds and maximum lengths

Added docs/onnx_semantic_backend.md with offline configuration and model-interface requirements. CI is running; no model weights are downloaded in tests.

@FreakyAdy
FreakyAdy merged commit 7b6ffa8 into master Oct 17, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(contamination): Add quantized ONNX runtime option for offline MiniLM embeddings

1 participant