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::Clientis anArcinternally); build it once and reuse it.Debugredacts the API key. - Client
Builder - Build a
Client. Start withClient::builder.Debugredacts the API key.
Enums§
- Embed
Kind - 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
Clienttalks to.
Constants§
- GEMINI_
API_ KEY_ ENV - The environment variable
Provider::Geminireads when no key is passed. - OPENAI_
API_ KEY_ ENV - The environment variable
Provider::OpenAireads when no key is passed. - VOYAGE_
API_ KEY_ ENV - The environment variable
Provider::Voyagereads when no key is passed.
Type Aliases§
- Transport
Error - 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 andstd::error::Error::sourcechain are preserved.