Skip to content

Commit 49e5ff5

Browse files
committed
Update VectorOperations.java
1 parent 4c9c219 commit 49e5ff5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

semantickernel-api/src/main/java/com/microsoft/semantickernel/data/vectorsearch/VectorOperations.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public static float cosineSimilarity(@Nonnull List<Float> x, @Nonnull List<Float
4848
normY += y.get(i) * y.get(i);
4949
}
5050

51+
if (normX == 0 || normY == 0) {
52+
throw new SKException("Vectors cannot have zero norm");
53+
}
54+
5155
return (dotProduct / (float) (Math.sqrt(normX) * Math.sqrt(normY)));
5256
}
5357

0 commit comments

Comments
 (0)