[][src]Trait finalfusion::similarity::EmbeddingSimilarity

pub trait EmbeddingSimilarity {
    fn embedding_similarity_masked(
        &self,
        query: ArrayView1<f32>,
        limit: usize,
        skips: &HashSet<&str>
    ) -> Option<Vec<WordSimilarityResult>>;
fn embedding_similarity_by<F>(
        &self,
        query: ArrayView1<f32>,
        limit: usize,
        skip: &HashSet<&str>,
        similarity: F
    ) -> Option<Vec<WordSimilarityResult>>
    where
        F: FnMut(ArrayView2<f32>, ArrayView1<f32>) -> Array1<f32>
; fn embedding_similarity(
        &self,
        query: ArrayView1<f32>,
        limit: usize
    ) -> Option<Vec<WordSimilarityResult>> { ... } }

Trait for embedding similarity queries.

Required methods

fn embedding_similarity_masked(
    &self,
    query: ArrayView1<f32>,
    limit: usize,
    skips: &HashSet<&str>
) -> Option<Vec<WordSimilarityResult>>

Find words that are similar to the query embedding while skipping certain words.

The similarity between the query embedding and other embeddings is defined by the dot product of the embeddings. If the vectors are unit vectors (e.g. by virtue of calling normalize), this is the cosine similarity. At most, limit results are returned.

fn embedding_similarity_by<F>(
    &self,
    query: ArrayView1<f32>,
    limit: usize,
    skip: &HashSet<&str>,
    similarity: F
) -> Option<Vec<WordSimilarityResult>> where
    F: FnMut(ArrayView2<f32>, ArrayView1<f32>) -> Array1<f32>, 

Find words that are similar to the query embedding using the given similarity function.

The similarity function should return, given the embeddings matrix and the query vector a vector of similarity scores. At most, limit results are returned.

Loading content...

Provided methods

fn embedding_similarity(
    &self,
    query: ArrayView1<f32>,
    limit: usize
) -> Option<Vec<WordSimilarityResult>>

Find words that are similar to the query embedding.

The similarity between the query embedding and other embeddings is defined by the dot product of the embeddings. If the vectors are unit vectors (e.g. by virtue of calling normalize), this is the cosine similarity. At most, limit results are returned.

Loading content...

Implementors

impl<V, S> EmbeddingSimilarity for Embeddings<V, S> where
    V: Vocab,
    S: StorageView
[src]

Loading content...