Skip to content

fix(qa): keep a comma CSV comma separated when one field holds a TAB - #20925

Merged
yuzhichang merged 3 commits into
infiniflow:0.27.xfrom
devYRPauli:fix/csv-delimiter-any-tab
Oct 20, 2026
Merged

yuzhichang merged 3 commits into
infiniflow:0.27.xfrom
devYRPauli:fix/csv-delimiter-any-tab

Conversation

@devYRPauli

Copy link
Copy Markdown
Contributor

Summary

The .csv branches of rag/app/qa.py and rag/app/tag.py read the whole file with TAB as soon as one line holds a TAB:

delimiter = "\t" if any("\t" in line for line in lines) else ","

A comma separated file with one TAB inside one field then reads every row as one field. The QA chunker reports those rows as failures or appends them to an answer. The tag chunker adds them to the content of the next chunk, or drops them at the end of the file. The rule in tag.py came from my #17496, which copied it from qa.py. Measured on 0.27.x at 98271fd8b (\t is a TAB):

file chunker 0.27.x this branch
Who wrote it?,Alice / How do I indent?,"Press\tTab" / When?,Today QA 1 garbled pair 3 pairs
the same file with Press\tTab not quoted QA 1 garbled pair 3 pairs
first line,alpha / "press\tTab",keys / last line,omega tag 0 chunks 3 chunks
the same file with press\tTab not quoted tag 1 garbled chunk 3 chunks

For the first file, 0.27.x gives one QA pair: the question How do I indent?,"Press and the answer Tab"\nWhen?,Today. Who wrote it? is lost.

This PR adds csv_pair_delimiter(lines) to qa.py, and tag.py imports it. The function reads the file once with a comma. It keeps TAB, the delimiter that both docstrings name, unless the file reads as comma separated:

  • A file with no TAB reads with a comma, as before.
  • TAB wins when the first non-empty row holds a TAB. A file in the documented format therefore reads as on 0.27.x.
  • TAB wins when a row with a TAB does not split into exactly two values at its commas.
  • Otherwise a comma wins only when the two-value rows with no TAB outnumber all other rows.
  • A csv.Error in this read gives TAB, the delimiter that 0.27.x picks for the file.

A rule that counts the two-value rows under each delimiter is not safe. A TAB file with commas in its continuation lines gets more two-value rows from a comma. On 2,000 generated TAB files with multi-line answers, that rule picked a comma for 737.

deepdoc.parser.excel_parser.detect_csv_delimiter does not fit here. It picks the delimiter that gives the most columns. It returns , for both #17496 cases, the quick, brown fox\tanimal,fox and hello world\tgreeting,demo, so it would bring back the defect that #17496 fixed.

Limits:

  • A comma separated file whose first row holds a TAB still reads with TAB, as on 0.27.x.
  • In a TAB file, the first non-empty row can hold no TAB, for example a title line or the first line of a multi-line record. If its lines with one comma then outnumber its records, it now reads with a comma. This happened in 4 of 2,000 generated files with a title line.
  • The QA chunker needs exactly two fields in each row, empty fields included. A comma file with an empty column, such as Who?,Alice,, gives no QA pairs on 0.27.x. With a TAB in one field, 0.27.x gives one garbled pair and this branch gives no pairs. The tag chunker skips empty fields, so this branch fixes the same tag file.

Tests:

  • test_qa_csv.py: a TAB inside a comma separated field, quoted, not quoted, and in a CRLF export. A TAB file with a comma in the question. A TAB file with an unclosed quote after a comma, followed by 20,000 rows. Two TAB files with commas in continuation lines, one quoted and one after a title line. A comma file with continuation lines and no TAB.
  • New test_tag_csv.py: a TAB inside a comma separated field, quoted, not quoted, and with a trailing empty column. The two Fix tag CSV parser ignoring the documented TAB delimiter #17496 cases, a TAB file with a trailing TAB, and two TAB files with a title line.

Each part of the function has a test that fails without it:

change failing tests
0.27.x code 6
no first-row check 1
no two-value check on rows with a TAB 1
a tie goes to comma 1
rows with a TAB count as two-value rows 2
no csv.Error handling 1
count all fields instead of non-empty fields 1
count empty rows 1
no check for a file with no TAB 1

The delimiter that the function picks on generated files, 2,000 files in each row:

files right, 0.27.x right, this branch
TAB, one line per record 2,000 2,000
TAB, multi-line answers 2,000 2,000
TAB, Excel "Unicode Text" export 2,000 2,000
TAB tag files 2,000 2,000
TAB tag files with a title line 2,000 2,000
TAB, multi-line answers and a title line 2,000 1,996
comma QA, a TAB in a quoted field 0 1,571
comma QA, a TAB in a field with no quotes 0 1,585
comma QA, Excel CSV export 150 1,633
comma tag files, a TAB in the content 0 1,618

In the Excel CSV row, 150 files hold no TAB, and both branches read them with a comma.

I compared the full chunker output of 0.27.x and this branch on 3,000 other generated files:

files QA output changed tag output changed
1,500 with no TAB 0 0
the same 1,500 with the no-TAB check removed 776 602
1,500 with a TAB 7 7

In each of the 7 files, the only TAB is on a line with no other text. 0.27.x gives no pair or one garbled pair. This branch gives one pair for each row with a comma.

A third set checks the output against the expected pairs. 1,000 TAB files give the right QA pairs and tags on both branches. On 1,000 comma files where 2 in 5 questions hold a TAB, 0.27.x is right for 0 and this branch for 375. In 393 of the other 625, the first row holds a TAB.

run 0.27.x this branch
test/unit_test/rag/app 103 passed 119 passed

I ran pytest with --noconftest, because the stub in test/unit_test/rag/conftest.py breaks the import of rag.app.qa with cannot import name 'PlainParser'. ruff format --check passes. ruff check gives the same 27 findings on 0.27.x and this branch.

The Go tag source on main has the same rule in csvTagSourceDelimiter (internal/ingestion/component/tag_source.go:412). This PR does not change it.

devYRPauli and others added 3 commits October 13, 2026 16:53
The .csv branches of rag/app/qa.py and rag/app/tag.py read the whole
file with TAB as soon as one line holds a TAB. A comma separated file
with one TAB inside a field then reads every other row as one field.
A 3-pair QA file gave 1 garbled pair, and a 3-row tag file gave 1
garbled chunk.

Count the rows that hold exactly two values under each delimiter and
use TAB unless comma gives more. A tie goes to TAB, the documented
delimiter. A file with no TAB still reads with a comma, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commit counted the two-value rows under each delimiter.
A TAB file with commas in its continuation lines then read with a
comma, because each continuation line splits into two values at its
comma. A quoted multi-line answer with commas did the same. On 2,000
generated TAB files with unquoted multi-line answers, that rule picked
a comma for 737.

Read the file once with a comma instead. Use TAB when a row with a
TAB is the first non-empty row, or does not split into exactly two
values. Use a comma only when the two-value rows with no TAB outnumber
all other rows. A csv.Error now gives TAB, as on 0.27.x, so the main
loop still raises it.

A file whose first row holds a TAB now reads as on 0.27.x. The
previous message said that a 3-row tag file gave 1 garbled chunk on
0.27.x. That is true when the TAB field has no quotes. With the field
quoted, 0.27.x gives no chunk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The docstring of csv_pair_delimiter said "first row" and did not
name the shortcut for a file with no TAB. The function skips rows
with no non-empty value, and a file with no TAB reads with a comma
before any count.

This also corrects two sentences in the previous commit message:

- "A file whose first row holds a TAB now reads as on 0.27.x" holds
  for the first non-empty row. A file that starts with a line that
  holds only a TAB can now read with a comma.
- "A csv.Error now gives TAB, as on 0.27.x, so the main loop still
  raises it" means that a csv.Error in the comma read gives TAB, the
  delimiter that 0.27.x picks for that file. The main loop then
  reads the file as 0.27.x does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 90a71aa6-215d-4531-8c46-ed0922f67cd8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@wangq8
wangq8 requested a review from xugangqiang October 19, 2026 09:54
@xugangqiang xugangqiang added the ci Continue Integration label Oct 20, 2026
@xugangqiang

Copy link
Copy Markdown
Contributor

LGTM --- @devYRPauli will you help to raise PR to fix go side if this issue exist at go side as well? Thank you.

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.12%. Comparing base (d3ebbdd) to head (c6c994e).
⚠️ Report is 27 commits behind head on 0.27.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           0.27.x   #20925      +/-   ##
==========================================
+ Coverage   37.97%   38.12%   +0.14%     
==========================================
  Files          54       54              
  Lines       15527    15543      +16     
  Branches      125      125              
==========================================
+ Hits         5896     5925      +29     
+ Misses       9603     9590      -13     
  Partials       28       28              

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

@yuzhichang
yuzhichang merged commit 5842911 into infiniflow:0.27.x Oct 20, 2026
4 checks passed
devYRPauli added a commit to devYRPauli/devYRPauli that referenced this pull request Oct 22, 2026
Merged external pull requests: 137 -> 143 across 36 -> 37 projects
(huggingface/peft#4015, infiniflow/ragflow#20925, #20926, #20927, #20928,
sqlfluff/sqlfluff#8620). Open: 62 -> 55. Upstream issues: 23 -> 20.

Table rows that moved: RAGFlow 26 -> 30. PEFT is new at 22k stars, above
the table's 10k floor, with 1 merge.

The table now covers 89 merges across 14 projects, so the remainder is 54
across 23.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@devYRPauli

Copy link
Copy Markdown
Contributor Author

@xugangqiang Yes. The Go tag source has the same defect, and the Go QA chunker does not. I measured the files from this PR on main at 4fd8c439a (\t is a TAB):

Go path file main expected
tag source .csv, csvTagSourceDelimiter first line,alpha / "press\tTab",keys / last line,omega 0 examples 3 examples
tag source .csv, csvTagSourceDelimiter the same file with press\tTab not quoted 1 garbled example 3 examples
tag source .csv, csvTagSourceDelimiter the same file with a trailing empty column 0 examples 3 examples
QA .csv, CSV parser then QA chunker Who wrote it?,Alice / How do I indent?,"Press\tTab" / When?,Today 3 pairs 3 pairs
QA .csv, CSV parser then QA chunker the same file with Press\tTab not quoted, and the same file with CRLF 3 pairs 3 pairs
QA text, detectDelimiter the same three QA files 3 pairs 3 pairs

csvTagSourceDelimiter in internal/ingestion/component/tag_source.go picks TAB as soon as the file holds one TAB. The CSV parser picks the delimiter that gives the same column count on every row. detectDelimiter counts the two-value rows for each delimiter. Both pick comma for these QA files.

I opened #21357. It ports csv_pair_delimiter from this PR to csvTagSourceDelimiter and adds the tag test cases from this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants