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.
The ORT session is wrapped in Arc<Mutex<_>> because Session::run
requires &mut self. CPU-heavy inference is 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.
Downloads the ONNX INT8 model from HuggingFace Hub if not cached.
Sourcepub fn download_hf_file_pub(
model_id: &str,
filename: &str,
cache_dir: &Path,
) -> Result<PathBuf, String>
pub fn download_hf_file_pub( model_id: &str, filename: &str, cache_dir: &Path, ) -> Result<PathBuf, String>
Download a single file from HuggingFace using ureq (sync, for spawn_blocking).
Handles relative Location headers that ureq 2.x cannot resolve automatically.
Public alias for use by other inference modules (e.g. GLiNER NER engine).
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