Skip to main content

kiromi_ai_embed_onnx/
lib.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2//! `kiromi-ai-embed-onnx` — ONNX-backed `Embedder` plugin for kiromi-ai-memory.
3//!
4//! See the mdBook chapter [Writing an Embedder][docs] for the full extender
5//! guide; this crate is the reference implementation.
6//!
7//! [docs]: https://kiromi.github.io/kiromi-mem/extending/embedders.html
8//!
9//! Slice 1 ships three models: `multilingual-e5-small` (default, 384d),
10//! `multilingual-e5-large` (1024d), and `bge-m3` (1024d). All three are
11//! downloaded on first use and cached locally; honour
12//! `KIROMI_AI_MODEL_CACHE_DIR` to pick the cache root.
13//!
14//! Programmatic callers construct directly:
15//!
16//! ```no_run
17//! # async fn demo() -> kiromi_ai_memory::Result<()> {
18//! let e = kiromi_ai_embed_onnx::multilingual_e5_small()?;
19//! # let _ = e;
20//! # Ok(()) }
21//! ```
22//!
23//! Config-driven callers register the family and build through the registry:
24//!
25//! ```no_run
26//! # async fn demo() -> kiromi_ai_memory::Result<()> {
27//! use kiromi_ai_memory::EmbedderRegistry;
28//! let mut registry = EmbedderRegistry::empty();
29//! kiromi_ai_embed_onnx::register(&mut registry);
30//! let _e = registry
31//!     .build("onnx", serde_json::json!({ "model": "multilingual-e5-small" }))
32//!     .await?;
33//! # Ok(()) }
34//! ```
35//!
36//! Asymmetric-prefixing convention: every E5/BGE/GTE/Jina-family constructor
37//! MUST honour `EmbedRole` the same way — `"passage: "` for `Document`,
38//! `"query: "` for `Query`. Models in symmetric families (BGE-M3 in our
39//! slice-1 menu, SBERT) MUST ignore `role`. See spec § 12.12 and the
40//! conformance harness in `kiromi-ai-test-suite`.
41// `deny` rather than `forbid` so test modules can opt in to a single
42// `unsafe { std::env::set_var(...) }` call required by the edition-2024
43// stdlib API. Production code stays unsafe-free.
44#![deny(unsafe_code)]
45#![warn(missing_docs)]
46
47mod choice;
48mod config;
49mod embedder;
50mod registry;
51
52pub use choice::ModelChoice;
53pub use config::OnnxConfig;
54pub use embedder::{
55    MultilingualE5Small, OnnxEmbedder, bge_m3, from_choice, from_config, multilingual_e5_large,
56    multilingual_e5_small,
57};
58pub use registry::{FAMILY, register};