pub struct SimpleEmbedder { /* private fields */ }Expand description
Simple hash-based embedder.
Creates embeddings by hashing words into a fixed-dimension space. Uses multiple hash functions for better distribution.
§Example
use phago_embeddings::SimpleEmbedder;
use phago_embeddings::Embedder;
let embedder = SimpleEmbedder::new(128);
let vec = embedder.embed("hello world").unwrap();
assert_eq!(vec.len(), 128);Implementations§
Source§impl SimpleEmbedder
impl SimpleEmbedder
Sourcepub fn default_dimension() -> Self
pub fn default_dimension() -> Self
Create with default dimension (256).
Trait Implementations§
Source§impl Default for SimpleEmbedder
impl Default for SimpleEmbedder
Source§impl Embedder for SimpleEmbedder
impl Embedder for SimpleEmbedder
Source§fn model_name(&self) -> &str
fn model_name(&self) -> &str
Get the model name/identifier.
Source§fn embed_batch(&self, texts: &[&str]) -> EmbeddingResult<Vec<Vec<f32>>>
fn embed_batch(&self, texts: &[&str]) -> EmbeddingResult<Vec<Vec<f32>>>
Embed multiple texts in a batch (more efficient).
Source§fn similarity(&self, a: &[f32], b: &[f32]) -> EmbeddingResult<f32>
fn similarity(&self, a: &[f32], b: &[f32]) -> EmbeddingResult<f32>
Compute cosine similarity between two vectors.
Source§fn most_similar<'a>(
&self,
query: &str,
candidates: &[&'a str],
) -> EmbeddingResult<Option<(&'a str, f32)>>
fn most_similar<'a>( &self, query: &str, candidates: &[&'a str], ) -> EmbeddingResult<Option<(&'a str, f32)>>
Find the most similar text from a list.
Source§fn top_k_similar<'a>(
&self,
query: &str,
candidates: &[&'a str],
k: usize,
) -> EmbeddingResult<Vec<(&'a str, f32)>>
fn top_k_similar<'a>( &self, query: &str, candidates: &[&'a str], k: usize, ) -> EmbeddingResult<Vec<(&'a str, f32)>>
Find top-k most similar texts.
Auto Trait Implementations§
impl Freeze for SimpleEmbedder
impl RefUnwindSafe for SimpleEmbedder
impl Send for SimpleEmbedder
impl Sync for SimpleEmbedder
impl Unpin for SimpleEmbedder
impl UnwindSafe for SimpleEmbedder
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