Skip to main content

Crate mnem_embed_providers

Crate mnem_embed_providers 

Source
Expand description

§mnem-embed-providers

Embedding-provider adapters for mnem. Ships OpenAI and Ollama out of the box; both behind opt-in (on-by-default) cargo features.

§Scope

This crate turns a user-configured provider into a concrete Embedder that the mnem CLI, MCP server, and Python bindings use to (a) auto-embed node summaries on write and (b) auto-embed query strings on retrieve. That is the piece that makes mnem retrieve --text ... semantic-hybrid by default once a provider is configured.

§Invariants

  • No tokio / no async. All adapters are sync, built on top of ureq (rustls-backed). Mnem cannot afford to drag an async runtime into the CLI or the MCP server.
  • No API keys in config / on disk. The config stores the name of the env var holding the key (api_key_env). The key itself is read from the environment at adapter-construction time and is never persisted by this crate.
  • Deterministic outputs. Adapters only wrap providers whose embed(text) is a pure function of (provider, model, text). Randomised projections would break mnem’s agent-replay guarantee.
  • mnem-core is not a dependency of the HTTP layer. mnem-core still has zero network / HTTP / tokio in its dep tree, preserving the WASM-embeddability promises.

§Usage

let cfg = ProviderConfig::Openai(OpenAiConfig {
    model: "text-embedding-3-small".into(),
    ..Default::default()
});
let embedder = open(&cfg)?;
let v = embedder.embed("Alice lives in Berlin")?;
assert_eq!(v.len(), embedder.dim() as usize);

Re-exports§

pub use config::OllamaConfig;
pub use config::OnnxConfig;
pub use config::OpenAiConfig;
pub use config::ProviderConfig;
pub use config::open;
pub use embedder::Embedder;
pub use embedder::to_embedding;
pub use error::EmbedError;
pub use manifest::DEFAULT_LATENCY_BUDGET_MS;
pub use manifest::EmbedderManifest;
pub use manifest::derive_max_cooccurrence_ms;
pub use manifest::derive_max_knn_ingest_per_node_ms;
pub use mock::MockEmbedder;

Modules§

config
ProviderConfig and the open factory.
embedder
The Embedder trait and the to_embedding conversion helper.
error
Error type for embedding-provider adapters.
manifest
Embedder manifest: self-describing metadata each provider publishes so downstream code never has to guess a semantic-similarity floor.
mock
A deterministic Embedder for tests. Available iff the mock feature is enabled OR the crate is being compiled as a test target.
ollama
Ollama Embeddings adapter.
openai
OpenAI Embeddings API adapter.