pub trait Embedder: Send + Sync {
// Required methods
fn identity(&self) -> &ModelIdentity;
fn supports(&self, modality: Modality) -> bool;
fn embed_batch(
&self,
requests: &[EmbeddingRequest<'_>],
) -> Result<Vec<Embedding>>;
// Provided methods
fn dimension(&self) -> Dimension { ... }
fn input_identity(&self, _modality: Modality) -> Result<&str> { ... }
fn unavailable_reason(&self, _modality: Modality) -> Option<String> { ... }
fn embed(
&self,
input: ResourceInput<'_>,
task: EmbeddingTask,
) -> Result<Embedding> { ... }
fn embed_text(&self, text: &str, task: EmbeddingTask) -> Result<Embedding> { ... }
fn embed_query(&self, query: &str) -> Result<Embedding> { ... }
fn embed_resources(
&self,
inputs: &[ResourceInput<'_>],
) -> Result<Vec<Embedding>> { ... }
fn embed_text_document(
&self,
title: Option<&str>,
text: &str,
) -> Result<Embedding> { ... }
}Expand description
Synchronous, task-aware local embedding interface. Successful batches return one result per request, in input order. Async callers can use their executor’s blocking pool.
Required Methods§
fn identity(&self) -> &ModelIdentity
fn supports(&self, modality: Modality) -> bool
fn embed_batch( &self, requests: &[EmbeddingRequest<'_>], ) -> Result<Vec<Embedding>>
Provided Methods§
fn dimension(&self) -> Dimension
Sourcefn input_identity(&self, _modality: Modality) -> Result<&str>
fn input_identity(&self, _modality: Modality) -> Result<&str>
Extra modality-specific weights/preparation identity, included in that input’s cache key without invalidating other modalities’ vectors. Resolve this before cache admission, even if inference is unnecessary. Backends may lazily read model assets here; failed preparation is retryable. Once successful, the identity must remain stable until the model is reloaded.
Why a configured modality is unavailable, including recovery instructions.
fn embed( &self, input: ResourceInput<'_>, task: EmbeddingTask, ) -> Result<Embedding>
fn embed_text(&self, text: &str, task: EmbeddingTask) -> Result<Embedding>
Sourcefn embed_query(&self, query: &str) -> Result<Embedding>
fn embed_query(&self, query: &str) -> Result<Embedding>
Retrieval convenience adapter.
Sourcefn embed_resources(
&self,
inputs: &[ResourceInput<'_>],
) -> Result<Vec<Embedding>>
fn embed_resources( &self, inputs: &[ResourceInput<'_>], ) -> Result<Vec<Embedding>>
Retrieval convenience adapter. Text titles are preserved.
fn embed_text_document( &self, title: Option<&str>, text: &str, ) -> Result<Embedding>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".