Skip to main content

Embedder

Trait Embedder 

Source
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§

Source

fn identity(&self) -> &ModelIdentity

Source

fn supports(&self, modality: Modality) -> bool

Source

fn embed_batch( &self, requests: &[EmbeddingRequest<'_>], ) -> Result<Vec<Embedding>>

Provided Methods§

Source

fn dimension(&self) -> Dimension

Source

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.

Source

fn unavailable_reason(&self, _modality: Modality) -> Option<String>

Why a configured modality is unavailable, including recovery instructions.

Source

fn embed( &self, input: ResourceInput<'_>, task: EmbeddingTask, ) -> Result<Embedding>

Source

fn embed_text(&self, text: &str, task: EmbeddingTask) -> Result<Embedding>

Source

fn embed_query(&self, query: &str) -> Result<Embedding>

Retrieval convenience adapter.

Source

fn embed_resources( &self, inputs: &[ResourceInput<'_>], ) -> Result<Vec<Embedding>>

Retrieval convenience adapter. Text titles are preserved.

Source

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".

Implementations on Foreign Types§

Source§

impl<E: Embedder + ?Sized> Embedder for Arc<E>

Source§

fn identity(&self) -> &ModelIdentity

Source§

fn input_identity(&self, modality: Modality) -> Result<&str>

Source§

fn unavailable_reason(&self, modality: Modality) -> Option<String>

Source§

fn supports(&self, modality: Modality) -> bool

Source§

fn embed_batch( &self, requests: &[EmbeddingRequest<'_>], ) -> Result<Vec<Embedding>>

Source§

fn dimension(&self) -> Dimension

Source§

fn embed( &self, input: ResourceInput<'_>, task: EmbeddingTask, ) -> Result<Embedding>

Source§

fn embed_text(&self, text: &str, task: EmbeddingTask) -> Result<Embedding>

Source§

fn embed_query(&self, query: &str) -> Result<Embedding>

Source§

fn embed_resources( &self, inputs: &[ResourceInput<'_>], ) -> Result<Vec<Embedding>>

Source§

fn embed_text_document( &self, title: Option<&str>, text: &str, ) -> Result<Embedding>

Source§

impl<E: Embedder + ?Sized> Embedder for Box<E>

Source§

fn identity(&self) -> &ModelIdentity

Source§

fn input_identity(&self, modality: Modality) -> Result<&str>

Source§

fn unavailable_reason(&self, modality: Modality) -> Option<String>

Source§

fn supports(&self, modality: Modality) -> bool

Source§

fn embed_batch( &self, requests: &[EmbeddingRequest<'_>], ) -> Result<Vec<Embedding>>

Source§

fn dimension(&self) -> Dimension

Source§

fn embed( &self, input: ResourceInput<'_>, task: EmbeddingTask, ) -> Result<Embedding>

Source§

fn embed_text(&self, text: &str, task: EmbeddingTask) -> Result<Embedding>

Source§

fn embed_query(&self, query: &str) -> Result<Embedding>

Source§

fn embed_resources( &self, inputs: &[ResourceInput<'_>], ) -> Result<Vec<Embedding>>

Source§

fn embed_text_document( &self, title: Option<&str>, text: &str, ) -> Result<Embedding>

Implementors§