Skip to main content

SimpleEmbedder

Struct SimpleEmbedder 

Source
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

Source

pub fn new(dimension: usize) -> Self

Create a new simple embedder with specified dimension.

Source

pub fn default_dimension() -> Self

Create with default dimension (256).

Trait Implementations§

Source§

impl Default for SimpleEmbedder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Embedder for SimpleEmbedder

Source§

fn embed(&self, text: &str) -> EmbeddingResult<Vec<f32>>

Embed a single text string.
Source§

fn dimension(&self) -> usize

Get the embedding dimension.
Source§

fn model_name(&self) -> &str

Get the model name/identifier.
Source§

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>

Compute cosine similarity between two vectors.
Source§

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)>>

Find top-k most similar texts.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.