Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
Fix disk I/O error when resetting short-term memory. (#1724)
Carlos Souza6b87d22a7084
diff --git a/src/crewai/knowledge/storage/knowledge_storage.py b/src/crewai/knowledge/storage/knowledge_storage.pyindex e0e36f4a7..acbbe75a1 100644--- a/src/crewai/knowledge/storage/knowledge_storage.py+++ b/src/crewai/knowledge/storage/knowledge_storage.py@@ -3,6 +3,7 @@ import hashlibimport ioimport loggingimport os+import shutilfrom typing import Any, Dict, List, Optional, Union, castimport chromadb@@ -15,6 +16,7 @@ from crewai.knowledge.storage.base_knowledge_storage import BaseKnowledgeStoragefrom crewai.utilities import EmbeddingConfiguratorfrom crewai.utilities.logger import Loggerfrom crewai.utilities.paths import db_storage_path+from crewai.utilities.constants import KNOWLEDGE_DIRECTORY@contextlib.contextmanager@@ -105,15 +107,17 @@ class KnowledgeStorage(BaseKnowledgeStorage):raise Exception("Failed to create or get collection")def reset(self):- if self.app:- self.app.reset()- else:- base_path = os.path.join(db_storage_path(), "knowledge")+ base_path = os.path.join(db_storage_path(), KNOWLEDGE_DIRECTORY)+ if not self.app:self.app = chromadb.PersistentClient(path=base_path,settings=Settings(allow_reset=True),)- self.app.reset()++ self.app.reset()+ shutil.rmtree(base_path)+ self.app = None+ self.collection = Nonedef save(self,diff --git a/src/crewai/memory/storage/rag_storage.py b/src/crewai/memory/storage/rag_storage.pyindex bf40aee96..fd4c77838 100644--- a/src/crewai/memory/storage/rag_storage.py+++ b/src/crewai/memory/storage/rag_storage.py@@ -150,9 +150,11 @@ class RAGStorage(BaseRAGStorage):def reset(self) -> None:try:- shutil.rmtree(f"{db_storage_path()}/{self.type}")if self.app:self.app.reset()+ shutil.rmtree(f"{db_storage_path()}/{self.type}")+ self.app = None+ self.collection = Noneexcept Exception as e:if "attempt to write a readonly database" in str(e):# Ignore this specific error