Skip to content

Commit 99d70c4

Browse files
committed
undo changes in pyproject
1 parent 29c7972 commit 99d70c4

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ exclude = [
6363
]
6464

6565
[[tool.mypy.overrides]]
66-
module = [
67-
"google.auth.*",
68-
"requests.*",
69-
"pymysql.*"
70-
]
66+
module="google.auth.*"
7167
ignore_missing_imports = true
7268

7369

src/langchain_google_cloud_sql_mysql/vectorstore.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,18 @@ def __exec_apply_vector_index(self, query_template: str, vector_index: VectorInd
281281
stmt = query_template.format(index_options_query)
282282
self.engine._execute_outside_tx(stmt)
283283

284-
def _get_vector_index_name(self):
284+
def _get_vector_index_name(self) -> Optional[str]:
285285
query = f"SELECT index_name FROM mysql.vector_indexes WHERE table_name='{self.db_name}.{self.table_name}';"
286-
result = self.engine._fetch(query)
287-
if result:
288-
return result[0]["index_name"]
289-
else:
290-
return None
286+
try:
287+
result = self.engine._fetch(query)
288+
if result:
289+
return result[0]["index_name"]
290+
else:
291+
return None
292+
except Exception as e:
293+
if "doesn't exist" in str(e) and "mysql.vector_indexes" in str(e):
294+
return None
295+
raise
291296

292297
def drop_vector_index(self):
293298
existing_index_name = self._get_vector_index_name()
@@ -731,25 +736,25 @@ def cosine_similarity(X: Matrix, Y: Matrix) -> np.ndarray:
731736

732737
X = np.array(X)
733738
Y = np.array(Y)
734-
if X.shape[1] != Y.shape[1]:
739+
if X.shape[1] != Y.shape[1]: # type: ignore
735740
raise ValueError(
736-
f"Number of columns in X and Y must be the same. X has shape {X.shape} "
737-
f"and Y has shape {Y.shape}."
741+
f"Number of columns in X and Y must be the same. X has shape {X.shape} " # type: ignore
742+
f"and Y has shape {Y.shape}." # type: ignore
738743
)
739744
try:
740745
import simsimd as simd # type: ignore
741746

742747
X = np.array(X, dtype=np.float32)
743748
Y = np.array(Y, dtype=np.float32)
744-
Z = 1 - simd.cdist(X, Y, metric="cosine")
749+
Z = 1 - simd.cdist(X, Y, metric="cosine") # type: ignore
745750
if isinstance(Z, float):
746751
return np.array([Z])
747-
return Z
752+
return Z # type: ignore
748753
except ImportError:
749754
X_norm = np.linalg.norm(X, axis=1)
750755
Y_norm = np.linalg.norm(Y, axis=1)
751756
# Ignore divide by zero errors run time warnings as those are handled below.
752757
with np.errstate(divide="ignore", invalid="ignore"):
753-
similarity = np.dot(X, Y.T) / np.outer(X_norm, Y_norm)
758+
similarity = np.dot(X, Y.T) / np.outer(X_norm, Y_norm) # type: ignore
754759
similarity[np.isnan(similarity) | np.isinf(similarity)] = 0.0
755760
return similarity

0 commit comments

Comments
 (0)