pub struct EmbeddingEngine { /* private fields */ }Implementations§
Source§impl EmbeddingEngine
impl EmbeddingEngine
Sourcepub fn load(model_dir: &Path) -> Result<Self>
pub fn load(model_dir: &Path) -> Result<Self>
Load embedding model and vocabulary from a directory. Downloads model automatically from HuggingFace if not present.
Sourcepub fn load_model(base_dir: &Path, model_id: EmbeddingModel) -> Result<Self>
pub fn load_model(base_dir: &Path, model_id: EmbeddingModel) -> Result<Self>
Load a specific embedding model from a directory.
Sourcepub fn load_default() -> Result<Self>
pub fn load_default() -> Result<Self>
Load from default model directory (~/.lean-ctx/models/).
Sourcepub fn embed(&self, text: &str) -> Result<Vec<f32>>
pub fn embed(&self, text: &str) -> Result<Vec<f32>>
Generate an embedding vector for a single text (document/code).
Sourcepub fn embed_query(&self, query: &str) -> Result<Vec<f32>>
pub fn embed_query(&self, query: &str) -> Result<Vec<f32>>
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>>>
pub fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>
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<()>
pub fn ensure_downloaded() -> Result<()>
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 !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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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