pub trait Embedder: Send + Sync {
// Required methods
fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>;
fn dimension(&self) -> usize;
fn is_available(&self) -> bool;
fn backend_name(&self) -> &'static str;
// Provided methods
fn embed(&self, text: &str) -> Result<Vec<f32>> { ... }
fn embed_query(&self, query: &str) -> Result<Vec<f32>> { ... }
fn cache_namespace(&self) -> String { ... }
fn preferred_max_batch_texts(&self) -> usize { ... }
}Expand description
Trait for text embedding providers.
Implementations:
HttpEmbedder— llama-server/v1/embeddingsendpointStubEmbedder— hash-based pseudo-embeddings (for testing)
Required Methods§
Sourcefn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>
fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>
Embed a batch of texts into f32 vectors.
Returns one vector per input text. All vectors have the same dimensionality.
Sourcefn is_available(&self) -> bool
fn is_available(&self) -> bool
Whether this embedder is available (model loaded, server reachable).
Sourcefn backend_name(&self) -> &'static str
fn backend_name(&self) -> &'static str
Name of this embedder backend.
Provided Methods§
Sourcefn cache_namespace(&self) -> String
fn cache_namespace(&self) -> String
Identity used to namespace the persistent embedding cache.
Vectors for identical text differ across models, quantization, and endpoints, so the cache key must carry this — switching models must never serve stale vectors. Default is the backend name.
Sourcefn preferred_max_batch_texts(&self) -> usize
fn preferred_max_batch_texts(&self) -> usize
Preferred batch granularity in TEXTS for batch write paths.
The write path’s char-chunking exists for HTTP token limits; local
engines have no such limit and want bigger batches so session
pools fan out efficiently (4-7 texts per call starves each shard).
usize::MAX = char-chunking only (the HTTP shape).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".