From 7c7a23640589b67be23ccc9c455ee5aed457f266 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sat, 19 Oct 2024 19:30:45 +0200 Subject: [PATCH] refactor: moved delete_collections to VectorMemory --- core/cat/memory/vector_memory.py | 12 ++++++++++++ core/cat/routes/memory/collections.py | 3 +-- core/cat/routes/settings.py | 3 +-- core/cat/utils.py | 19 ------------------- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/core/cat/memory/vector_memory.py b/core/cat/memory/vector_memory.py index ea422f4f..27506692 100644 --- a/core/cat/memory/vector_memory.py +++ b/core/cat/memory/vector_memory.py @@ -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""" diff --git a/core/cat/routes/memory/collections.py b/core/cat/routes/memory/collections.py index 4ef72b26..d84eb5f8 100644 --- a/core/cat/routes/memory/collections.py +++ b/core/cat/routes/memory/collections.py @@ -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 diff --git a/core/cat/routes/settings.py b/core/cat/routes/settings.py index 25ddd258..ff6b5e01 100644 --- a/core/cat/routes/settings.py +++ b/core/cat/routes/settings.py @@ -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() diff --git a/core/cat/utils.py b/core/cat/utils.py index f4b2bd43..ba46745a 100644 --- a/core/cat/utils.py +++ b/core/cat/utils.py @@ -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 @@ -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