Skip to content

Commit

Permalink
pinecone[patch]: release 0.0.2rc0, remove simsimd dep (#17469)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Feb 13, 2024
1 parent 065cde6 commit 10bdf24
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 55 deletions.
23 changes: 16 additions & 7 deletions libs/partners/pinecone/langchain_pinecone/_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import List, Union

import numpy as np
import simsimd # type: ignore

Matrix = Union[List[List[float]], List[np.ndarray], np.ndarray]

Expand Down Expand Up @@ -62,10 +61,20 @@ def cosine_similarity(X: Matrix, Y: Matrix) -> np.ndarray:
f"Number of columns in X and Y must be the same. X has shape {X.shape} "
f"and Y has shape {Y.shape}."
)
try:
import simsimd as simd # type: ignore

X = np.array(X, dtype=np.float32)
Y = np.array(Y, dtype=np.float32)
Z = 1 - simsimd.cdist(X, Y, metric="cosine")
if isinstance(Z, float):
return np.array([Z])
return Z
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 Z
except ImportError:
X_norm = np.linalg.norm(X, axis=1)
Y_norm = np.linalg.norm(Y, axis=1)
# Ignore divide by zero errors run time warnings as those are handled below.
with np.errstate(divide="ignore", invalid="ignore"):
similarity = np.dot(X, Y.T) / np.outer(X_norm, Y_norm)
similarity[np.isnan(similarity) | np.isinf(similarity)] = 0.0
return similarity
50 changes: 7 additions & 43 deletions libs/partners/pinecone/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions libs/partners/pinecone/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langchain-pinecone"
version = "0.0.1"
version = "0.0.2rc0"
description = "An integration package connecting Pinecone and LangChain"
authors = []
readme = "README.md"
Expand All @@ -11,10 +11,10 @@ license = "MIT"
"Source Code" = "https://github.com/langchain-ai/langchain/tree/master/libs/partners/pinecone"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
langchain-core = ">=0.0.12"
pinecone-client = { version = "^3", python = ">=3.8,<3.13" }
simsimd = "^3.6.3"
# <3.13 is due to restriction in pinecone-client package
python = ">=3.8.1,<3.13"
langchain-core = "^0.1"
pinecone-client = { version = "^3" }
numpy = "^1"

[tool.poetry.group.test]
Expand Down

0 comments on commit 10bdf24

Please sign in to comment.