pub trait TextEmbedder: Send + Sync {
// Required method
fn embed_texts(
&self,
texts: &[String],
mode: EmbedMode,
) -> Result<Vec<Vec<f32>>>;
// Provided methods
fn embed_text(&self, text: &str, mode: EmbedMode) -> Result<Vec<f32>> { ... }
fn model_id(&self) -> Option<&str> { ... }
fn dimension(&self) -> Option<usize> { ... }
fn capabilities(&self) -> TextEmbedderCapabilities { ... }
}Expand description
Minimal interface for “text → dense vector” encoders (bi-encoder style).
This covers the common “sentence embedding” family: one vector per input string.
Important: there are multiple kinds of “embeddings” used in retrieval:
- Dense sentence embeddings (this trait): one (d)-dim vector per string.
- Dense token embeddings / late interaction (e.g. ColBERT): many vectors per string.
- Sparse embeddings (e.g. SPLADE): a weighted sparse vector over vocabulary IDs.
- Binary / quantized embeddings: compressed representations for ANN speed/memory.
We start with the dense-sentence contract because it’s the smallest stable surface that many parts of the workspace can share (iksh, chunking, retrieval prototypes).
Required Methods§
Provided Methods§
Sourcefn embed_text(&self, text: &str, mode: EmbedMode) -> Result<Vec<f32>>
fn embed_text(&self, text: &str, mode: EmbedMode) -> Result<Vec<f32>>
Convenience: embed a single text, avoiding the &[s.to_string()][0].clone() boilerplate.
Sourcefn dimension(&self) -> Option<usize>
fn dimension(&self) -> Option<usize>
Optional: embedding dimension as returned by this embedder.
Notes:
- If you wrap an embedder with
apply_output_dim(Some(d)), this should becomeSome(d). - Many remote backends can’t report this without a request; returning
Noneis fine.
Sourcefn capabilities(&self) -> TextEmbedderCapabilities
fn capabilities(&self) -> TextEmbedderCapabilities
Optional: backend capability declaration.
This exists to design around “silent drift” failure modes:
- prompt applied client-side vs server-side vs internally
- whether
EmbedModeis actually used - whether outputs are L2-normalized
Backends that don’t override this should be treated as “unknown” by callers.