diff --git a/backend/danswer/db/engine.py b/backend/danswer/db/engine.py index d83627dc5..aa576cb92 100644 --- a/backend/danswer/db/engine.py +++ b/backend/danswer/db/engine.py @@ -36,7 +36,7 @@ POSTGRES_APP_NAME = ( _SYNC_ENGINE: Engine | None = None _ASYNC_ENGINE: AsyncEngine | None = None -SessionFactory = None +SessionFactory: sessionmaker[Session] | None = None def get_db_current_time(db_session: Session) -> datetime: diff --git a/backend/danswer/search/postprocessing/postprocessing.py b/backend/danswer/search/postprocessing/postprocessing.py index 629181945..0aacce71a 100644 --- a/backend/danswer/search/postprocessing/postprocessing.py +++ b/backend/danswer/search/postprocessing/postprocessing.py @@ -236,6 +236,12 @@ def search_postprocessing( ) -> Iterator[list[InferenceSection] | list[int]]: post_processing_tasks: list[FunctionCall] = [] + if not retrieved_sections: + # Avoids trying to rerank an empty list which throws an error + yield [] + yield [] + return + rerank_task_id = None sections_yielded = False if should_rerank(search_query):