Skip to content

Commit

Permalink
refactor: moved delete_collections to VectorMemory
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredotoselli committed Oct 19, 2024
1 parent ca175e5 commit 7c7a236
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
12 changes: 12 additions & 0 deletions core/cat/memory/vector_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ def delete_collection(self, collection_name: str):
"""Delete specific vector collection"""

return self.vector_db.delete_collection(collection_name)

def delete_collections(self) -> dict[str, bool]:
"""Delete all collections"""

collections = list(self.collections.keys())

deleted = {}
for c in collections:
ret = self.delete_collection(c)
deleted[c] = ret

return deleted

def get_collection(self, collection_name: str):
"""Get collection info"""
Expand Down
3 changes: 1 addition & 2 deletions core/cat/routes/memory/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ async def wipe_collections(
) -> Dict:
"""Delete and create all collections"""

vector_memory: VectorMemory = stray.memory.vectors
deleted_memories = utils.delete_collections(vector_memory)
deleted_memories = stray.memory.vectors.delete_collections()

ccat: CheshireCat = request.app.state.ccat
ccat.load_memory() # recreate the long term memories
Expand Down
3 changes: 1 addition & 2 deletions core/cat/routes/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def factory_reset(

os.remove(metadata_file)

vector_memory: VectorMemory = stray.memory.vectors
deleted_memories = utils.delete_collections(vector_memory)
deleted_memories = stray.memory.vectors.delete_collections()

utils.singleton.instances.clear()
request.app.state.strays.clear()
Expand Down
19 changes: 0 additions & 19 deletions core/cat/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
"""Various utiles used from the projects."""

# Avoids circular import issues for type hints
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from cat.memory.vector_memory import VectorMemory

import os
import traceback
import inspect
Expand Down Expand Up @@ -316,16 +310,3 @@ def items(self):

def __contains__(self, key):
return key in self.keys()


def delete_collections(vector_memory: VectorMemory) -> Dict[str, bool]:
"""Delete all collections"""

collections = list(vector_memory.collections.keys())

deleted = {}
for c in collections:
ret = vector_memory.delete_collection(c)
deleted[c] = ret

return deleted

0 comments on commit 7c7a236

Please sign in to comment.