pub struct EmbeddingEngine { /* private fields */ }Expand description
The main embedding engine for generating vector embeddings.
This struct is thread-safe and can be shared across async tasks.
Internal fields use Arc so CPU-heavy inference can be offloaded
to blocking threads via tokio::task::spawn_blocking.
Implementations§
Source§impl EmbeddingEngine
impl EmbeddingEngine
Sourcepub async fn new(config: ModelConfig) -> Result<Self>
pub async fn new(config: ModelConfig) -> Result<Self>
Create a new embedding engine with the given configuration.
This will download the model from HuggingFace Hub if not cached.
Sourcepub fn model(&self) -> EmbeddingModel
pub fn model(&self) -> EmbeddingModel
Get the model being used.
Sourcepub async fn embed_query(&self, text: &str) -> Result<Vec<f32>>
pub async fn embed_query(&self, text: &str) -> Result<Vec<f32>>
Embed a single query text.
For models like E5, this automatically applies the query prefix.
Sourcepub async fn embed_queries(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>
pub async fn embed_queries(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>
Embed multiple query texts.
For models like E5, this automatically applies the query prefix.
Sourcepub async fn embed_document(&self, text: &str) -> Result<Vec<f32>>
pub async fn embed_document(&self, text: &str) -> Result<Vec<f32>>
Embed a single document/passage.
For models like E5, this automatically applies the document prefix.
Sourcepub async fn embed_documents(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>
pub async fn embed_documents(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>
Embed multiple documents/passages.
For models like E5, this automatically applies the document prefix.
Sourcepub async fn embed_raw(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>
pub async fn embed_raw(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>
Embed texts without any prefix (raw embedding).
Sourcepub fn estimate_time_ms(&self, text_count: usize, avg_text_len: usize) -> f64
pub fn estimate_time_ms(&self, text_count: usize, avg_text_len: usize) -> f64
Estimate the time to embed a batch of texts (in milliseconds).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EmbeddingEngine
impl !RefUnwindSafe for EmbeddingEngine
impl Send for EmbeddingEngine
impl Sync for EmbeddingEngine
impl Unpin for EmbeddingEngine
impl UnsafeUnpin for EmbeddingEngine
impl !UnwindSafe for EmbeddingEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more