Skip to main content

Crate lean_embed

Crate lean_embed 

Source
Expand description

A lean, provider-agnostic text-embeddings client.

One Client turns batches of text into vectors against any of four Providers - Voyage AI, OpenAI (or any OpenAI-compatible endpoint), Gemini, or Ollama (local, no key, offline) - behind a single embed call. EmbedKind selects query- vs document-side vectors where the provider supports it, and an optional output_dimension is requested and validated so a model drift can’t silently desync a fixed-width column.

The wire is reqwest on rustls + ring only - never OpenSSL or aws-lc - so the dependency tree stays small and cross-compiles cleanly (musl, aarch64). That lean stack is the reason this crate exists instead of a full agent/RAG framework: it is only the embeddings HTTP client, so a vector store, chunking, and retrieval stay in the caller where they belong.

§Example

use lean_embed::{Client, EmbedKind, Provider};

// Local Ollama - no key, offline.
let client = Client::builder(Provider::Ollama, "nomic-embed-text").build()?;
let vectors = client
    .embed(&["hello".into(), "world".into()], EmbedKind::Document)
    .await?;
assert_eq!(vectors.len(), 2);

// Hosted Voyage, pinned to 1024 dimensions (key from VOYAGE_API_KEY).
let voyage = Client::builder(Provider::Voyage, "voyage-3.5-lite")
    .output_dimension(1024)
    .max_batch(96)
    .build()?;
let q = voyage.embed(&["a question".into()], EmbedKind::Query).await?;

Structs§

Client
A configured embeddings client. Cheap to clone (reqwest::Client is an Arc internally); build it once and reuse it. Debug redacts the API key.
ClientBuilder
Build a Client. Start with Client::builder. Debug redacts the API key.

Enums§

EmbedKind
Whether a batch is stored documents or a search query. Voyage uses this for asymmetric retrieval (query- and document-side vectors differ, which retrieves better); Ollama ignores it.
Error
Everything that can go wrong producing embeddings. Each variant carries the provider that raised it so a caller can log or match without string-scraping.
Provider
Which embeddings backend a Client talks to.

Constants§

GEMINI_API_KEY_ENV
The environment variable Provider::Gemini reads when no key is passed.
OPENAI_API_KEY_ENV
The environment variable Provider::OpenAi reads when no key is passed.
VOYAGE_API_KEY_ENV
The environment variable Provider::Voyage reads when no key is passed.

Type Aliases§

TransportError
A transport/decoding error, kept opaque on purpose. The concrete HTTP backend (reqwest) is an implementation detail, so it is boxed rather than exposed in the public API - a reqwest major bump must not force a breaking release of this crate. The message and std::error::Error::source chain are preserved.