Repository navigation
Description
Self Checks
- I have read the Contributing Guide and Language Policy.
- This is a bug report, not a usage question.
- I have searched for existing issues, including closed ones.
- I confirm I am using English to submit this report.
Dify version
main at e5acabc3d (2026-10-29)
Cloud or Self Hosted
Self Hosted (Source)
What happened?
In QA chunk mode (doc_form="qa_model"), the chunk preview / indexing-estimate endpoint returns HTTP 500 for any source that yields zero chunks, e.g. a whitespace-only text file or a blank/scanned PDF without extractable text.
api/core/rag/index_processor/processor/qa_index_processor.py:97-104 (preview branch) indexes all_documents[0] without checking that the list is non-empty:
extracted: ["' \n\n \n'"]
QA preview: IndexError: list index out of range
Paragraph preview: OK -> []
At the estimate adapter (api/services/knowledge/indexing/adapters/estimate.py:120-129) the same failure is wrapped as IndexingEstimateExecutionError: list index out of range, which the console controllers map to IndexingEstimateError → HTTP 500 Knowledge indexing estimate failed: list index out of range (controllers/console/datasets/error.py:57-60).
Non-preview QA indexing of the same empty source returns [] correctly, and paragraph-mode preview returns an empty preview list, so the failure is specific to QA preview/estimate of an empty document.
Steps To Reproduce
- Create a dataset with QA chunk mode (
doc_form="qa_model"). - Preview/estimate indexing for a whitespace-only
.txtor a blank PDF (or an image-only PDF whose images are not persisted, e.g. URL-sourced). - Observe HTTP 500 with
list index out of rangeinstead of an empty preview.
A self-contained script using the real TextExtractor / PdfExtractor and QAIndexProcessor.transform(..., preview=True) reproduces it without services (repro_qa_empty_preview.py, repro_qa_blank_pdf.py, qa_estimate_empty.py); happy to attach them.
Expected behavior
200 with an empty preview for a zero-chunk document: preview=[], qa_preview=[], total_segments=0, consistent with paragraph mode and with non-preview QA indexing.
Suggested fix
Guard the preview branch, e.g.:
if preview:
if not all_documents:
return {"preview": [], "qa_preview": [], "total_segments": 0}
...and add a regression test for empty/whitespace input in QA preview. Searched open and closed issues/PRs (EN and ZH) for QA preview / empty chunks / IndexError in knowledge indexing: no duplicate; open PR #34236 (format_preview KeyError) and merged #42205 (preview cap) are different.
Activity
dosubot commentedon Oct 29, 2026
One relevant contract detail:
QAIndexProcessor.transform()returnslist[Document], not the HTTP preview response. Its empty result should therefore be[], rather than the response-shaped dictionary in the example. The method already returnsall_qa_documentsat the end. [1] [2]The estimate adapter builds
preview,qa_preview, andtotal_segmentsitself. With an empty document list, it already produces your expected zero-segment QA response. It also processes sources individually, so a useful additional regression case is a batch containing one empty source and one non-empty source, ensuring the empty source does not prevent the other source's preview. [3] [4]To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.