Skip to main content

blazen_embed/
lib.rs

1//! Facade over the concrete embedding backend for the current target.
2//!
3//! Backend selection priority:
4//! 1. `--features embed-fastembed` forces the fastembed (ORT) backend.
5//! 2. `--features embed-tract` forces the pure-Rust tract backend.
6//! 3. Otherwise the target-cfg in `Cargo.toml` picks the default:
7//!    - fastembed on `aarch64-apple-darwin`, `x86_64-pc-windows-msvc`,
8//!      `x86_64-unknown-linux-gnu` (the only triples with ORT prebuilts).
9//!    - tract on every other target (aarch64-linux, musl, all wasm,
10//!      aarch64-windows, AND x86_64-apple-darwin — pyke dropped the Intel-mac
11//!      ORT prebuilt, so the facade routes Intel macs to tract here).
12//!
13//! Downstream code imports ONLY from this crate. The backend selection is invisible.
14//!
15//! `embed-fastembed` and `embed-tract` are documented as mutually exclusive.
16//! If both are set, fastembed wins (the re-export below picks it first); this
17//! is a soft guarantee — prefer enabling exactly one.
18
19// --- Forced fastembed (feature wins over target-cfg default) ---
20#[cfg(feature = "embed-fastembed")]
21pub use blazen_embed_fastembed::{
22    FastEmbedError as EmbedError, FastEmbedModel as EmbedModel, FastEmbedOptions as EmbedOptions,
23    FastEmbedResponse as EmbedResponse,
24};
25
26// --- Forced tract (only when fastembed is NOT also forced) ---
27#[cfg(all(feature = "embed-tract", not(feature = "embed-fastembed")))]
28pub use blazen_embed_tract::{
29    TractEmbedModel as EmbedModel, TractError as EmbedError, TractOptions as EmbedOptions,
30    TractResponse as EmbedResponse,
31};
32
33// --- Default fastembed on ORT-supported triples (no override feature set) ---
34#[cfg(all(
35    not(feature = "embed-fastembed"),
36    not(feature = "embed-tract"),
37    not(target_family = "wasm"),
38    not(target_env = "musl"),
39    any(
40        all(target_arch = "x86_64", target_os = "linux"),
41        all(target_arch = "x86_64", target_os = "windows"),
42        all(target_arch = "aarch64", target_os = "macos"),
43    )
44))]
45pub use blazen_embed_fastembed::{
46    FastEmbedError as EmbedError, FastEmbedModel as EmbedModel, FastEmbedOptions as EmbedOptions,
47    FastEmbedResponse as EmbedResponse,
48};
49
50// --- Default tract on every other target (no override feature set) ---
51#[cfg(all(
52    not(feature = "embed-fastembed"),
53    not(feature = "embed-tract"),
54    any(
55        target_family = "wasm",
56        target_env = "musl",
57        all(target_arch = "aarch64", target_os = "linux"),
58        all(target_arch = "aarch64", target_os = "windows"),
59        all(target_arch = "x86_64", target_os = "macos"),
60    )
61))]
62pub use blazen_embed_tract::{
63    TractEmbedModel as EmbedModel, TractError as EmbedError, TractOptions as EmbedOptions,
64    TractResponse as EmbedResponse,
65};