Skip to main content

Module metric

Module metric 

Source
Expand description

Distance metrics and the distance computations built on them.

Enums§

Metric
How the distance between two vectors is measured. as_str and FromStr convert it to and from the name stored in an index’s info/metric.

Functions§

calculate_distances
Scores every row of embeddings against the query q, as L2 distances or, for IP, inner products. Set is_normalized only if every row is unit-length, which lets L2 skip computing the rows’ norms. L2 distance for unit-length rows = sqrt(1 − 2·e·q + ‖q‖²).
negative_squared_distances
Computes the squared L2 distance between every row of a and every row of b, negated so a higher score is closer, as an (a.nrows(), b.nrows()) matrix. Squared distance = ‖a‖² − 2·a·b + ‖b‖².