We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 68ed432 + 6a09118 commit ee3ee47Copy full SHA for ee3ee47
src/distance/cosine.rs
@@ -40,8 +40,9 @@ impl Distance for Cosine {
40
let qn = q.header.norm;
41
let pq = dot_product(&p.vector, &q.vector);
42
let pnqn = pn * qn;
43
- if pnqn != 0.0 {
+ if pnqn > f32::EPSILON {
44
let cos = pq / pnqn;
45
+ let cos = cos.clamp(-1.0, 1.0);
46
// cos is [-1; 1]
47
// cos = 0. -> 0.5
48
// cos = -1. -> 1.0
0 commit comments