Skip to content

Commit

Permalink
fix pylint & better code
Browse files Browse the repository at this point in the history
Signed-off-by: akashAD <[email protected]>
  • Loading branch information
akashAD98 committed Sep 4, 2024
1 parent 57e5c30 commit f5ca7f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
19 changes: 5 additions & 14 deletions gptcache/manager/vector_data/lancedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def __init__(

def mul_add(self, datas: List[VectorData]):
"""Add multiple vectors to the LanceDB table"""
vectors, ids = map(list, zip(*((data.data.tolist(), str(data.id)) for data in datas)))

vectors, vector_ids = map(list, zip(*((data.data.tolist(), str(data.id)) for data in datas)))
# Infer the dimension of the vectors
vector_dim = len(vectors[0]) if vectors else 0

Expand All @@ -56,7 +55,7 @@ def mul_add(self, datas: List[VectorData]):
self._table = self._db.create_table(self._table_name, schema=schema)

# Prepare data for insertion
data = [{"id": id, "vector": vector} for id, vector in zip(ids, vectors)]
data = [{"id": vector_id, "vector": vector} for vector_id, vector in zip(vector_ids, vectors)]
self._table.add(data)

def search(self, data: np.ndarray, top_k: int = -1):
Expand All @@ -72,21 +71,13 @@ def search(self, data: np.ndarray, top_k: int = -1):

def delete(self, ids: List[int]):
"""Delete vectors from the LanceDB table based on IDs"""
for id in ids:
self._table.delete(f"id = '{id}'")
for vector_id in ids:
self._table.delete(f"id = '{vector_id}'")

def rebuild(self, ids: Optional[List[int]] = None):
"""Rebuild the index, if applicable"""
return True

def flush(self):
"""Flush changes to disk (if necessary)"""
pass

def close(self):
"""Close the connection to LanceDB"""
pass

def count(self):
"""Return the total number of vectors in the table"""
return len(self._table)
return len(self._table)
2 changes: 1 addition & 1 deletion gptcache/manager/vector_data/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def get(name, **kwargs):
from gptcache.manager.vector_data.weaviate import Weaviate

url = kwargs.get("url", None)
auth_client_secret = kwargs.get("auth_client_secrets", None)
auth_client_secret = kwargs.get("auth_client_secret", None)
timeout_config = kwargs.get("timeout_config", WEAVIATE_TIMEOUT_CONFIG)
proxies = kwargs.get("proxies", None)
trust_env = kwargs.get("trust_env", False)
Expand Down

0 comments on commit f5ca7f4

Please sign in to comment.