Skip to main content

Module onnx

Module onnx 

Source
Expand description

ONNX Runtime local embedding provider.

Provides local embedding inference using ONNX Runtime, eliminating the need for an external API. Supports sentence-transformer models such as all-MiniLM-L6-v2 exported to ONNX format.

§Feature gating

When compiled without the onnx feature the module provides a stub that validates the model path but returns Error::Embedding from embed() and embed_batch().

When compiled with the onnx feature the module loads the ONNX session and a HuggingFace tokenizer, then performs real local inference with mean-pooling and L2 normalisation.

[features]
onnx = ["dep:ort", "dep:tokenizers", "dep:ndarray"]

[dependencies]
ort = { version = "2.0.0-rc.11", optional = true }
tokenizers = { version = "0.23", optional = true, default-features = false, features = ["fancy-regex"] }
ndarray = { version = "0.17", optional = true }

These are the versions the workspace actually pins. The #[cfg(feature = "onnx")] inference path is written against — and builds + tests against — this ort 2.0.0-rc.11 / ndarray 0.17 / tokenizers 0.23 API (the migration that repaired the old ndarray-0.16 drift). A dedicated onnx feature CI job (.github/workflows/ci.yml) builds and tests --features onnx so it cannot silently rot; it stays out of the workspace-wide jobs only because ort is a heavy native dependency. The one open item on https://github.com/sattyamjjain/mnemo/issues/125 is a model-fetch CI job to make the ONNX MiniLM recall number itself reproducible (end-to-end inference needs a real model on disk via MNEMO_ONNX_MODEL_PATH, which the build+test job does not fetch). Build locally with --features onnx.

§Example (stub)

use mnemo_core::embedding::onnx::OnnxEmbedding;
use mnemo_core::embedding::EmbeddingProvider;

// Will succeed only if the path exists on disk.
let provider = OnnxEmbedding::new("/models/all-MiniLM-L6-v2.onnx", 384)
    .expect("model path must exist");

assert_eq!(provider.dimensions(), 384);
assert_eq!(provider.model_path(), "/models/all-MiniLM-L6-v2.onnx");

Structs§

OnnxEmbedding
ONNX-based local embedding provider.