diff --git a/backend/danswer/background/celery/tasks/indexing/tasks.py b/backend/danswer/background/celery/tasks/indexing/tasks.py index 7c1460cbddf..32b43a9d8e0 100644 --- a/backend/danswer/background/celery/tasks/indexing/tasks.py +++ b/backend/danswer/background/celery/tasks/indexing/tasks.py @@ -105,7 +105,7 @@ def check_for_indexing(self: Task, *, tenant_id: str | None) -> int | None: return None with get_session_with_tenant(tenant_id=tenant_id) as db_session: - check_index_swap(db_session=db_session) + old_search_settings = check_index_swap(db_session=db_session) current_search_settings = get_current_search_settings(db_session) # So that the first time users aren't surprised by really slow speed of first # batch of documents indexed @@ -115,9 +115,11 @@ def check_for_indexing(self: Task, *, tenant_id: str | None) -> int | None: server_host=INDEXING_MODEL_SERVER_HOST, server_port=INDEXING_MODEL_SERVER_PORT, ) - warm_up_bi_encoder( - embedding_model=embedding_model, - ) + if old_search_settings: + # only warm up if search settings were changed + warm_up_bi_encoder( + embedding_model=embedding_model, + ) cc_pair_ids: list[int] = [] with get_session_with_tenant(tenant_id) as db_session: diff --git a/backend/danswer/db/swap_index.py b/backend/danswer/db/swap_index.py index 4961f05bbd4..8b583bd2e4b 100644 --- a/backend/danswer/db/swap_index.py +++ b/backend/danswer/db/swap_index.py @@ -14,7 +14,6 @@ from danswer.db.search_settings import update_search_settings_status from danswer.key_value_store.factory import get_kv_store from danswer.utils.logger import setup_logger -from shared_configs.configs import MULTI_TENANT logger = setup_logger() @@ -23,7 +22,14 @@ def check_index_swap(db_session: Session) -> SearchSettings | None: """Get count of cc-pairs and count of successful index_attempts for the new model grouped by connector + credential, if it's the same, then assume - new index is done building. If so, swap the indices and expire the old one.""" + new index is done building. If so, swap the indices and expire the old one. + + Returns None if search settings did not change, or the old search settings if they + did change. + """ + + old_search_settings = None + # Default CC-pair created for Ingestion API unused here all_cc_pairs = get_connector_credential_pairs(db_session) cc_pair_count = max(len(all_cc_pairs) - 1, 0) @@ -43,9 +49,9 @@ def check_index_swap(db_session: Session) -> SearchSettings | None: if cc_pair_count == 0 or cc_pair_count == unique_cc_indexings: # Swap indices - now_old_search_settings = get_current_search_settings(db_session) + current_search_settings = get_current_search_settings(db_session) update_search_settings_status( - search_settings=now_old_search_settings, + search_settings=current_search_settings, new_status=IndexModelStatus.PAST, db_session=db_session, ) @@ -67,6 +73,6 @@ def check_index_swap(db_session: Session) -> SearchSettings | None: for cc_pair in all_cc_pairs: resync_cc_pair(cc_pair, db_session=db_session) - if MULTI_TENANT: - return now_old_search_settings - return None + old_search_settings = current_search_settings + + return old_search_settings