Skip to content

Commit

Permalink
only warmup on index swap
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuo-danswer committed Oct 30, 2024
1 parent 7384ca8 commit 10df616
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
10 changes: 6 additions & 4 deletions backend/danswer/background/celery/tasks/indexing/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
20 changes: 13 additions & 7 deletions backend/danswer/db/swap_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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,
)
Expand All @@ -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

0 comments on commit 10df616

Please sign in to comment.