From 4c549a5a991efade2bea2b062babe07a2e4e25ed Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Fri, 30 Aug 2024 16:44:26 -0700 Subject: [PATCH 1/7] fix mypy --- backend/danswer/file_processing/extract_file_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/danswer/file_processing/extract_file_text.py b/backend/danswer/file_processing/extract_file_text.py index eeb7b5ae8ba..a9110290e2c 100644 --- a/backend/danswer/file_processing/extract_file_text.py +++ b/backend/danswer/file_processing/extract_file_text.py @@ -283,7 +283,7 @@ def extract_file_text( file_name: str | None, file: IO[Any], break_on_unprocessable: bool = True, -) -> str: +) -> tuple[str, dict]: extension_to_function: dict[str, Callable[[IO[Any]], str]] = { ".pdf": read_pdf_file, ".docx": docx_to_text, From 137967577190c58875ec4029eedf8f8e94465914 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 27 Aug 2024 11:25:14 -0700 Subject: [PATCH 2/7] search settings startup --- backend/danswer/main.py | 2 ++ web/src/app/chat/ChatPage.tsx | 1 + 2 files changed, 3 insertions(+) diff --git a/backend/danswer/main.py b/backend/danswer/main.py index 6652e5d3c39..96e1cb92321 100644 --- a/backend/danswer/main.py +++ b/backend/danswer/main.py @@ -48,6 +48,7 @@ from danswer.db.engine import warm_up_connections from danswer.db.index_attempt import cancel_indexing_attempts_past_model from danswer.db.index_attempt import expire_index_attempts +from danswer.db.models import Connector from danswer.db.persona import delete_old_default_personas from danswer.db.search_settings import get_current_search_settings from danswer.db.search_settings import get_secondary_search_settings @@ -194,6 +195,7 @@ def setup_postgres(db_session: Session) -> None: def translate_saved_search_settings(db_session: Session) -> None: kv_store = get_dynamic_config_store() + db_session.query(Connector).count() try: search_settings_dict = kv_store.load(KV_SEARCH_SETTINGS) diff --git a/web/src/app/chat/ChatPage.tsx b/web/src/app/chat/ChatPage.tsx index 1c9441d079b..43503a3af14 100644 --- a/web/src/app/chat/ChatPage.tsx +++ b/web/src/app/chat/ChatPage.tsx @@ -2095,6 +2095,7 @@ export function ChatPage({ )} )} + {/* Some padding at the bottom so the search bar has space at the bottom to not cover the last message*/}
From f725aa1344effa44cbd27066f86382ec18985513 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 27 Aug 2024 11:49:35 -0700 Subject: [PATCH 3/7] append the values --- backend/danswer/main.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/backend/danswer/main.py b/backend/danswer/main.py index 96e1cb92321..865ea3a0b5d 100644 --- a/backend/danswer/main.py +++ b/backend/danswer/main.py @@ -48,7 +48,6 @@ from danswer.db.engine import warm_up_connections from danswer.db.index_attempt import cancel_indexing_attempts_past_model from danswer.db.index_attempt import expire_index_attempts -from danswer.db.models import Connector from danswer.db.persona import delete_old_default_personas from danswer.db.search_settings import get_current_search_settings from danswer.db.search_settings import get_secondary_search_settings @@ -195,7 +194,30 @@ def setup_postgres(db_session: Session) -> None: def translate_saved_search_settings(db_session: Session) -> None: kv_store = get_dynamic_config_store() - db_session.query(Connector).count() + # connector_count = db_session.query(Connector).count() + + docs_exist = check_docs_exist(db_session) + connectors_exist = check_connectors_exist(db_session) + if not docs_exist and not connectors_exist: + import requests + from shared_configs.configs import MODEL_SERVER_HOST + from shared_configs.configs import MODEL_SERVER_PORT + + response = requests.get( + f"http://{MODEL_SERVER_HOST}:{MODEL_SERVER_PORT}/api/gpu-status" + ) + + if response.status_code == 200: + gpu_status = response.json() + print(f"GPU Status: {gpu_status}") + if gpu_status["gpu_available"]: + print(f"GPU is available. Type: {gpu_status['type']}") + else: + print("GPU is not available") + else: + print( + f"Error: Unable to fetch GPU status. Status code: {response.status_code}" + ) try: search_settings_dict = kv_store.load(KV_SEARCH_SETTINGS) From 083bc4b9beb58c5f5841c8214bf99e048fa04a93 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 27 Aug 2024 12:17:44 -0700 Subject: [PATCH 4/7] on fresh starts, detect GPU to set multipass indexing --- backend/danswer/main.py | 47 +++++++++++++++++------------- backend/danswer/utils/gpu_utils.py | 28 ++++++++++++++++++ 2 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 backend/danswer/utils/gpu_utils.py diff --git a/backend/danswer/main.py b/backend/danswer/main.py index 865ea3a0b5d..99a4bff9fe5 100644 --- a/backend/danswer/main.py +++ b/backend/danswer/main.py @@ -109,6 +109,7 @@ from danswer.tools.built_in_tools import auto_add_search_tool_to_personas from danswer.tools.built_in_tools import load_builtin_tools from danswer.tools.built_in_tools import refresh_built_in_tools_cache +from danswer.utils.gpu_utils import gpu_status_request from danswer.utils.logger import setup_logger from danswer.utils.telemetry import optional_telemetry from danswer.utils.telemetry import RecordType @@ -192,32 +193,36 @@ def setup_postgres(db_session: Session) -> None: auto_add_search_tool_to_personas(db_session) -def translate_saved_search_settings(db_session: Session) -> None: - kv_store = get_dynamic_config_store() - # connector_count = db_session.query(Connector).count() - +def update_default_multipass_indexing(db_session: Session) -> None: docs_exist = check_docs_exist(db_session) connectors_exist = check_connectors_exist(db_session) - if not docs_exist and not connectors_exist: - import requests - from shared_configs.configs import MODEL_SERVER_HOST - from shared_configs.configs import MODEL_SERVER_PORT + logger.debug(f"Docs exist: {docs_exist}, Connectors exist: {connectors_exist}") - response = requests.get( - f"http://{MODEL_SERVER_HOST}:{MODEL_SERVER_PORT}/api/gpu-status" + if not docs_exist and not connectors_exist: + logger.info( + "No existing docs or connectors found. Checking GPU availability for multipass indexing." ) - - if response.status_code == 200: - gpu_status = response.json() - print(f"GPU Status: {gpu_status}") - if gpu_status["gpu_available"]: - print(f"GPU is available. Type: {gpu_status['type']}") - else: - print("GPU is not available") + gpu_available = gpu_status_request() + logger.info(f"GPU availability: {gpu_available}") + + current_settings = get_current_search_settings(db_session) + if current_settings: + logger.notice(f"Updating multipass indexing setting to: {gpu_available}") + updated_settings = SavedSearchSettings.from_db_model(current_settings) + updated_settings.multipass_indexing = gpu_available + update_current_search_settings(db_session, updated_settings) else: - print( - f"Error: Unable to fetch GPU status. Status code: {response.status_code}" + logger.warning( + "No current search settings found. Skipping multipass indexing update." ) + else: + logger.debug( + "Existing docs or connectors found. Skipping multipass indexing update." + ) + + +def translate_saved_search_settings(db_session: Session) -> None: + kv_store = get_dynamic_config_store() try: search_settings_dict = kv_store.load(KV_SEARCH_SETTINGS) @@ -365,6 +370,8 @@ async def lifespan(app: FastAPI) -> AsyncGenerator: translate_saved_search_settings(db_session) + update_default_multipass_indexing(db_session) + # Does the user need to trigger a reindexing to bring the document index # into a good state, marked in the kv store mark_reindex_flag(db_session) diff --git a/backend/danswer/utils/gpu_utils.py b/backend/danswer/utils/gpu_utils.py new file mode 100644 index 00000000000..2eb59563df8 --- /dev/null +++ b/backend/danswer/utils/gpu_utils.py @@ -0,0 +1,28 @@ +import requests + +from danswer.utils.logger import setup_logger +from shared_configs.configs import MODEL_SERVER_HOST +from shared_configs.configs import MODEL_SERVER_PORT + +logger = setup_logger() + + +def gpu_status_request() -> bool: + model_server_url = f"{MODEL_SERVER_HOST}:{MODEL_SERVER_PORT}" + + if "http" not in model_server_url: + model_server_url = f"http://{model_server_url}" + + response = requests.get(f"{model_server_url}/api/gpu-status") + + if response.status_code == 200: + gpu_status = response.json() + if gpu_status["gpu_available"]: + return True + else: + return False + else: + logger.warning( + f"Error: Unable to fetch GPU status. Status code: {response.status_code}" + ) + return False From 14409852b0b8f69be2b1c3df72e6b4778cb21470 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 27 Aug 2024 12:23:35 -0700 Subject: [PATCH 5/7] squash --- backend/danswer/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/danswer/main.py b/backend/danswer/main.py index 99a4bff9fe5..41dcc59d76c 100644 --- a/backend/danswer/main.py +++ b/backend/danswer/main.py @@ -370,6 +370,7 @@ async def lifespan(app: FastAPI) -> AsyncGenerator: translate_saved_search_settings(db_session) + # update multipass indexing setting based on GPU availability update_default_multipass_indexing(db_session) # Does the user need to trigger a reindexing to bring the document index From 16672bead8438c73696544f703b76c1892250c30 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Fri, 30 Aug 2024 16:42:54 -0700 Subject: [PATCH 6/7] add gpu --- backend/danswer/utils/gpu_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/danswer/utils/gpu_utils.py b/backend/danswer/utils/gpu_utils.py index 2eb59563df8..5b872ffddb4 100644 --- a/backend/danswer/utils/gpu_utils.py +++ b/backend/danswer/utils/gpu_utils.py @@ -7,7 +7,7 @@ logger = setup_logger() -def gpu_status_request() -> bool: +def gpu_status_request(indexing: bool = False) -> bool: model_server_url = f"{MODEL_SERVER_HOST}:{MODEL_SERVER_PORT}" if "http" not in model_server_url: From c1fbbfa9cb1b27128e0064dd007513373d7fed84 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Fri, 30 Aug 2024 17:13:07 -0700 Subject: [PATCH 7/7] add retries --- backend/danswer/main.py | 24 ++++++++++++------------ backend/danswer/utils/gpu_utils.py | 30 ++++++++++++++++-------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/backend/danswer/main.py b/backend/danswer/main.py index 41dcc59d76c..8b660f5a9e3 100644 --- a/backend/danswer/main.py +++ b/backend/danswer/main.py @@ -206,15 +206,15 @@ def update_default_multipass_indexing(db_session: Session) -> None: logger.info(f"GPU availability: {gpu_available}") current_settings = get_current_search_settings(db_session) - if current_settings: - logger.notice(f"Updating multipass indexing setting to: {gpu_available}") - updated_settings = SavedSearchSettings.from_db_model(current_settings) - updated_settings.multipass_indexing = gpu_available - update_current_search_settings(db_session, updated_settings) - else: - logger.warning( - "No current search settings found. Skipping multipass indexing update." - ) + + logger.notice(f"Updating multipass indexing setting to: {gpu_available}") + updated_settings = SavedSearchSettings.from_db_model(current_settings) + # Enable multipass indexing if GPU is available or if using a cloud provider + updated_settings.multipass_indexing = ( + gpu_available or current_settings.cloud_provider is not None + ) + update_current_search_settings(db_session, updated_settings) + else: logger.debug( "Existing docs or connectors found. Skipping multipass indexing update." @@ -370,9 +370,6 @@ async def lifespan(app: FastAPI) -> AsyncGenerator: translate_saved_search_settings(db_session) - # update multipass indexing setting based on GPU availability - update_default_multipass_indexing(db_session) - # Does the user need to trigger a reindexing to bring the document index # into a good state, marked in the kv store mark_reindex_flag(db_session) @@ -403,6 +400,9 @@ async def lifespan(app: FastAPI) -> AsyncGenerator: ), ) + # update multipass indexing setting based on GPU availability + update_default_multipass_indexing(db_session) + optional_telemetry(record_type=RecordType.VERSION, data={"version": __version__}) yield diff --git a/backend/danswer/utils/gpu_utils.py b/backend/danswer/utils/gpu_utils.py index 5b872ffddb4..70a3dbc2c95 100644 --- a/backend/danswer/utils/gpu_utils.py +++ b/backend/danswer/utils/gpu_utils.py @@ -1,28 +1,30 @@ import requests +from retry import retry from danswer.utils.logger import setup_logger +from shared_configs.configs import INDEXING_MODEL_SERVER_HOST +from shared_configs.configs import INDEXING_MODEL_SERVER_PORT from shared_configs.configs import MODEL_SERVER_HOST from shared_configs.configs import MODEL_SERVER_PORT logger = setup_logger() -def gpu_status_request(indexing: bool = False) -> bool: - model_server_url = f"{MODEL_SERVER_HOST}:{MODEL_SERVER_PORT}" +@retry(tries=5, delay=5) +def gpu_status_request(indexing: bool = True) -> bool: + if indexing: + model_server_url = f"{INDEXING_MODEL_SERVER_HOST}:{INDEXING_MODEL_SERVER_PORT}" + else: + model_server_url = f"{MODEL_SERVER_HOST}:{MODEL_SERVER_PORT}" if "http" not in model_server_url: model_server_url = f"http://{model_server_url}" - response = requests.get(f"{model_server_url}/api/gpu-status") - - if response.status_code == 200: + try: + response = requests.get(f"{model_server_url}/api/gpu-status", timeout=10) + response.raise_for_status() gpu_status = response.json() - if gpu_status["gpu_available"]: - return True - else: - return False - else: - logger.warning( - f"Error: Unable to fetch GPU status. Status code: {response.status_code}" - ) - return False + return gpu_status["gpu_available"] + except requests.RequestException as e: + logger.error(f"Error: Unable to fetch GPU status. Error: {str(e)}") + raise # Re-raise exception to trigger a retry