workspace working

This commit is contained in:
2026-01-12 22:31:11 +08:00
parent 2738a822d1
commit 370fe6368a
149 changed files with 4648 additions and 660 deletions

View File

@@ -2250,6 +2250,50 @@ class LightRAG:
except Exception as e:
logger.error(f"Error while clearing cache: {e}")
async def adelete_workspace_data(self) -> None:
"""Delete all data for the current workspace from all storage instances.
This method drops all collections/namespaces for the workspace, effectively
clearing all documents, chunks, entities, relationships, and cache.
Should be called before deleting workspace directories.
Example:
# Delete all workspace data
await rag.adelete_workspace_data()
"""
logger.info(f"Deleting all workspace data for workspace: {self.workspace}")
# Ensure storages are initialized before dropping
if self._storages_status != StoragesStatus.INITIALIZED:
await self.initialize_storages()
storages = [
("full_docs", self.full_docs),
("text_chunks", self.text_chunks),
("full_entities", self.full_entities),
("full_relations", self.full_relations),
("entities_vdb", self.entities_vdb),
("relationships_vdb", self.relationships_vdb),
("chunks_vdb", self.chunks_vdb),
("chunk_entity_relation_graph", self.chunk_entity_relation_graph),
("llm_response_cache", self.llm_response_cache),
("doc_status", self.doc_status),
]
for name, storage in storages:
if storage is None:
continue
try:
success = await storage.drop()
if success:
logger.debug(f"Successfully dropped {name} for workspace {self.workspace}")
else:
logger.warning(f"Failed to drop {name} for workspace {self.workspace}")
except Exception as e:
logger.error(f"Error dropping {name}: {e}")
logger.info(f"Workspace data deletion completed for workspace: {self.workspace}")
def delete_workspace_data(self) -> None:
"""Synchronous version of adelete_workspace_data."""
return always_get_an_event_loop().run_until_complete(self.adelete_workspace_data())
def clear_cache(self) -> None:
"""Synchronous version of aclear_cache."""
return always_get_an_event_loop().run_until_complete(self.aclear_cache())