Skip to content

Fix: Excel parser emits a spurious header-only chunk at exact chunk_rows multiples - #15490

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/excel-html-spurious-chunk
Jun 8, 2026
Merged

yingfeng merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/excel-html-spurious-chunk

Conversation

@devYRPauli

@devYRPauli devYRPauli commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

RAGFlowExcelParser.html() iterates (len(rows) - 1) // chunk_rows + 1 times. rows[0] is the header, so len(rows) - 1 is the data-row count. When that count is an exact multiple of chunk_rows, the + 1 over-counts by one: the final iteration's data slice is empty, but the header row is still appended — producing a chunk that contains only the table header and no data.

This is reachable via rag/app/naive.py (html4excel, chunk_rows=12) and rag/app/one.py. A sheet with 12/24/36… data rows (or 256/512… with the default chunk_rows=256) produces an extra <table><caption>…</caption><tr><th>…</th></tr></table> chunk. It is non-empty, so it passes the if _ filter and gets indexed as a real (empty) chunk.

data rows (chunk_rows=12) before after
12 2 chunks (1 header-only) 1
24 3 chunks (1 header-only) 2
13 2 (unchanged) 2

Fix

Iterate ceil(n_data / chunk_rows) times instead of n_data // chunk_rows + 1. Adds test/unit_test/deepdoc/parser/test_excel_parser.py; the header-only-chunk cases fail before this change and pass after.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

Used the Claude CLI while working on this.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Jun 1, 2026
@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR fixes a chunking boundary bug in RAGFlowExcelParser.html() where data row count was miscalculated, causing spurious header-only chunks when rows equaled exact multiples of chunk_rows. The fix adjusts the row count calculation and iteration logic, with new comprehensive tests validating three chunking scenarios.

Changes

Excel Parser Chunking Behavior

Layer / File(s) Summary
Chunking boundary calculation fix
deepdoc/parser/excel_parser.py
Changes chunk boundary computation to separate header from data rows using n_data_rows = len(rows) - 1, and adjusts the iteration range formula to prevent header-only chunks on exact multiples of chunk_rows.
Test module and chunking validation
test/unit_test/deepdoc/parser/test_excel_parser.py
Introduces test infrastructure that stubs optional imports and dynamically loads the parser, provides XLSX generation and chunk validation helpers, and validates three scenarios: exact-multiple input (single chunk), multiple input splitting cleanly (no spurious chunks), and non-multiple input producing expected chunks (all containing data cells).

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A header row that hid too long,
Made chunks miscount and chunks went wrong.
Now data rows are counted true,
With tests in place to see us through! 📊✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and specifically identifies the bug being fixed: the spurious header-only chunk that appears when data rows are exact multiples of chunk_rows.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description comprehensively addresses all required template sections with clear context, concrete examples, and explicit fix details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/unit_test/deepdoc/parser/test_excel_parser.py`:
- Around line 69-87: Add the required pytest priority markers to each new test
function (test_exact_multiple_does_not_emit_header_only_chunk,
test_multiple_of_chunk_rows_splits_without_spurious_chunk,
test_non_multiple_unchanged) by decorating them with the appropriate
`@pytest.mark.p1/`@pytest.mark.p2/@pytest.mark.p3 marker per test priority; ensure
pytest is imported if not already and apply the chosen marker above each
function definition.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fd79e059-637f-4ab1-a40e-80c7db4b6946

📥 Commits

Reviewing files that changed from the base of the PR and between 3aea80f and a451f05.

📒 Files selected for processing (2)
  • deepdoc/parser/excel_parser.py
  • test/unit_test/deepdoc/parser/test_excel_parser.py

The chunk loop used (len(rows) - 1) // chunk_rows + 1 iterations. When the
data-row count (len(rows) - 1, since rows[0] is the header) is an exact
multiple of chunk_rows, this over-counts by one: the final iteration's data
slice is empty but the header row is still appended, producing a chunk that
contains only the table header and no data.

This is reachable via rag/app/naive.py (html4excel, chunk_rows=12) and
rag/app/one.py: a sheet with 12/24/36... data rows (or 256/512... with the
default chunk_rows=256) yields an extra header-only chunk that is non-empty,
so it passes the `if _` filter and gets indexed.

Use ceil(n_data / chunk_rows) iterations instead. Adds
test/unit_test/deepdoc/parser/test_excel_parser.py.
@devYRPauli
devYRPauli force-pushed the fix/excel-html-spurious-chunk branch from a451f05 to 12a75c5 Compare June 1, 2026 17:43
@yingfeng yingfeng added the ci Continue Integration label Jun 2, 2026
@yingfeng
yingfeng marked this pull request as draft June 2, 2026 05:30
@yingfeng
yingfeng marked this pull request as ready for review June 2, 2026 05:30
@codecov

codecov Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (3aea80f) to head (12a75c5).
⚠️ Report is 121 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15490      +/-   ##
==========================================
- Coverage   94.56%   93.16%   -1.40%     
==========================================
  Files          10       10              
  Lines         717      717              
  Branches      118      118              
==========================================
- Hits          678      668      -10     
- Misses         25       29       +4     
- Partials       14       20       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng requested a review from KevinHuSh June 8, 2026 08:34
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 8, 2026
@yingfeng
yingfeng merged commit 14c460a into infiniflow:main Jun 8, 2026
2 checks passed
xugangqiang added a commit to xugangqiang/ragflow that referenced this pull request Sep 11, 2026
A sheet holding only its header row produced zero chunks: ExcelParser.html
derives the chunk count from the data-row count, so `range(0)` emitted nothing
and the sheet vanished. A blank template therefore indexed as an empty
document, and its column schema was lost without any warning.

Emit a captioned header-only table positioned at row 1 instead, which is what
the Go path already does (recordsToHTMLTableChunkList, nData == 0). Sheets
that do have data rows are unaffected: the existing n_data_rows > 0 branch
still avoids the spurious trailing chunk fixed in infiniflow#15490.

rag/app/one.py also calls ExcelParser.html; it now receives the header-only
table as one more section instead of nothing, which is the desired "keep the
file's content" behaviour for the One chunker.

Also document where TABLE_CHUNK_TOKENS comes from: max_length defaults to 8192
and LLMBundle truncates at 95% of it (~7782), so 4096 keeps ~2x headroom.
xugangqiang added a commit to xugangqiang/ragflow that referenced this pull request Sep 11, 2026
A sheet holding only its header row produced zero chunks: ExcelParser.html
derives the chunk count from the data-row count, so `range(0)` emitted nothing
and the sheet vanished. A blank template therefore indexed as an empty
document, and its column schema was lost without any warning.

Emit a captioned header-only table positioned at row 1 instead, which is what
the Go path already does (recordsToHTMLTableChunkList, nData == 0). Sheets
that do have data rows are unaffected: the existing n_data_rows > 0 branch
still avoids the spurious trailing chunk fixed in infiniflow#15490.

rag/app/one.py also calls ExcelParser.html; it now receives the header-only
table as one more section instead of nothing, which is the desired "keep the
file's content" behaviour for the One chunker.

Also document where TABLE_CHUNK_TOKENS comes from: max_length defaults to 8192
and LLMBundle truncates at 95% of it (~7782), so 4096 keeps ~2x headroom.
xugangqiang added a commit to xugangqiang/ragflow that referenced this pull request Sep 11, 2026
A sheet holding only its header row produced zero chunks: ExcelParser.html
derives the chunk count from the data-row count, so `range(0)` emitted nothing
and the sheet vanished. A blank template therefore indexed as an empty
document, and its column schema was lost without any warning.

Emit a captioned header-only table positioned at row 1 instead, which is what
the Go path already does (recordsToHTMLTableChunkList, nData == 0). Sheets
that do have data rows are unaffected: the existing n_data_rows > 0 branch
still avoids the spurious trailing chunk fixed in infiniflow#15490.

rag/app/one.py also calls ExcelParser.html; it now receives the header-only
table as one more section instead of nothing, which is the desired "keep the
file's content" behaviour for the One chunker.

Also document where TABLE_CHUNK_TOKENS comes from: max_length defaults to 8192
and LLMBundle truncates at 95% of it (~7782), so 4096 keeps ~2x headroom.
xugangqiang added a commit to xugangqiang/ragflow that referenced this pull request Sep 14, 2026
A sheet holding only its header row produced zero chunks: ExcelParser.html
derives the chunk count from the data-row count, so `range(0)` emitted nothing
and the sheet vanished. A blank template therefore indexed as an empty
document, and its column schema was lost without any warning.

Emit a captioned header-only table positioned at row 1 instead, which is what
the Go path already does (recordsToHTMLTableChunkList, nData == 0). Sheets
that do have data rows are unaffected: the existing n_data_rows > 0 branch
still avoids the spurious trailing chunk fixed in infiniflow#15490.

rag/app/one.py also calls ExcelParser.html; it now receives the header-only
table as one more section instead of nothing, which is the desired "keep the
file's content" behaviour for the One chunker.

Also document where TABLE_CHUNK_TOKENS comes from: max_length defaults to 8192
and LLMBundle truncates at 95% of it (~7782), so 4096 keeps ~2x headroom.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants