Repository navigation
Fix Markdown parser, the table should be inside chunk - #17477
Conversation
📝 WalkthroughWalkthroughMarkdown table replacement now renders tables consistently and normalizes trailing newlines. Naive and flow parsers request non-separated table parsing, keeping table content within sections while adjusting element extraction and standalone table chunks. ChangesMarkdown table flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
deepdoc/parser/markdown_parser.py (1)
62-67: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd debug logging for both in-place table replacement paths.
These new
separate_tables=Falsebranches alter parser output but emit no diagnostic. Addlogger.debug(...)with the table type and match position, without logging document contents.As per coding guidelines,
**/*.py: Add logging for new flows.Also applies to: 149-154
🤖 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 `@deepdoc/parser/markdown_parser.py` around lines 62 - 67, Add logger.debug calls to both new separate_tables=False table replacement branches in the markdown parser, including the table type and match position while excluding document contents. Preserve the existing replacement behavior and use the module’s established logger.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.
Inline comments:
In `@deepdoc/parser/markdown_parser.py`:
- Around line 62-67: Update the Markdown table rendering logic in both
table-processing passes to preserve the newline separator captured before each
match. Ensure the text appended before each rendered table cannot concatenate
prose directly with the opening <table>, while retaining the existing handling
of trailing newlines and separate_tables=False.
---
Nitpick comments:
In `@deepdoc/parser/markdown_parser.py`:
- Around line 62-67: Add logger.debug calls to both new separate_tables=False
table replacement branches in the markdown parser, including the table type and
match position while excluding document contents. Preserve the existing
replacement behavior and use the module’s established logger.
🪄 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 Plus
Run ID: 4436be0b-6d5d-4305-9a9e-dea4b4187d2c
📒 Files selected for processing (3)
deepdoc/parser/markdown_parser.pyrag/app/naive.pyrag/flow/parser/parser.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17477 +/- ##
==========================================
- 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:
|
wangq8
left a comment
There was a problem hiding this comment.
PR Review — #17477: Fix Markdown parser, the table should be inside chunk
Summary
This PR flips the default behavior for markdown chunking from separate_tables=True to separate_tables=False, so tables stay inside their surrounding text chunks rather than being extracted into standalone chunks. It follows up on #16074 / #16143 but takes the opposite approach: instead of deduplicating separated tables, it keeps tables inline.
Changes: 3 files, +12 / −11. Looks clean overall, but there are a few things worth double-checking.
File-by-file
1. deepdoc/parser/markdown_parser.py
-
\n\n→\nin both table-replacement functions (border/borderless markdown + HTML). This reduces paragraph spacing around rendered tables. Sensible for the "table inside chunk" approach since you want the table to feel like part of the paragraph flow. One edge case to watch: if the markdown parser or downstream renderer relies on double-newlines for paragraph breaks, this could cause visual merging. Unlikely to be a real problem in RAGFlow chunks, but worth a quick smoke test. -
Removed
render=separate_tablesfrom both calls toreplace_tables_with_rendered_html. This was actually a latent bug: whenseparate_tables=False, the old code passedrender=False, meaning tables kept in the text were not rendered as HTML — they stayed as raw markdown pipe-tables. The fix defaultsrender=True, so tables are correctly rendered as HTML when they are kept inline. ✅
2. rag/app/naive.py
-
parsing_text = remainder if separate_tables else txt→parsing_text = remainder: Correct — sinceseparate_tablesis now alwaysFalseand tables are rendered insideremainder, we should always parse fromremainder. -
tblsloop guarded byif separate_tables:: Prevents double-adding tables when they are already insidesections. Good. -
chunk():separate_tables=True→separate_tables=False: The behavioral pivot. Tables will now live inside text chunks, providing better context at retrieval time. The tradeoff is you lose the ability to retrieve a standalone table chunk (e.g., for structured data search). This seems intentional based on the PR title.
3. rag/flow/parser/parser.py
- Same
separate_tables=True→separate_tables=Falsechange for the flow-level markdown parser. Consistent with thenaive.pychange. ✅
Concerns & Suggestions
-
Missing tests. This changes default parsing behavior — a unit test covering a markdown file with a table, verified via
chunk()(not just the parser in isolation), would give confidence that:- Tables appear exactly once in the output
- Tables are rendered as HTML inside their surrounding chunk
- No stray raw markdown pipe-tables leak through
-
Behavioral conflict with PR #16143. That PR explicitly set
separate_tables=Trueand added a regression test (test_markdown_parser.py) asserting that tables don't appear twice in chunks. This PR reverses that decision. If this PR is merged, the test added in #16143 likely needs updating (or may now be testing the wrong thing). Please check whethertest/unit_test/deepdoc/parser/test_markdown_parser.pystill passes. -
\n\n→\nin the skip-match branch. Even thoughseparate_tablesis now alwaysFalseat the call sites, the function still supportsseparate_tables=Truevia the closure. The\n\n→\nchange affects that path too — if any code path still callsextract_tables_and_remainder(separate_tables=True), the spacing around removed tables will be tighter than before. Low risk but worth noting. -
Caller-side
separate_tablesparameter. The__call__method still acceptsseparate_tables=Trueas default parameter, but the only callers (chunk()and_markdown()) now passseparate_tables=False. Consider updating the default toFalsefor consistency, or at least documenting the new expected behavior.
Verdict
The logic is sound and the duplication bug (#16074) should be resolved by this approach. The main question is architectural — whether keeping tables in chunks (this PR) or separating them (#16143) is the better UX for RAG retrieval. That is a product decision, not a code-quality one.
Request: Please run the existing test suite and confirm it passes (or update the test if needed). A small integration test for the new inline-table behavior would also be valuable.
…hunk for markdown file
…arkdown file (#17488) Porting change from #17477 python to go, parse table into chunk for markdown file Before: <img width="3606" height="1805" alt="image" src="https://github.com/user-attachments/assets/363698be-c182-40cf-a167-0f0c13a68b12" /> After: <img width="3606" height="1805" alt="image" src="https://github.com/user-attachments/assets/9d0d18cb-843e-4a1a-b176-16ac32998310" />
…hunk for markdown file (infiniflow#17488) Porting change from infiniflow#17477 python to go, parse table into chunk for markdown file Before: <img width="3606" height="1805" alt="image" src="https://github.com/user-attachments/assets/363698be-c182-40cf-a167-0f0c13a68b12" /> After: <img width="3606" height="1805" alt="image" src="https://github.com/user-attachments/assets/9d0d18cb-843e-4a1a-b176-16ac32998310" />
Follow on issue #16074 and PR #16143

Before:
After:
