Sting.Similarity (Sting v0.1.0)

Copy Markdown View Source

Vector similarity and distance functions mirroring sentence_transformers.util.

Summary

Functions

Computes the cosine similarity matrix between two 1D or 2D tensors.

Computes the dot product similarity matrix between two 1D or 2D tensors.

Computes the Euclidean similarity matrix between two tensors. Returns negative Euclidean distance -dist(a[i], b[j]) so higher values indicate closer vectors.

Computes the Manhattan (L1) similarity matrix between two tensors. Returns negative Manhattan distance -dist(a[i], b[j]) so higher values indicate closer vectors.

Computes the absolute normalized angle distance between pairs of tensors x[i] and y[i].

Computes the pairwise cosine similarity cos_sim(a[i], b[i]).

Computes the pairwise dot product dot_score(a[i], b[i]).

Computes the pairwise Euclidean similarity -dist(a[i], b[i]).

Computes the pairwise Manhattan similarity -dist(a[i], b[i]).

Functions

cos_sim(a, b)

Computes the cosine similarity matrix between two 1D or 2D tensors.

Returns a matrix of shape {num_a, num_b} where result[i, j] is the cosine similarity between a[i] and b[j].

dot_score(a, b)

Computes the dot product similarity matrix between two 1D or 2D tensors.

Returns a matrix of shape {num_a, num_b} where result[i, j] is the dot product between a[i] and b[j].

euclidean_sim(a, b)

Computes the Euclidean similarity matrix between two tensors. Returns negative Euclidean distance -dist(a[i], b[j]) so higher values indicate closer vectors.

manhattan_sim(a, b)

Computes the Manhattan (L1) similarity matrix between two tensors. Returns negative Manhattan distance -dist(a[i], b[j]) so higher values indicate closer vectors.

pairwise_angle_sim(x, y)

Computes the absolute normalized angle distance between pairs of tensors x[i] and y[i].

Matches sentence_transformers.util.pairwise_angle_sim.

pairwise_cos_sim(a, b)

Computes the pairwise cosine similarity cos_sim(a[i], b[i]).

pairwise_dot_score(a, b)

Computes the pairwise dot product dot_score(a[i], b[i]).

pairwise_euclidean_sim(a, b)

Computes the pairwise Euclidean similarity -dist(a[i], b[i]).

pairwise_manhattan_sim(a, b)

Computes the pairwise Manhattan similarity -dist(a[i], b[i]).