workspace working
This commit is contained in:
@@ -5,6 +5,7 @@ Provides isolation between different workspaces by managing separate LightRAG in
|
||||
|
||||
import os
|
||||
import logging
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from lightrag import LightRAG
|
||||
@@ -62,11 +63,54 @@ class WorkspaceManager:
|
||||
logger.error(f"Failed to create workspace '{name}': {e}")
|
||||
raise
|
||||
|
||||
def delete_workspace(self, name: str) -> bool:
|
||||
async def delete_workspace(self, name: str) -> bool:
|
||||
"""Delete a workspace directory and all its data."""
|
||||
# TODO: implement deletion with caution (maybe require confirmation)
|
||||
# For now, just raise NotImplementedError
|
||||
raise NotImplementedError("Workspace deletion not yet implemented")
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
# Validate name
|
||||
if not name or not name.strip():
|
||||
raise ValueError("Workspace name cannot be empty")
|
||||
name = name.strip()
|
||||
|
||||
# Check if workspace exists
|
||||
workspace_dir = self.base_working_dir / name
|
||||
input_subdir = self.base_input_dir / name
|
||||
if not workspace_dir.exists() and not input_subdir.exists():
|
||||
raise ValueError(f"Workspace '{name}' does not exist")
|
||||
|
||||
# Remove cached instances
|
||||
if name in self._rag_instances:
|
||||
del self._rag_instances[name]
|
||||
if name in self._doc_managers:
|
||||
del self._doc_managers[name]
|
||||
|
||||
# Delete workspace data from storage (vector DB, KV, graph, etc.)
|
||||
try:
|
||||
if self.lightrag_factory:
|
||||
# Create a temporary LightRAG instance for this workspace to delete its data
|
||||
rag = self.lightrag_factory(str(self.base_working_dir), name)
|
||||
# Call async delete_workspace_data
|
||||
await rag.adelete_workspace_data()
|
||||
logger.info(f"Deleted workspace data for '{name}' from storage")
|
||||
else:
|
||||
logger.warning("No lightrag_factory provided; workspace data may remain in storage")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to delete workspace data for '{name}': {e}. Proceeding with directory deletion.")
|
||||
|
||||
# Delete directories recursively
|
||||
try:
|
||||
if workspace_dir.exists():
|
||||
shutil.rmtree(workspace_dir)
|
||||
logger.info(f"Deleted workspace directory: {workspace_dir}")
|
||||
if input_subdir.exists():
|
||||
shutil.rmtree(input_subdir)
|
||||
logger.info(f"Deleted workspace input directory: {input_subdir}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to delete workspace '{name}': {e}")
|
||||
raise
|
||||
|
||||
return True
|
||||
|
||||
def get_rag(self, workspace: str = "") -> LightRAG:
|
||||
"""Get or create a LightRAG instance for the given workspace."""
|
||||
|
||||
Reference in New Issue
Block a user