diff --git a/lightrag/api/routers/document_routes.py b/lightrag/api/routers/document_routes.py index 06862fe6..64de58f6 100644 --- a/lightrag/api/routers/document_routes.py +++ b/lightrag/api/routers/document_routes.py @@ -941,114 +941,6 @@ def create_document_routes( logger.error(traceback.format_exc()) raise HTTPException(status_code=500, detail=str(e)) - # TODO: deprecated, use /upload instead - @router.post( - "/file", response_model=InsertResponse, dependencies=[Depends(combined_auth)] - ) - async def insert_file( - background_tasks: BackgroundTasks, file: UploadFile = File(...) - ): - """ - Insert a file directly into the RAG system. - - This endpoint accepts a file upload and processes it for inclusion in the RAG system. - The file is saved temporarily and processed in the background. - - Args: - background_tasks: FastAPI BackgroundTasks for async processing - file (UploadFile): The file to be processed - - Returns: - InsertResponse: A response object containing the status of the operation. - - Raises: - HTTPException: If the file type is not supported (400) or other errors occur (500). - """ - try: - if not doc_manager.is_supported_file(file.filename): - raise HTTPException( - status_code=400, - detail=f"Unsupported file type. Supported types: {doc_manager.supported_extensions}", - ) - - temp_path = await save_temp_file(doc_manager.input_dir, file) - - # Add to background tasks - background_tasks.add_task(pipeline_index_file, rag, temp_path) - - return InsertResponse( - status="success", - message=f"File '{file.filename}' saved successfully. Processing will continue in background.", - ) - except Exception as e: - logger.error(f"Error /documents/file: {str(e)}") - logger.error(traceback.format_exc()) - raise HTTPException(status_code=500, detail=str(e)) - - # TODO: deprecated, use /upload instead - @router.post( - "/file_batch", - response_model=InsertResponse, - dependencies=[Depends(combined_auth)], - ) - async def insert_batch( - background_tasks: BackgroundTasks, files: List[UploadFile] = File(...) - ): - """ - Process multiple files in batch mode. - - This endpoint allows uploading and processing multiple files simultaneously. - It handles partial successes and provides detailed feedback about failed files. - - Args: - background_tasks: FastAPI BackgroundTasks for async processing - files (List[UploadFile]): List of files to process - - Returns: - InsertResponse: A response object containing: - - status: "success", "partial_success", or "failure" - - message: Detailed information about the operation results - - Raises: - HTTPException: If an error occurs during processing (500). - """ - try: - inserted_count = 0 - failed_files = [] - temp_files = [] - - for file in files: - if doc_manager.is_supported_file(file.filename): - # Create a temporary file to save the uploaded content - temp_files.append(await save_temp_file(doc_manager.input_dir, file)) - inserted_count += 1 - else: - failed_files.append(f"{file.filename} (unsupported type)") - - if temp_files: - background_tasks.add_task(pipeline_index_files, rag, temp_files) - - # Prepare status message - if inserted_count == len(files): - status = "success" - status_message = f"Successfully inserted all {inserted_count} documents" - elif inserted_count > 0: - status = "partial_success" - status_message = f"Successfully inserted {inserted_count} out of {len(files)} documents" - if failed_files: - status_message += f". Failed files: {', '.join(failed_files)}" - else: - status = "failure" - status_message = "No documents were successfully inserted" - if failed_files: - status_message += f". Failed files: {', '.join(failed_files)}" - - return InsertResponse(status=status, message=status_message) - except Exception as e: - logger.error(f"Error /documents/batch: {str(e)}") - logger.error(traceback.format_exc()) - raise HTTPException(status_code=500, detail=str(e)) - @router.delete( "", response_model=ClearDocumentsResponse, dependencies=[Depends(combined_auth)] )