Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pinecone[patch]: release 0.0.2rc0, remove simsimd dep #17469

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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