pub struct EmbeddingEngine { /* private fields */ }Implementations§
Source§impl EmbeddingEngine
impl EmbeddingEngine
pub fn load(_model_dir: &Path) -> Result<EmbeddingEngine, Error>
Sourcepub fn load_default() -> Result<EmbeddingEngine, Error>
pub fn load_default() -> Result<EmbeddingEngine, Error>
Load from default model directory (~/.lean-ctx/models/).
Sourcepub fn embed(&self, text: &str) -> Result<Vec<f32>, Error>
pub fn embed(&self, text: &str) -> Result<Vec<f32>, Error>
Generate an embedding vector for a single text (document/code).
Sourcepub fn embed_query(&self, query: &str) -> Result<Vec<f32>, Error>
pub fn embed_query(&self, query: &str) -> Result<Vec<f32>, Error>
Generate an embedding vector for a query string. Applies query-specific prefix if the model requires one.
Sourcepub fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, Error>
pub fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, Error>
Generate embedding vectors for multiple texts using true batched ONNX
inference. Sends a single [batch, max_seq_len] tensor through the model
instead of batch separate calls — up to 50× faster on CPU for typical
batch sizes (64–128) by leveraging matrix-matrix instead of matrix-vector
operations inside the transformer.
pub fn dimensions(&self) -> usize
pub fn model_id(&self) -> &EmbeddingModel
pub fn model_name(&self) -> &str
Sourcepub fn model_directory() -> PathBuf
pub fn model_directory() -> PathBuf
Resolve the model directory (respects LEAN_CTX_MODELS_DIR env).
Sourcepub fn is_available() -> bool
pub fn is_available() -> bool
Check if the model files are present and loadable.
Sourcepub fn ensure_downloaded() -> Result<(), Error>
pub fn ensure_downloaded() -> Result<(), Error>
Ensure the selected model’s files exist on disk, downloading them from
HuggingFace if absent. Pure network/file IO — this never initializes the
ONNX Runtime, so a failed bootstrap costs nothing in ORT teardown (the
caller only loads ORT via [shared_engine] once the files are present).
After Ok, is_available is guaranteed true; on a
warm cache it short-circuits without touching the network.
The explicit index-build path uses this to cold-start a fresh machine.
is_available() alone is only a file check, so the build path must call
this to actually trigger the download instead of bailing (#545).
Auto Trait Implementations§
impl Forget for EmbeddingEngine
impl Freeze for EmbeddingEngine
impl Move for EmbeddingEngine
impl RefUnwindSafe for EmbeddingEngine
impl Send for EmbeddingEngine
impl Sync for EmbeddingEnginewhere
RawVecInner: Sync,
impl Unpin for EmbeddingEngine
impl UnsafeUnpin for EmbeddingEnginewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
&'static [(&'static str, &'static str)]: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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