Fix linting

This commit is contained in:
yangdx
2025-02-28 01:25:59 +08:00
parent 3dcfa561d7
commit cd7648791a
6 changed files with 23 additions and 21 deletions

View File

@@ -17,6 +17,7 @@ if not pm.is_installed("faiss"):
import faiss # type: ignore
from threading import Lock as ThreadLock
@final
@dataclass
class FaissVectorDBStorage(BaseVectorStorage):
@@ -59,7 +60,6 @@ class FaissVectorDBStorage(BaseVectorStorage):
with self._storage_lock:
self._load_faiss_index()
def _get_index(self):
"""Check if the shtorage should be reloaded"""
return self._index
@@ -224,10 +224,7 @@ class FaissVectorDBStorage(BaseVectorStorage):
logger.debug(f"Searching relations for entity {entity_name}")
relations = []
for fid, meta in self._id_to_meta.items():
if (
meta.get("src_id") == entity_name
or meta.get("tgt_id") == entity_name
):
if meta.get("src_id") == entity_name or meta.get("tgt_id") == entity_name:
relations.append(fid)
logger.debug(f"Found {len(relations)} relations for {entity_name}")
@@ -265,7 +262,7 @@ class FaissVectorDBStorage(BaseVectorStorage):
new_id_to_meta[new_fid] = vec_meta
with self._storage_lock:
# Re-init index
# Re-init index
self._index = faiss.IndexFlatIP(self._dim)
if vectors_to_keep:
arr = np.array(vectors_to_keep, dtype=np.float32)
@@ -273,7 +270,6 @@ class FaissVectorDBStorage(BaseVectorStorage):
self._id_to_meta = new_id_to_meta
def _save_faiss_index(self):
"""
Save the current Faiss index + metadata to disk so it can persist across runs.
@@ -290,7 +286,6 @@ class FaissVectorDBStorage(BaseVectorStorage):
with open(self._meta_file, "w", encoding="utf-8") as f:
json.dump(serializable_dict, f)
def _load_faiss_index(self):
"""
Load the Faiss index + metadata from disk if it exists,