Skip to content

Commit

Permalink
address issue for mmr calculation (#99)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
IanQS authored Aug 12, 2024
1 parent f64aec3 commit 6d4f6f3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions langchain_postgres/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ def cosine_similarity(X: Matrix, Y: Matrix) -> np.ndarray:

X = np.array(X, dtype=np.float32)
Y = np.array(Y, dtype=np.float32)
Z = 1 - simd.cdist(X, Y, metric="cosine")
if isinstance(Z, float):
return np.array([Z])
return np.array(Z)
Z = 1 - np.array(simd.cdist(X, Y, metric="cosine"))
return Z
except ImportError:
logger.debug(
"Unable to import simsimd, defaulting to NumPy implementation. If you want "
Expand Down

0 comments on commit 6d4f6f3

Please sign in to comment.