fix(chunk-context): address PR #767 round-3 review — gate readability + legacy-fallback comment
- search/context.py: rename triple-negation gate condition to `skip_offset_lookup` named boolean for readability; convert new logger.warning to lazy %-style per repo convention. - api/visualization.py, auth/viz_routes.py: add comment on the offset-only Qdrant scroll branch noting it is a legacy path for pre-astrolabe#75 clients and degrades gracefully on Qdrant Cloud strict mode. Reviewer item #2 (extracting the duplicated scroll block into a shared helper) deferred to a follow-up issue per the reviewer's "not blocking" framing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
058463ee87
commit
47b0b737b6
@@ -601,6 +601,12 @@ async def get_chunk_context(request: Request) -> JSONResponse:
|
|||||||
with_payload=["chunk_bbox", "page_number"],
|
with_payload=["chunk_bbox", "page_number"],
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# Legacy fallback for clients that don't send chunk_index
|
||||||
|
# (pre-cbcoutinho/astrolabe#75). chunk_start/end_offset
|
||||||
|
# aren't indexed in Qdrant Cloud strict mode, so this
|
||||||
|
# call may fail with HTTP 400 there; the outer except
|
||||||
|
# logs a warning and the response degrades gracefully
|
||||||
|
# (no chunk_bbox).
|
||||||
points_response = await qdrant_client.scroll(
|
points_response = await qdrant_client.scroll(
|
||||||
collection_name=settings.get_collection_name(),
|
collection_name=settings.get_collection_name(),
|
||||||
scroll_filter=Filter(
|
scroll_filter=Filter(
|
||||||
|
|||||||
@@ -659,6 +659,12 @@ async def chunk_context_endpoint(request: Request) -> JSONResponse:
|
|||||||
with_payload=["chunk_bbox", "page_number"],
|
with_payload=["chunk_bbox", "page_number"],
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# Legacy fallback for clients that don't send chunk_index
|
||||||
|
# (pre-cbcoutinho/astrolabe#75). chunk_start/end_offset
|
||||||
|
# aren't indexed in Qdrant Cloud strict mode, so this
|
||||||
|
# call may fail with HTTP 400 there; the outer except
|
||||||
|
# logs a warning and the response degrades gracefully
|
||||||
|
# (no chunk_bbox).
|
||||||
points_response = await qdrant_client.scroll(
|
points_response = await qdrant_client.scroll(
|
||||||
collection_name=settings.get_collection_name(),
|
collection_name=settings.get_collection_name(),
|
||||||
scroll_filter=Filter(
|
scroll_filter=Filter(
|
||||||
|
|||||||
@@ -283,12 +283,13 @@ async def get_chunk_with_context(
|
|||||||
chunk_text = await _get_chunk_by_index_from_qdrant(
|
chunk_text = await _get_chunk_by_index_from_qdrant(
|
||||||
user_id, doc_id_int, doc_type, chunk_index
|
user_id, doc_id_int, doc_type, chunk_index
|
||||||
)
|
)
|
||||||
# Skip the offset fallback for files when the indexed lookup was
|
# Skip the offset fallback for files when the indexed chunk_index
|
||||||
# already attempted: Qdrant Cloud's strict mode requires an index on
|
# lookup already ran: chunk_start/end_offset aren't indexed in Qdrant
|
||||||
# filtered fields, and chunk_start/end_offset aren't indexed there, so
|
# Cloud strict mode, so the call returns 400 and surfaces a misleading
|
||||||
# the call returns 400 and surfaces a misleading logger.error. The
|
# logger.error. The file fast-fail below correctly handles the miss
|
||||||
# file fast-fail below correctly handles the miss without it.
|
# without it.
|
||||||
if chunk_text is None and not (chunk_index is not None and doc_type == "file"):
|
skip_offset_lookup = chunk_index is not None and doc_type == "file"
|
||||||
|
if chunk_text is None and not skip_offset_lookup:
|
||||||
chunk_text = await _get_chunk_from_qdrant(
|
chunk_text = await _get_chunk_from_qdrant(
|
||||||
user_id, doc_id_int, doc_type, chunk_start, chunk_end
|
user_id, doc_id_int, doc_type, chunk_start, chunk_end
|
||||||
)
|
)
|
||||||
@@ -394,9 +395,12 @@ async def get_chunk_with_context(
|
|||||||
# (the chunk has been removed or re-indexed with different offsets).
|
# (the chunk has been removed or re-indexed with different offsets).
|
||||||
if doc_type == "file":
|
if doc_type == "file":
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Chunk not found in Qdrant for file {doc_id} "
|
"Chunk not found in Qdrant for file %s (chunk_index=%s, "
|
||||||
f"(chunk_index={chunk_index}, offsets={chunk_start}-{chunk_end}); "
|
"offsets=%s-%s); skipping slow PDF re-parse fallback",
|
||||||
"skipping slow PDF re-parse fallback"
|
doc_id,
|
||||||
|
chunk_index,
|
||||||
|
chunk_start,
|
||||||
|
chunk_end,
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user