mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-25 22:08:46 +01:00
Cosine similarity should be orthogonal when both vectors are zero
This commit is contained in:
parent
09fe2e7613
commit
0a7a20c140
@ -1819,11 +1819,8 @@ float common_embd_similarity_cos(const float * embd1, const float * embd2, int n
|
|||||||
sum2 += embd2[i] * embd2[i];
|
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) {
|
||||||
if (sum1 == 0.0 && sum2 == 0.0) {
|
|
||||||
return 1.0f; // two zero vectors are similar
|
|
||||||
}
|
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user