From bd487dd252ab5155bf752341bc64d4ff54df1f01 Mon Sep 17 00:00:00 2001 From: yangdx Date: Mon, 23 Jun 2025 21:38:47 +0800 Subject: [PATCH] Unify document APIs returen status string --- lightrag/api/routers/document_routes.py | 4 ++-- lightrag/base.py | 2 +- lightrag/lightrag.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lightrag/api/routers/document_routes.py b/lightrag/api/routers/document_routes.py index 2dcca47a..f5bdf01d 100644 --- a/lightrag/api/routers/document_routes.py +++ b/lightrag/api/routers/document_routes.py @@ -1341,12 +1341,12 @@ def create_document_routes( ) @router.delete( - "/delete_by_doc_id", + "/delete_document", response_model=DeleteDocByIdResponse, dependencies=[Depends(combined_auth)], summary="Delete a document and all its associated data by its ID.", ) - async def delete_by_doc_id( + async def delete_document( delete_request: DeleteDocRequest, ) -> DeleteDocByIdResponse: """ diff --git a/lightrag/base.py b/lightrag/base.py index 47a390b5..84fc7564 100644 --- a/lightrag/base.py +++ b/lightrag/base.py @@ -619,7 +619,7 @@ class StoragesStatus(str, Enum): class DeletionResult: """Represents the result of a deletion operation.""" - status: Literal["success", "not_found", "failure"] + status: Literal["success", "not_found", "fail"] doc_id: str message: str status_code: int = 200 diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index 98a9157c..ec40d197 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -1698,10 +1698,10 @@ class LightRAG: Returns: DeletionResult: An object containing the outcome of the deletion process. - - `success` (bool): True if the deletion was successful, False otherwise. + - `status` (str): "success", "not_found", or "failure". + - `doc_id` (str): The ID of the document attempted to be deleted. - `message` (str): A summary of the operation's result. - - `deleted_ids` (dict[str, list[str]]): A dictionary detailing the IDs of - all deleted items, categorized by storage type (e.g., "chunks", "entities"). + - `status_code` (int): HTTP status code (e.g., 200, 404, 500). """ try: # 1. Get the document status and related data @@ -1902,7 +1902,7 @@ Rebuilt: {len(entities_to_rebuild)} entities, {len(relationships_to_rebuild)} re logger.error(error_message) logger.error(traceback.format_exc()) return DeletionResult( - status="failure", + status="fail", doc_id=doc_id, message=error_message, status_code=500,