pub struct EmbeddingService { /* private fields */ }Expand description
Embedding service with Candle inference (no internal cache — use CachedProvider wrapper).
Implementations§
Source§impl EmbeddingService
impl EmbeddingService
Sourcepub fn new(
model_dir: &Path,
batch_size: usize,
) -> Result<EmbeddingService, CodememError>
pub fn new( model_dir: &Path, batch_size: usize, ) -> Result<EmbeddingService, 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.
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 using a true batched forward pass.
Tokenizes all texts, pads to the longest sequence in each chunk, runs a
single forward pass per chunk of up to batch_size texts, then performs
mean pooling and L2 normalization on the batched output.
Trait Implementations§
Source§impl EmbeddingProvider for EmbeddingService
impl EmbeddingProvider for EmbeddingService
Source§fn dimensions(&self) -> usize
fn dimensions(&self) -> usize
Source§fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, CodememError>
fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, CodememError>
Source§fn cache_stats(&self) -> (usize, usize)
fn cache_stats(&self) -> (usize, usize)
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
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