Skip to main content

Embedder

Trait Embedder 

Source
pub trait Embedder:
    Send
    + Sync
    + Debug {
    // Required methods
    fn model(&self) -> &str;
    fn embed_documents<'a>(
        &'a self,
        texts: &'a [String],
    ) -> BoxFuture<'a, Result<Vec<Vec<f32>>, RagError>>;

    // Provided methods
    fn dimensions(&self) -> Option<usize> { ... }
    fn embed_query<'a>(
        &'a self,
        text: &'a str,
    ) -> BoxFuture<'a, Result<Vec<f32>, RagError>> { ... }
}
Expand description

Turns text into embedding vectors.

Required Methods§

Source

fn model(&self) -> &str

Model identifier (used to detect mixing incompatible embeddings).

Source

fn embed_documents<'a>( &'a self, texts: &'a [String], ) -> BoxFuture<'a, Result<Vec<Vec<f32>>, RagError>>

Embed documents for indexing. Returns one vector per input, in order.

Provided Methods§

Source

fn dimensions(&self) -> Option<usize>

Vector dimensionality, when known up front.

Source

fn embed_query<'a>( &'a self, text: &'a str, ) -> BoxFuture<'a, Result<Vec<f32>, RagError>>

Embed a search query. Defaults to Embedder::embed_documents on one text; override for models that need a query-specific prefix or endpoint.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§