mnem_rerank_providers/lib.rs
1//! # mnem-rerank-providers
2//!
3//! Cross-encoder reranker adapters for mnem. Ships Cohere, Voyage, and
4//! Jina out of the box; all three behind opt-in (on-by-default) cargo
5//! features.
6//!
7//! ## Scope
8//!
9//! Per , `mnem-core` defines a
10//! [`Reranker`][mnem_core::rerank::Reranker] trait
11//! and wires it into the retrieve
12//! pipeline as an optional post-fusion pass over the top-K. This crate
13//! provides the production adapters. The adapters all read `(query,
14//! candidate)` pairs jointly, which is what makes them useful for
15//! compositional paraphrase that defeats dense + sparse bi-encoder
16//! fusion ("father's sister" == "aunt").
17//!
18//! ## Invariants
19//!
20//! - **No tokio / no async.** All adapters are sync, built on top of
21//! [`ureq`] (rustls-backed). Matches `mnem-embed-providers`.
22//! - **No API keys in config / on disk.** The config stores the *name*
23//! of the env var holding the key (`api_key_env`). The key itself is
24//! read from the environment at adapter-construction time and is
25//! never persisted by this crate.
26//! - **`mnem-core` is not pulled onto an HTTP client.** `mnem-core`
27//! still has zero network / HTTP / tokio in its dep tree, preserving
28//! the WASM-embeddability promises.
29//!
30//! ## Usage
31//!
32//! ```no_run
33//! # use std::sync::Arc;
34//! # use mnem_rerank_providers::{open, ProviderConfig, CohereConfig};
35//! # use mnem_core::rerank::Reranker;
36//! # fn demo() -> Result<(), Box<dyn std::error::Error>> {
37//! let cfg = ProviderConfig::Cohere(CohereConfig {
38//! model: "rerank-v3.5".into(),
39//! ..Default::default()
40//! });
41//! let rr: Arc<dyn Reranker> = open(&cfg)?;
42//! let scores = rr.rerank("who is my father's sister", &["Eve is my aunt", "Bob is my cousin"])?;
43//! assert_eq!(scores.len(), 2);
44//! # Ok(()) }
45//! ```
46//!
47//!
48
49#![forbid(unsafe_code)]
50#![deny(missing_docs)]
51
52pub mod config;
53pub(crate) mod http;
54
55#[cfg(feature = "cohere")]
56pub mod cohere;
57#[cfg(feature = "jina")]
58pub mod jina;
59#[cfg(feature = "onnx")]
60pub mod onnx;
61#[cfg(feature = "voyage")]
62pub mod voyage;
63
64pub use config::{CohereConfig, JinaConfig, ProviderConfig, VoyageConfig, open};
65#[cfg(feature = "onnx")]
66pub use onnx::{OnnxReranker, RerankerModel};