pub struct EmbeddingService { /* private fields */ }Expand description
Embedding service with Candle inference and LRU caching.
Implementations§
Source§impl EmbeddingService
impl EmbeddingService
Sourcepub fn new(model_dir: &Path) -> Result<Self, CodememError>
pub fn new(model_dir: &Path) -> Result<Self, CodememError>
Create a new embedding service, loading model from the given directory.
Expects model.safetensors, config.json, and tokenizer.json in the directory.
Sourcepub fn default_model_dir() -> PathBuf
pub fn default_model_dir() -> PathBuf
Get the default model directory path (~/.codemem/models/{MODEL_NAME}).
Sourcepub fn download_model(dest_dir: &Path) -> Result<PathBuf, CodememError>
pub fn download_model(dest_dir: &Path) -> Result<PathBuf, CodememError>
Download the model from HuggingFace Hub to the given directory. Returns the directory path. No-ops if model already exists.
Sourcepub fn embed(&self, text: &str) -> Result<Vec<f32>, CodememError>
pub fn embed(&self, text: &str) -> Result<Vec<f32>, CodememError>
Embed a single text string. Returns a 768-dim L2-normalized vector. Uses LRU cache for repeated queries.
Sourcepub fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, CodememError>
pub fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, CodememError>
Embed a batch of texts with cache-aware batching.
Checks the LRU cache first and only runs the model on uncached texts, using a true batched forward pass (single GPU/CPU kernel launch per chunk).
Sourcepub fn cache_stats(&self) -> (usize, usize)
pub fn cache_stats(&self) -> (usize, usize)
Get cache statistics: (current_size, capacity).
Trait Implementations§
Source§impl EmbeddingProvider for EmbeddingService
impl EmbeddingProvider for EmbeddingService
Source§fn dimensions(&self) -> usize
fn dimensions(&self) -> usize
Embedding vector dimensions.
Source§fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, CodememError>
fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, CodememError>
Embed a batch of texts (default: sequential).
Source§fn cache_stats(&self) -> (usize, usize)
fn cache_stats(&self) -> (usize, usize)
Cache statistics: (current_size, capacity). Returns (0, 0) if no cache.
Auto Trait Implementations§
impl !Freeze for EmbeddingService
impl RefUnwindSafe for EmbeddingService
impl Send for EmbeddingService
impl Sync for EmbeddingService
impl Unpin for EmbeddingService
impl UnsafeUnpin for EmbeddingService
impl UnwindSafe for EmbeddingService
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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