Skip to content

Fix Markdown parser, the table should be inside chunk - #17477

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:bugfix/table-should-be-inside-chunk
Jul 28, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:bugfix/table-should-be-inside-chunk

Conversation

@wangq8

@wangq8 wangq8 commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Follow on issue #16074 and PR #16143
Before:
image

After:
image

@wangq8 wangq8 added the ci Continue Integration label Jul 28, 2026
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Markdown 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.

Changes

Markdown table flow

Layer / File(s) Summary
Table replacement and newline normalization
deepdoc/parser/markdown_parser.py
Markdown and HTML table replacement paths render tables consistently and normalize trailing line breaks.
Naive chunk markdown integration
rag/app/naive.py
Element extraction uses the remainder, standalone table chunks require separation, and markdown parsing passes separate_tables=False.
Flow parser markdown integration
rag/flow/parser/parser.py
Markdown parsing passes separate_tables=False for flow parser output generation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: 🧪 test

Suggested reviewers: hz-186

Poem

I nudge each table into line,
With tidy breaks and HTML shine.
No extra chunks go hopping free,
The remainder holds them carefully.
Squeak! Parsing flows as smooth as tea.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks the required Summary section and only includes issue references and screenshots. Add a brief Summary section explaining the problem, the fix, and relevant background context per the template.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title matches the main change: Markdown parsing was fixed so tables stay inside chunks.

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.

@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

🧹 Nitpick comments (1)
deepdoc/parser/markdown_parser.py (1)

62-67: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add debug logging for both in-place table replacement paths.

These new separate_tables=False branches alter parser output but emit no diagnostic. Add logger.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

📥 Commits

Reviewing files that changed from the base of the PR and between 19b6013 and 8070107.

📒 Files selected for processing (3)
  • deepdoc/parser/markdown_parser.py
  • rag/app/naive.py
  • rag/flow/parser/parser.py

Comment thread deepdoc/parser/markdown_parser.py Resolved
@wangq8 wangq8 changed the title Fix Markdown parser, the table should be insider chunk Fix Markdown parser, the table should be inside chunk Jul 28, 2026
@codecov

codecov Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (8b793ee) to head (850d875).
⚠️ Report is 9 commits behind head on main.

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.
📢 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.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 → \n in 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_tables from both calls to replace_tables_with_rendered_html. This was actually a latent bug: when separate_tables=False, the old code passed render=False, meaning tables kept in the text were not rendered as HTML — they stayed as raw markdown pipe-tables. The fix defaults render=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 — since separate_tables is now always False and tables are rendered inside remainder, we should always parse from remainder.

  • tbls loop guarded by if separate_tables:: Prevents double-adding tables when they are already inside sections. 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=False change for the flow-level markdown parser. Consistent with the naive.py change. ✅

Concerns & Suggestions

  1. 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
  2. Behavioral conflict with PR #16143. That PR explicitly set separate_tables=True and 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 whether test/unit_test/deepdoc/parser/test_markdown_parser.py still passes.

  3. \n\n → \n in the skip-match branch. Even though separate_tables is now always False at the call sites, the function still supports separate_tables=True via the closure. The \n\n → \n change affects that path too — if any code path still calls extract_tables_and_remainder(separate_tables=True), the spacing around removed tables will be tighter than before. Low risk but worth noting.

  4. Caller-side separate_tables parameter. The __call__ method still accepts separate_tables=True as default parameter, but the only callers (chunk() and _markdown()) now pass separate_tables=False. Consider updating the default to False for 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.

@wangq8
wangq8 merged commit b8bb229 into infiniflow:main Jul 28, 2026
3 checks passed
wangq8 added a commit to wangq8/ragflow that referenced this pull request Jul 28, 2026
yuzhichang pushed a commit that referenced this pull request Jul 29, 2026
buua436 pushed a commit to buua436/ragflow that referenced this pull request Jul 29, 2026
buua436 pushed a commit to buua436/ragflow that referenced this pull request Jul 29, 2026
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 size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant