pub trait Embedder: Send + Sync {
// Required methods
fn embed_sync(&self, text: &str) -> Result<Vec<f32>, SearchError>;
fn dimension(&self) -> usize;
fn id(&self) -> &str;
fn is_semantic(&self) -> bool;
fn category(&self) -> ModelCategory;
// Provided methods
fn embed_batch_sync(
&self,
texts: &[&str],
) -> Result<Vec<Vec<f32>>, SearchError> { ... }
fn model_name(&self) -> &str { ... }
fn is_ready(&self) -> bool { ... }
fn tier(&self) -> ModelTier { ... }
fn supports_mrl(&self) -> bool { ... }
}Expand description
Synchronous embedding interface for host projects that call embedders from non-async contexts.
Implement this trait for embedders whose embed operations are inherently
synchronous (e.g., hash embedders, CPU-only ONNX inference). The companion
SyncEmbedderAdapter wraps any SyncEmbed implementor into a full
async Embedder, suitable for use anywhere frankensearch expects one.
§Example
use frankensearch_core::traits::{SyncEmbed, SyncEmbedderAdapter, Embedder};
struct MyHashEmbedder { dim: usize }
impl SyncEmbed for MyHashEmbedder {
fn embed_sync(&self, text: &str) -> SearchResult<Vec<f32>> { /* ... */ }
fn dimension(&self) -> usize { self.dim }
fn id(&self) -> &str { "my-hash" }
fn model_name(&self) -> &str { "My Hash Embedder" }
fn is_semantic(&self) -> bool { false }
fn category(&self) -> ModelCategory { ModelCategory::HashEmbedder }
}
// Use it as a full async Embedder:
let adapted: Box<dyn Embedder> = Box::new(SyncEmbedderAdapter(MyHashEmbedder { dim: 256 }));Required Methods§
Sourcefn embed_sync(&self, text: &str) -> Result<Vec<f32>, SearchError>
fn embed_sync(&self, text: &str) -> Result<Vec<f32>, SearchError>
Synchronously embed a single text into a vector.
§Errors
Returns SearchError when embedding fails (for example model load,
inference, or input validation failures).
Sourcefn is_semantic(&self) -> bool
fn is_semantic(&self) -> bool
Whether this embedder produces semantically meaningful vectors.
Sourcefn category(&self) -> ModelCategory
fn category(&self) -> ModelCategory
The speed/quality category of this embedder.
Provided Methods§
Sourcefn embed_batch_sync(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, SearchError>
fn embed_batch_sync(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, SearchError>
Synchronously embed a batch of texts.
Default implementation calls embed_sync for each text.
§Errors
Returns the first SearchError encountered while embedding any item
in the batch.
Sourcefn model_name(&self) -> &str
fn model_name(&self) -> &str
Human-readable model name.
Sourcefn supports_mrl(&self) -> bool
fn supports_mrl(&self) -> bool
Whether this model supports Matryoshka Representation Learning.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl SyncEmbed for DaemonFallbackEmbedder
impl SyncEmbed for FastEmbedder
semantic only.