Skip to content

Commit 44b7889

Browse files
MichaelLi65535mdrxy
authored andcommitted
fix: fix score threshold is zero scenario (#398)
Co-authored-by: Mason Daugherty <[email protected]>
1 parent 27962ce commit 44b7889

File tree

1 file changed

+1
-1
lines changed
  • libs/community/langchain_community/utils

1 file changed

+1
-1
lines changed

libs/community/langchain_community/utils/math.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def cosine_similarity_top_k(
6464
if len(X) == 0 or len(Y) == 0:
6565
return [], []
6666
score_array = cosine_similarity(X, Y)
67-
score_threshold = score_threshold or -1.0
67+
score_threshold = -1.0 if score_threshold is None else score_threshold
6868
score_array[score_array < score_threshold] = 0
6969
top_k = int(min(top_k or len(score_array), int(np.count_nonzero(score_array))))
7070
top_k_idxs = np.argpartition(score_array, -top_k, axis=None)[-top_k:]

0 commit comments

Comments
 (0)