fix(llm): don't panic in rerank_topk_filter on an empty document list - #275
linhongyu510 wants to merge 1 commit into
Conversation
66d86e5 to
835987d
Compare
|
Rebased onto current The conflict was in So I kept your 0.33.0 section byte-for-byte and moved my entry to a new Three added lines, zero deletions, zero modifications. I also re-verified the defect is still live in the released 0.33.0 rather than assuming my earlier run still applied — installed That is the panic path this PR closes, reproduced on the published wheel. One blocker left that I cannot clear myself: CLA assistant still reports |
rerank_topk_filter started with
docs, scores = zip(*sorted(zip(docs, scores), ...))
zip(*[]) produces nothing to unpack, so a row whose document list is empty
raised ValueError inside the UDF. Because this runs in the engine, the failure
surfaces as a worker panic rather than a recoverable error:
thread 'pathway:work-0' panicked at src/engine/report_error.rs:152:14:
ValueError: not enough values to unpack (expected 2, got 0)
A query that matched no documents is a normal outcome, not an error, and this is
a documented public helper (llm-xpack overview points users at it for choosing
the k best documents after ranking). In a long-running streaming pipeline one
such row takes the whole pipeline down.
Return empty document and score lists for that row instead. Rows with documents
are unaffected: they still sort by score descending and truncate to k.
Also added a CHANGELOG entry under Unreleased / Fixed, matching the existing
entries that describe removed worker panics.
835987d to
1a1b1a4
Compare
|
CLA is signed now — I also rebased onto current Re-ran the two regression tests after the rebase rather than assuming the earlier run still applied: both pass against the published The |
What's wrong
rerank_topk_filter(python/pathway/xpacks/llm/rerankers.py) opens with:zip(*[])yields nothing, so unpacking into two names raisesValueErrorwhen arow's document list is empty. Because this runs inside a UDF in the engine, the
failure is not a recoverable error — it takes down the worker:
Reproduced against the real function through
pw.debug:Why it matters
A query that retrieved nothing is a normal outcome, not an error — a metadata
filter that excludes everything, a
filepath_globpatternmatching no file, afreshly started pipeline whose index is still empty. The row still exists; only
its document list is empty.
rerank_topk_filteris a documented public helper: the LLM xpack overview pointsusers at it directly ("once you rank the documents, you can use
rerank_topk_filterto choosekbest documents",docs/2.developers/4.user-guide/50.llm-xpack/10.overview.md:104). In along-running streaming deployment, one such row ends the whole pipeline.
Note this does not affect
BaseRAGQuestionAnswerer, which truncates via_limit_documents(a plain slice, safe on empty input). It affects pipelinesbuilt with the public helper as documented.
The fix
Return empty lists for that row and leave every other row alone:
Rows that do have documents still sort by score descending and truncate to
k—verified in the same run that exercises the empty row:
Tests
Two cases added to
python/pathway/xpacks/llm/tests/test_rerankers.py, followingthe existing
test_rerank_topk_filterconvention (pw.schema_from_types,table_from_rows,assert_table_equality):test_rerank_topk_filter_empty_docs— an empty row yields empty lists ratherthan panicking.
test_rerank_topk_filter_keeps_filtering_with_mixed_rows— an empty rowalongside a populated one, so the fix cannot pass by short-circuiting the
ranking for everybody.
CHANGELOG
Added an entry under
Unreleased / Fixed. The surrounding entries there describeexactly this class of change (removed worker panics), so it seemed in scope
rather than noise — happy to drop it if you'd rather keep xpack changes out of
the changelog.
Verification
Whole LLM xpack test directory, excluding
test_parsers.pywhich fails tocollect locally for a missing optional dependency — identical failure count
before and after, with exactly my two new tests added to the passing side:
Those 101 are missing optional LLM dependencies in my local environment (the
same set fails on an unmodified checkout), not regressions.
Reverse-verified: with the source change reverted and both tests kept, the two
new tests fail and the existing
test_rerank_topk_filterstill passes — so theypin this behaviour specifically, and the fix does not alter the ranking path.
AI disclosure
This change was prepared with AI assistance. The defect was found by auditing the
xpack's filtering and ranking helpers for empty-input boundaries, then confirmed
by running the real function through the engine and observing the panic; the
quoted panic text, doc reference, test counts and baseline comparison were all
produced by running the code.