diff --git a/backend/open_webui/events.py b/backend/open_webui/events.py index 5b23231f41..81b8cc3968 100644 --- a/backend/open_webui/events.py +++ b/backend/open_webui/events.py @@ -411,6 +411,11 @@ class EventDefinitions(BaseModel): description='Retrieval content was processed.', message='Retrieval Content processed', ) + RETRIEVAL_CONTENT_PROCESS_FAILED: EventDefinition = EventDefinition( + name='retrieval.content.process_failed', + description='Retrieval content processing failed.', + message='Retrieval Content process failed', + ) RETRIEVAL_COLLECTION_DELETED: EventDefinition = EventDefinition( name='retrieval.collection.deleted', description='A retrieval collection was deleted.', @@ -666,6 +671,7 @@ NOTIFICATION_EVENTS = ( EVENTS.CHAT_FAILED.name, EVENTS.CHANNEL_MESSAGE.name, EVENTS.CALENDAR_ALERT.name, + EVENTS.RETRIEVAL_CONTENT_PROCESS_FAILED.name, ) diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py index 464a2b233b..d81e1e4e2c 100644 --- a/backend/open_webui/routers/retrieval.py +++ b/backend/open_webui/routers/retrieval.py @@ -1998,7 +1998,7 @@ async def process_file( hash = calculate_sha256_string(text_content) if config.BYPASS_EMBEDDING_AND_RETRIEVAL: - await Files.update_file_data_by_id(file.id, {'status': 'completed'}, db=db) + await Files.update_file_data_by_id(file.id, {'status': 'completed', 'error': None}, db=db) await Files.update_file_hash_by_id(file.id, hash, db=db) await publish_event( request, @@ -2057,7 +2057,7 @@ async def process_file( await Files.update_file_data_by_id( file.id, - {'status': 'completed'}, + {'status': 'completed', 'error': None}, db=session, ) await Files.update_file_hash_by_id(file.id, hash, db=session) @@ -2087,12 +2087,25 @@ async def process_file( async with get_async_db() as session: await Files.update_file_data_by_id( file.id, - {'status': 'failed'}, + {'status': 'failed', 'error': str(e)}, db=session, ) # Clear the hash so the file can be re-uploaded after fixing the issue await Files.update_file_hash_by_id(file.id, None, db=session) + await publish_event( + request, + EVENTS.RETRIEVAL_CONTENT_PROCESS_FAILED, + actor=user, + subject_id=file.id, + subject_type='file', + data={ + 'collection_name': collection_name, + 'filename': file.filename, + 'message': f'{file.filename}: {e}', + }, + ) + if 'No pandoc was found' in str(e): raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST,