blazen_embed_tract/lib.rs
1//! Pure-Rust ONNX inference backend for Blazen embeddings via `tract-onnx`.
2//!
3//! Mirrors the public API of `blazen-embed-fastembed` so the two backends are
4//! swappable via `cfg` gating in `blazen-llm`. Exists because `fastembed`/`ort`
5//! require Microsoft's prebuilt ONNX Runtime binaries which are not published
6//! for several target triples (notably `*-unknown-linux-musl` and `wasm32-*`).
7//!
8//! ## wasm32 support
9//!
10//! On `wasm32-*` targets the native [`provider`] module is compiled out
11//! because its `from_options` constructor relies on `tokio` runtime primitives
12//! and on `blazen-model-cache`'s `HuggingFace` Hub downloader, neither of
13//! which compiles to wasm32. In its place, [`wasm_provider`] exposes
14//! [`WasmTractEmbedModel`] which downloads ONNX weights and the tokenizer via
15//! `web_sys::fetch` and runs inference through the same `tract-onnx` pipeline.
16
17pub mod options;
18
19#[cfg(not(target_arch = "wasm32"))]
20pub mod provider;
21
22#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
23pub mod wasm_provider;
24
25#[cfg(all(target_arch = "wasm32", target_os = "wasi"))]
26pub mod wasi_provider;
27
28pub use options::TractOptions;
29
30#[cfg(not(target_arch = "wasm32"))]
31pub use provider::{TractEmbedModel, TractError, TractResponse};
32
33#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
34pub use wasm_provider::{WasmTractEmbedModel, WasmTractError, WasmTractResponse};
35
36#[cfg(all(target_arch = "wasm32", target_os = "wasi"))]
37pub use wasi_provider::{WasiTractEmbedModel, WasiTractError, WasiTractResponse};