Preserve CLIP client errors through qdrant

This commit is contained in:
2026-08-29 09:19:38 +02:00
parent d5faa49c47
commit 32ddf70e2f
4 changed files with 122 additions and 9 deletions
+9 -2
View File
@@ -211,6 +211,13 @@ def _log_clip_failure(operation: str, *, elapsed_ms: float, status: int | None =
logger.warning("%s", " ".join(f"{key}={value!r}" for key, value in fields.items()))
def _raise_clip_response_error(response: httpx.Response) -> None:
"""Preserve CLIP client statuses while keeping upstream detail private."""
if 400 <= response.status_code < 500:
raise HTTPException(response.status_code, "CLIP image request rejected.")
raise HTTPException(502, "CLIP service unavailable.")
async def _embed_url(url: str) -> List[float]:
"""Call the CLIP service to get an image embedding."""
started_at = time.perf_counter()
@@ -222,7 +229,7 @@ async def _embed_url(url: str) -> List[float]:
raise HTTPException(502, f"CLIP request failed: {str(e)}")
if r.status_code >= 400:
_log_clip_failure("embed_url", elapsed_ms=(time.perf_counter() - started_at) * 1000, status=r.status_code, error_type="upstream_http_error", safe_detail=_safe_clip_detail(r))
raise HTTPException(502, f"CLIP /embed error: {r.status_code} {r.text[:200]}")
_raise_clip_response_error(r)
try:
return r.json()["vector"]
except Exception:
@@ -242,7 +249,7 @@ async def _embed_bytes(data: bytes) -> List[float]:
raise HTTPException(502, f"CLIP request failed: {str(e)}")
if r.status_code >= 400:
_log_clip_failure("embed_file", elapsed_ms=(time.perf_counter() - started_at) * 1000, status=r.status_code, error_type="upstream_http_error", safe_detail=_safe_clip_detail(r))
raise HTTPException(502, f"CLIP /embed/file error: {r.status_code} {r.text[:200]}")
_raise_clip_response_error(r)
try:
return r.json()["vector"]
except Exception: