Skip to main content

mnem_sparse_providers/
lib.rs

1//! # mnem-sparse-providers
2//!
3//! Learned-sparse encoder adapters for mnem. Implements the
4//! [`mnem_core::sparse::SparseEncoder`] trait for the three shipping
5//! backends :
6//!
7//! - **Sidecar** (always available): HTTP POST to a local Python
8//!   service running the reference SPLADE / BGE-M3 implementation.
9//!   Lightest install; the sidecar handles weights + tokenization.
10//! - **ONNX** (feature `onnx`): in-process inference via `ort` +
11//!   `tokenizers`. Pulls an ~80MB onnxruntime binary and a ~70MB
12//!   quantized model weights file. Fastest but heaviest dep.
13//! - **Mock** (always available, re-exports
14//!   [`mnem_core::sparse::MockSparseEncoder`]): deterministic
15//!   length-inverse hash, for tests and dry-run benchmarks.
16//!
17//! ## Why ONNX is feature-gated
18//!
19//! `ort` wraps a C++ shared library; `tokenizers` carries internal
20//! `unsafe` for its SIMD fast paths. Both compile fine on native
21//! but do NOT compile to wasm32. Keeping them optional means a
22//! wasm-target build of mnem + this crate stays clean; and users who
23//! don't want the onnxruntime dep skip it entirely.
24//!
25//! ## Why sidecar is the default
26//!
27//! Most real users will run SPLADE inside their existing Python ML
28//! infra. The sidecar transport keeps mnem-sparse-providers a
29//! single binary with one HTTP dep (ureq + rustls), deferring the
30//! heavy lifting to whatever the user already has running.
31//!
32//! ## Invariants
33//!
34//! - **No tokio.** All adapters are sync. Matches every other mnem
35//!   provider crate.
36//! - **No API keys on disk.** Sidecar URLs are configurable; auth
37//!   (when needed) comes from env vars.
38//! - **`mnem-core` stays zero-network.** This crate carries the
39//!   HTTP + optional ML runtime deps alone.
40
41#![forbid(unsafe_code)]
42#![deny(missing_docs)]
43
44pub mod config;
45pub mod sidecar;
46
47#[cfg(feature = "onnx")]
48pub mod onnx;
49
50// Re-export the mock so callers get a one-line swap for adapter
51// tests without pulling mnem-core directly.
52pub use mnem_core::sparse::MockSparseEncoder;
53
54pub use config::{ProviderConfig, SidecarConfig, open};