Skip to content

Commit

Permalink
Minor vespa standardization (onyx-dot-app#2861)
Browse files Browse the repository at this point in the history
* minor additional standardization

* nit: typo

* k

* account for malformed params
  • Loading branch information
pablonyx authored Oct 21, 2024
1 parent a24b465 commit cee6810
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions backend/danswer/document_index/vespa/chunk_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import cast

import httpx
import requests
from retry import retry

from danswer.configs.app_configs import LOG_VESPA_TIMING_INFORMATION
Expand Down Expand Up @@ -194,20 +193,21 @@ def _get_chunks_via_visit_api(

document_chunks: list[dict] = []
while True:
response = requests.get(url, params=params)
try:
response.raise_for_status()
except requests.HTTPError as e:
request_info = f"Headers: {response.request.headers}\nPayload: {params}"
response_info = f"Status Code: {response.status_code}\nResponse Content: {response.text}"
error_base = f"Error occurred getting chunk by Document ID {chunk_request.document_id}"
filtered_params = {k: v for k, v in params.items() if v is not None}
with get_vespa_http_client() as http_client:
response = http_client.get(url, params=filtered_params)
response.raise_for_status()
except httpx.HTTPError as e:
error_base = "Failed to query Vespa"
logger.error(
f"{error_base}:\n"
f"{request_info}\n"
f"{response_info}\n"
f"Exception: {e}"
f"Request URL: {e.request.url}\n"
f"Request Headers: {e.request.headers}\n"
f"Request Payload: {params}\n"
f"Exception: {str(e)}"
)
raise requests.HTTPError(error_base) from e
raise httpx.HTTPError(error_base) from e

# Check if the response contains any documents
response_data = response.json()
Expand Down Expand Up @@ -301,17 +301,13 @@ def query_vespa(
response = http_client.post(SEARCH_ENDPOINT, json=params)
response.raise_for_status()
except httpx.HTTPError as e:
request_info = f"Headers: {response.request.headers}\nPayload: {params}"
response_info = (
f"Status Code: {response.status_code}\n"
f"Response Content: {response.text}"
)
error_base = "Failed to query Vespa"
logger.error(
f"{error_base}:\n"
f"{request_info}\n"
f"{response_info}\n"
f"Exception: {e}"
f"Request URL: {e.request.url}\n"
f"Request Headers: {e.request.headers}\n"
f"Request Payload: {params}\n"
f"Exception: {str(e)}"
)
raise httpx.HTTPError(error_base) from e

Expand Down

0 comments on commit cee6810

Please sign in to comment.