pub struct EmbedderRegistry { /* private fields */ }Expand description
Thread-safe registry that holds the active embedding backends.
On creation the TF-IDF slot is empty and the IdentityEmbedder is used as
a deterministic fall-back. Once enough documents have been seen (or
EmbedderRegistry::fit_tfidf is called explicitly) the TF-IDF embedder
is installed and used for all subsequent requests.
Implementations§
Source§impl EmbedderRegistry
impl EmbedderRegistry
Sourcepub fn new(default_dim: usize) -> Self
pub fn new(default_dim: usize) -> Self
Create a new registry.
default_dim controls the dimensionality of the IdentityEmbedder
fallback and is also used as max_features when fitting TF-IDF.
Sourcepub fn embed_texts(&self, texts: &[String]) -> Vec<Vec<f32>>
pub fn embed_texts(&self, texts: &[String]) -> Vec<Vec<f32>>
Embed a slice of text strings, returning one dense vector per input.
Uses the TF-IDF backend when it has been fitted; falls back to
IdentityEmbedder otherwise. Texts that fail to embed are silently
replaced with a zero vector of the appropriate dimension.
Sourcepub fn fit_tfidf(&self, corpus: &[String])
pub fn fit_tfidf(&self, corpus: &[String])
Fit the TF-IDF backend from corpus.
After this call embed_texts will use TF-IDF for
all subsequent requests. Subsequent calls replace the existing model.
Sourcepub fn embedding_dim(&self) -> usize
pub fn embedding_dim(&self) -> usize
Return the current embedding dimension.
Returns the TF-IDF vocabulary size when a fitted model is present,
otherwise the configured default_dim.
Sourcepub fn encode_base64(embedding: &[f32]) -> String
pub fn encode_base64(embedding: &[f32]) -> String
Encode an embedding vector as a hex string (pure Rust, no external deps).
Each f32 is serialised as four bytes in little-endian order, with each
byte represented as two lowercase hex digits. The result is therefore
8 * embedding.len() characters long.
Auto Trait Implementations§
impl !Freeze for EmbedderRegistry
impl RefUnwindSafe for EmbedderRegistry
impl Send for EmbedderRegistry
impl Sync for EmbedderRegistry
impl Unpin for EmbedderRegistry
impl UnsafeUnpin for EmbedderRegistry
impl UnwindSafe for EmbedderRegistry
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