MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / dist_to_sim

Function dist_to_sim

nodedb-vector/src/multivec/scoring.rs:27–33  ·  view source on GitHub ↗

Convert a distance value produced by `scalar_distance` into a similarity score where higher is better. | Metric | Conversion | |----------------|---------------------| | L2 | `−distance` | | Cosine | `1 − distance` | | InnerProduct | `−distance` (scalar_distance returns neg-IP) | | All others | `−distance` |

(d: f32, metric: DistanceMetric)

Source from the content-addressed store, hash-verified

25/// | InnerProduct | `−distance` (scalar_distance returns neg-IP) |
26/// | All others | `−distance` |
27fn dist_to_sim(d: f32, metric: DistanceMetric) -> f32 {
28 match metric {
29 DistanceMetric::Cosine => 1.0 - d,
30 // All other metrics (and unknown future metrics) use negated distance.
31 _ => -d,
32 }
33}
34
35// ---------------------------------------------------------------------------
36// Public API

Callers 1

maxsimFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected