pub struct OnnxEmbeddingProvider { /* private fields */ }Expand description
ONNX Runtime embedding provider.
Uses all-MiniLM-L6-v2 (384 dimensions) for semantic text embeddings.
When the ONNX runtime is not available (no onnx-embeddings feature or
missing model file), falls back to a position-aware token-hashing approach
that is architecturally compatible with real inference.
Implementations§
Source§impl OnnxEmbeddingProvider
impl OnnxEmbeddingProvider
Sourcepub const DEFAULT_DIMS: usize = 384
pub const DEFAULT_DIMS: usize = 384
Default output dimensionality (all-MiniLM-L6-v2).
Sourcepub const DEFAULT_MAX_TOKENS: usize = 128
pub const DEFAULT_MAX_TOKENS: usize = 128
Default maximum input tokens for code snippets.
Sourcepub const MODEL_NAME: &'static str = "all-MiniLM-L6-v2"
pub const MODEL_NAME: &'static str = "all-MiniLM-L6-v2"
Model identifier.
Sourcepub fn new(model_path: impl Into<PathBuf>) -> Self
pub fn new(model_path: impl Into<PathBuf>) -> Self
Create a new ONNX provider pointing at the given model path.
If the model file does not exist or the onnx-embeddings feature is
disabled, the provider transparently falls back to token-hashing.
Sourcepub fn with_config(
model_path: impl Into<PathBuf>,
dimensions: usize,
max_tokens: usize,
) -> Self
pub fn with_config( model_path: impl Into<PathBuf>, dimensions: usize, max_tokens: usize, ) -> Self
Create a provider with custom dimensions and max tokens.
Sourcepub fn is_runtime_available(&self) -> bool
pub fn is_runtime_available(&self) -> bool
Whether the real ONNX runtime is active (vs. fallback).
Sourcepub fn model_path(&self) -> &PathBuf
pub fn model_path(&self) -> &PathBuf
Path to the configured model file.
Sourcepub fn max_tokens(&self) -> usize
pub fn max_tokens(&self) -> usize
Maximum input token count.
Trait Implementations§
Source§impl EmbeddingProvider for OnnxEmbeddingProvider
impl EmbeddingProvider for OnnxEmbeddingProvider
Source§fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn dimensions(&self) -> usize
fn dimensions(&self) -> usize
Source§fn model_name(&self) -> &str
fn model_name(&self) -> &str
Source§fn embed_query<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embed_query<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn warm<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn warm<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
embed so the
model graph, runtime thread pool, and allocator are hot before the first
real call. Best-effort — errors are swallowed (a backend with nothing to
warm, like the Mock, just pays one cheap call). Intended to be called
once at daemon startup so the first conversation turn doesn’t pay the
model’s first-inference cost (ADR-058 Phase 5.3; mirrors the 6.2 STT
pre-warm).Auto Trait Implementations§
impl Freeze for OnnxEmbeddingProvider
impl RefUnwindSafe for OnnxEmbeddingProvider
impl Send for OnnxEmbeddingProvider
impl Sync for OnnxEmbeddingProvider
impl Unpin for OnnxEmbeddingProvider
impl UnsafeUnpin for OnnxEmbeddingProvider
impl UnwindSafe for OnnxEmbeddingProvider
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