Repository navigation
Fix QA DOCX table parser dropping cells between repeated text - #17497
Conversation
The merged-cell scan in qa.py's Docx handler does not stop at the first
non-matching cell. It keeps scanning the rest of the row, so any later
non-adjacent cell sharing text with the current one is folded into the
colspan and every cell in between is dropped from the generated HTML.
A row like ["Name", "", "Age", ""] - two blank cells separated by
real content, a very common table shape - renders as
<td>Name</td><td colspan='2'></td>
losing "Age" entirely. That HTML is what tokenize_table indexes, so the
content is silently missing from search results.
rag/app/manual.py, rag/app/naive.py and rag/app/laws.py all contain the
same loop with an else: break. qa.py is the only copy without it.
📝 WalkthroughWalkthroughThe Docx table parser now stops calculating a cell span when subsequent cell text differs, preventing incorrect colspan expansion. ChangesDocx table parsing
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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.
🧹 Nitpick comments (1)
rag/app/qa.py (1)
232-233: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd a regression test for
rag.app.qa.Docx.The new
breakis correct, but the supplied test exercisesrag.app.laws.Docxand only verifies adjacent identical cells. Add a focused QA-parser test coveringA, B, Aand blank cells separated by another value, while retaining the adjacent-merge assertion.As per coding guidelines, preserve still-valid behavior with focused tests.
🤖 Prompt for 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. In `@rag/app/qa.py` around lines 232 - 233, Add a focused regression test for rag.app.qa.Docx covering non-adjacent repeated cells in the A, B, A pattern and blank cells separated by another value, while retaining the existing assertion for adjacent identical-cell merging; ensure the test targets the QA parser rather than rag.app.laws.Docx.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@rag/app/qa.py`:
- Around line 232-233: Add a focused regression test for rag.app.qa.Docx
covering non-adjacent repeated cells in the A, B, A pattern and blank cells
separated by another value, while retaining the existing assertion for adjacent
identical-cell merging; ensure the test targets the QA parser rather than
rag.app.laws.Docx.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17497 +/- ##
==========================================
- Coverage 94.56% 90.65% -3.91%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 650 -28
- Misses 25 39 +14
- Partials 14 28 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
LGTM |
What problem does this PR solve?
The merged-cell scan in
rag/app/qa.py'sDocxhandler never stops at the first non-matching cell. The inner loop keeps scanning to the end of the row, so any later, non-adjacent cell that happens to share text with the current one is folded into thecolspan, and every cell in between is dropped from the generated HTML.The same loop exists in three sibling parsers, and all three break out of the scan correctly:
rag/app/manual.pyrag/app/naive.pyrag/app/laws.pyrag/app/qa.pyis the only copy missing theelse: break. The loops are otherwise identical.Impact
The most common trigger is blank cells, which routinely repeat within a row. A row like
["Name", "", "Age", ""]renders as:Ageis gone. The two blank cells are treated as a merged pair even though they are not adjacent, and the real content between them is discarded along with the cells it belonged to.This HTML is passed to
tokenize_table()in the docxchunk()path, so the dropped content is silently absent from what gets indexed and searched. There is no error and nothing in the logs.Type of change
Change
Add the
else: breakthat the three sibling parsers already have.Verification
Running the row-building loop from
qa.pyand frommanual.pyover the same inputs, before and after:Name, "", Age, ""<td>Name</td><td colspan='2'></td><td>Name</td><td></td><td>Age</td><td></td>A, B, A, D<td colspan='2'>A</td><td>D</td><td>A</td><td>B</td><td>A</td><td>D</td>M, M, X(real merge)<td colspan='2'>M</td><td>X</td>Z, Z, Z<td colspan='3'>Z</td>a, b, c<td>a</td><td>b</td><td>c</td>Genuine adjacent merges and rows without repeated text are unaffected. After the change,
qa.pyproduces byte-identical output tomanual.pyon every case above.