Skip to content

fix: deduplicate markdown table chunks - #16143

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
helloxjade:fix-16074-md-table-dedup
Jun 24, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
helloxjade:fix-16074-md-table-dedup

Conversation

@helloxjade

@helloxjade helloxjade commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

When markdown tables are extracted as standalone chunks, the original markdown text is still parsed from the full document content. As a result, the same table content can appear twice in chunk results: once as a dedicated table chunk, and again inside regular text chunks.

This PR fixes that duplication by parsing markdown text from the table-stripped remainder when table separation is enabled. It also enables separated table extraction in the markdown chunking entry points and adds a regression test for pipe-table duplication.

Closes #16074.

Type of change

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

Testing

  • Added/updated tests
  • Verified with:
    • python -m pytest -q test/unit_test/deepdoc/parser/test_markdown_parser.py

Additional context

I also verified the fix manually in the chunk preview UI. After the change, duplicated table chunks no longer appear
Uploading CleanShot 2026-06-17 at 16.11.54@2x.png…

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Jun 17, 2026
@helloxjade

Copy link
Copy Markdown
Contributor Author

This PR is ready for review and the fix has been validated locally.
Please let me know if I should adjust anything else.

@helloxjade

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Enables separate_tables=True in the Markdown parser call sites in rag/app/naive.py and rag/flow/parser/parser.py. Inside Markdown.__call__, element extraction and image URL extraction are redirected to use the table-stripped remainder text instead of the full txt, preventing tables from being processed twice. A new unit test verifies this deduplication behavior.

Changes

Markdown Table Deduplication Fix

Layer / File(s) Summary
Enable separate_tables at parser call sites
rag/flow/parser/parser.py, rag/app/naive.py
Both Markdown parser invocations now pass separate_tables=True (previously False), activating table separation end-to-end in chunking and flow parsing.
Align element and image extraction to remainder text
rag/app/naive.py
Markdown.__call__ computes a shared parsing_text — the remainder when separate_tables is enabled, otherwise the full txt — and feeds it to both MarkdownElementExtractor and extract_image_urls_with_lines, so table content is not re-processed.
Unit test for table deduplication
test/unit_test/deepdoc/parser/test_markdown_parser.py
Adds markdown_parser_module fixture (stubs missing markdown dependency) and TestMarkdownTableDedup test that calls extract_tables_and_remainder with separate_tables=True, asserting one table extracted, pipe-table markup absent from remainder, and sections containing "Before"/"After" but not table rows.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size:M

Poem

🐰 Hop hop, the table was seen twice before,
A duplicate chunk that rattled the floor!
Now remainder steers both image and text,
separate_tables=True puts the bug to rest.
One table, one copy — the rabbit approves! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% 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 title 'fix: deduplicate markdown table chunks' clearly and concisely describes the main change addressing markdown table duplication.
Linked Issues check ✅ Passed The PR fully addresses the objectives from issue #16074 by eliminating markdown table duplication through table-stripped remainder parsing and enabled separated table extraction.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing markdown table duplication: modifying parsing logic and adding regression tests, with no extraneous modifications.
Description check ✅ Passed The PR description provides a clear problem statement, identifies the root cause, explains the fix, specifies the change type, includes testing validation, and references a related issue.

✏️ 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.

@yingfeng yingfeng added the ci Continue Integration label Jun 23, 2026
@yingfeng
yingfeng marked this pull request as draft June 23, 2026 13:33
@yingfeng
yingfeng marked this pull request as ready for review June 23, 2026 13:33
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (a70c7e8) to head (5f9cf02).
⚠️ Report is 59 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16143   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ 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 wangq8 June 24, 2026 02:18
@wangq8
wangq8 merged commit 1b2da64 into infiniflow:main Jun 24, 2026
8 of 12 checks passed
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 🌈 python Pull requests that update Python code size:S This PR changes 10-29 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question]: Why are the tables in the Markdown file parsed into two copies?

3 participants