Skip to content

Commit 6d4f6f3

Browse files
authored
address issue for mmr calculation (#99)
I added a fix based on an issue that was addressed on the main [langchain-ai: max_marginal_relevance_search](https://github.com/langchain-ai/langchain/pull/22271/files) code.
1 parent f64aec3 commit 6d4f6f3

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

langchain_postgres/_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ def cosine_similarity(X: Matrix, Y: Matrix) -> np.ndarray:
3030

3131
X = np.array(X, dtype=np.float32)
3232
Y = np.array(Y, dtype=np.float32)
33-
Z = 1 - simd.cdist(X, Y, metric="cosine")
34-
if isinstance(Z, float):
35-
return np.array([Z])
36-
return np.array(Z)
33+
Z = 1 - np.array(simd.cdist(X, Y, metric="cosine"))
34+
return Z
3735
except ImportError:
3836
logger.debug(
3937
"Unable to import simsimd, defaulting to NumPy implementation. If you want "

0 commit comments

Comments
 (0)