Repository navigation
Fix: Excel parser emits a spurious header-only chunk at exact chunk_rows multiples - #15490
Conversation
📝 WalkthroughWalkthroughThe PR fixes a chunking boundary bug in ChangesExcel Parser Chunking Behavior
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
deepdoc/parser/excel_parser.pytest/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.
a451f05 to
12a75c5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
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.
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.
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.
What problem does this PR solve?
RAGFlowExcelParser.html()iterates(len(rows) - 1) // chunk_rows + 1times.rows[0]is the header, solen(rows) - 1is the data-row count. When that count is an exact multiple ofchunk_rows, the+ 1over-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) andrag/app/one.py. A sheet with 12/24/36… data rows (or 256/512… with the defaultchunk_rows=256) produces an extra<table><caption>…</caption><tr><th>…</th></tr></table>chunk. It is non-empty, so it passes theif _filter and gets indexed as a real (empty) chunk.Fix
Iterate
ceil(n_data / chunk_rows)times instead ofn_data // chunk_rows + 1. Addstest/unit_test/deepdoc/parser/test_excel_parser.py; the header-only-chunk cases fail before this change and pass after.Type of change
Used the Claude CLI while working on this.