Skip to content

Commit

Permalink
Cosine similarity should be orthogonal when both vectors are zero
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyM3 committed Dec 24, 2024
1 parent 09fe2e7 commit 0a7a20c
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,11 +1819,8 @@ float common_embd_similarity_cos(const float * embd1, const float * embd2, int n
sum2 += embd2[i] * embd2[i];
}

// Handle the case where one or both vectors are zero vectors
// Both vectors are required to be non-zero.
if (sum1 == 0.0 || sum2 == 0.0) {
if (sum1 == 0.0 && sum2 == 0.0) {
return 1.0f; // two zero vectors are similar
}
return 0.0f;
}

Expand Down

0 comments on commit 0a7a20c

Please sign in to comment.