Add a guard on norm zero vectors in cosine distance (issue
@@ -299,6 +299,9 @@ def cosine(x, y):
norm_x += x[i]**2
norm_y += y[i]**2
+ if norm_x == 0.0 or norm_y == 0.0:
+ return 1.0
+ else:
return 1.0 - (result / np.sqrt(norm_x * norm_y))
