Skip to content

[Bug]: QA chunk preview returns HTTP 500 (IndexError) for sources with zero chunks #45087

Open

Description

@BlueX888

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

  1. Create a dataset with QA chunk mode (doc_form="qa_model").
  2. Preview/estimate indexing for a whitespace-only .txt or a blank PDF (or an image-only PDF whose images are not persisted, e.g. URL-sourced).
  3. Observe HTTP 500 with list index out of range instead 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

  1. dosubot commented on Oct 29, 2026

    @dosubot

    One relevant contract detail: QAIndexProcessor.transform() returns list[Document], not the HTTP preview response. Its empty result should therefore be [], rather than the response-shaped dictionary in the example. The method already returns all_qa_documents at the end. [1] [2]

    The estimate adapter builds preview, qa_preview, and total_segments itself. 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.

    Leave Feedback Learn about dify with Dosu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.18.0Bugs from 1.18.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions