cleanup storage state
Browse files- lightrag/lightrag.py +9 -10
lightrag/lightrag.py
CHANGED
@@ -250,12 +250,14 @@ class LightRAG:
|
|
250 |
The default function is :func:`.utils.convert_response_to_json`.
|
251 |
"""
|
252 |
|
|
|
|
|
253 |
def __post_init__(self):
|
|
|
254 |
os.makedirs(os.path.dirname(self.log_file_path), exist_ok=True)
|
255 |
set_logger(self.log_file_path)
|
256 |
-
|
257 |
-
logger.setLevel(self.log_level)
|
258 |
logger.info(f"Logger initialized for working directory: {self.working_dir}")
|
|
|
259 |
if not os.path.exists(self.working_dir):
|
260 |
logger.info(f"Creating working directory {self.working_dir}")
|
261 |
os.makedirs(self.working_dir)
|
@@ -283,9 +285,6 @@ class LightRAG:
|
|
283 |
**self.vector_db_storage_cls_kwargs,
|
284 |
}
|
285 |
|
286 |
-
# Life cycle
|
287 |
-
self.storages_status = StoragesStatus.NOT_CREATED
|
288 |
-
|
289 |
# Show config
|
290 |
global_config = asdict(self)
|
291 |
_print_config = ",\n ".join([f"{k} = {v}" for k, v in global_config.items()])
|
@@ -393,7 +392,7 @@ class LightRAG:
|
|
393 |
)
|
394 |
)
|
395 |
|
396 |
-
self.
|
397 |
|
398 |
# Initialize storages
|
399 |
if self.auto_manage_storages_states:
|
@@ -408,7 +407,7 @@ class LightRAG:
|
|
408 |
|
409 |
async def initialize_storages(self):
|
410 |
"""Asynchronously initialize the storages"""
|
411 |
-
if self.
|
412 |
tasks = []
|
413 |
|
414 |
for storage in (
|
@@ -426,12 +425,12 @@ class LightRAG:
|
|
426 |
|
427 |
await asyncio.gather(*tasks)
|
428 |
|
429 |
-
self.
|
430 |
logger.debug("Initialized Storages")
|
431 |
|
432 |
async def finalize_storages(self):
|
433 |
"""Asynchronously finalize the storages"""
|
434 |
-
if self.
|
435 |
tasks = []
|
436 |
|
437 |
for storage in (
|
@@ -449,7 +448,7 @@ class LightRAG:
|
|
449 |
|
450 |
await asyncio.gather(*tasks)
|
451 |
|
452 |
-
self.
|
453 |
logger.debug("Finalized Storages")
|
454 |
|
455 |
def _get_storage_class(self, storage_name: str) -> Callable[..., Any]:
|
|
|
250 |
The default function is :func:`.utils.convert_response_to_json`.
|
251 |
"""
|
252 |
|
253 |
+
_storages_status: StoragesStatus = field(default=StoragesStatus.NOT_CREATED)
|
254 |
+
|
255 |
def __post_init__(self):
|
256 |
+
logger.setLevel(self.log_level)
|
257 |
os.makedirs(os.path.dirname(self.log_file_path), exist_ok=True)
|
258 |
set_logger(self.log_file_path)
|
|
|
|
|
259 |
logger.info(f"Logger initialized for working directory: {self.working_dir}")
|
260 |
+
|
261 |
if not os.path.exists(self.working_dir):
|
262 |
logger.info(f"Creating working directory {self.working_dir}")
|
263 |
os.makedirs(self.working_dir)
|
|
|
285 |
**self.vector_db_storage_cls_kwargs,
|
286 |
}
|
287 |
|
|
|
|
|
|
|
288 |
# Show config
|
289 |
global_config = asdict(self)
|
290 |
_print_config = ",\n ".join([f"{k} = {v}" for k, v in global_config.items()])
|
|
|
392 |
)
|
393 |
)
|
394 |
|
395 |
+
self._storages_status = StoragesStatus.CREATED
|
396 |
|
397 |
# Initialize storages
|
398 |
if self.auto_manage_storages_states:
|
|
|
407 |
|
408 |
async def initialize_storages(self):
|
409 |
"""Asynchronously initialize the storages"""
|
410 |
+
if self._storages_status == StoragesStatus.CREATED:
|
411 |
tasks = []
|
412 |
|
413 |
for storage in (
|
|
|
425 |
|
426 |
await asyncio.gather(*tasks)
|
427 |
|
428 |
+
self._storages_status = StoragesStatus.INITIALIZED
|
429 |
logger.debug("Initialized Storages")
|
430 |
|
431 |
async def finalize_storages(self):
|
432 |
"""Asynchronously finalize the storages"""
|
433 |
+
if self._storages_status == StoragesStatus.INITIALIZED:
|
434 |
tasks = []
|
435 |
|
436 |
for storage in (
|
|
|
448 |
|
449 |
await asyncio.gather(*tasks)
|
450 |
|
451 |
+
self._storages_status = StoragesStatus.FINALIZED
|
452 |
logger.debug("Finalized Storages")
|
453 |
|
454 |
def _get_storage_class(self, storage_name: str) -> Callable[..., Any]:
|