only warmup on index swap (#3003)

* only warmup on index swap

* move conditional
This commit is contained in:
rkuo-danswer 2024-10-30 17:40:03 -07:00 committed by GitHub
parent 1a7d627949
commit dba2d67cdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 16 deletions

View File

@ -105,19 +105,22 @@ 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
if current_search_settings.provider_type is None and not MULTI_TENANT:
embedding_model = EmbeddingModel.from_db_model(
search_settings=current_search_settings,
server_host=INDEXING_MODEL_SERVER_HOST,
server_port=INDEXING_MODEL_SERVER_PORT,
)
warm_up_bi_encoder(
embedding_model=embedding_model,
)
if old_search_settings:
embedding_model = EmbeddingModel.from_db_model(
search_settings=current_search_settings,
server_host=INDEXING_MODEL_SERVER_HOST,
server_port=INDEXING_MODEL_SERVER_PORT,
)
# 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:

View File

@ -14,7 +14,6 @@ from danswer.db.search_settings import get_secondary_search_settings
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 @@ logger = setup_logger()
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