MCPcopy Create free account
hub / github.com/Spinachead/arg / ThreadSafeFaiss

Class ThreadSafeFaiss

app/knowledge_base/kb_cache/faiss_cache.py:27–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26
27class ThreadSafeFaiss(ThreadSafeObject):
28 def __repr__(self) -> str:
29 cls = type(self).__name__
30 return f"<{cls}: key: {self.key}, obj: {self._obj}, docs_count: {self.docs_count()}>"
31
32 def docs_count(self) -> int:
33 return len(self._obj.docstore._dict)
34
35 def save(self, path: str, create_path: bool = True):
36 with self.acquire():
37 if not os.path.isdir(path) and create_path:
38 os.makedirs(path)
39 ret = self._obj.save_local(path)
40 # logger.info(f"已将向量库 {self.key} 保存到磁盘")
41 return ret
42
43 def clear(self):
44 ret = []
45 with self.acquire():
46 ids = list(self._obj.docstore._dict.keys())
47 if ids:
48 ret = self._obj.delete(ids)
49 assert len(self._obj.docstore._dict) == 0
50 # logger.info(f"已将向量库 {self.key} 清空")
51 return ret
52
53
54class _FaissPool(CachePool):

Callers 2

load_vector_storeMethod · 0.85
load_vector_storeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected