Repository navigation
fix(qa): keep a comma CSV comma separated when one field holds a TAB - #20925
Conversation
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]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
LGTM --- @devYRPauli will you help to raise PR to fix go side if this issue exist at go side as well? Thank you. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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]>
|
@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
I opened #21357. It ports |
Summary
The
.csvbranches ofrag/app/qa.pyandrag/app/tag.pyread the whole file with TAB as soon as one line holds a TAB: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.pycame from my #17496, which copied it fromqa.py. Measured on0.27.xat98271fd8b(\tis a TAB):0.27.xWho wrote it?,Alice/How do I indent?,"Press\tTab"/When?,TodayPress\tTabnot quotedfirst line,alpha/"press\tTab",keys/last line,omegapress\tTabnot quotedFor the first file,
0.27.xgives one QA pair: the questionHow do I indent?,"Pressand the answerTab"\nWhen?,Today.Who wrote it?is lost.This PR adds
csv_pair_delimiter(lines)toqa.py, andtag.pyimports 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:0.27.x.csv.Errorin this read gives TAB, the delimiter that0.27.xpicks 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_delimiterdoes not fit here. It picks the delimiter that gives the most columns. It returns,for both #17496 cases,the quick, brown fox\tanimal,foxandhello world\tgreeting,demo, so it would bring back the defect that #17496 fixed.Limits:
0.27.x.Who?,Alice,, gives no QA pairs on0.27.x. With a TAB in one field,0.27.xgives 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.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:
0.27.xcodecsv.ErrorhandlingThe delimiter that the function picks on generated files, 2,000 files in each row:
0.27.xIn 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.xand this branch on 3,000 other generated files:In each of the 7 files, the only TAB is on a line with no other text.
0.27.xgives 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.xis right for 0 and this branch for 375. In 393 of the other 625, the first row holds a TAB.0.27.xtest/unit_test/rag/appI ran pytest with
--noconftest, because the stub intest/unit_test/rag/conftest.pybreaks the import ofrag.app.qawithcannot import name 'PlainParser'.ruff format --checkpasses.ruff checkgives the same 27 findings on0.27.xand this branch.The Go tag source on
mainhas the same rule incsvTagSourceDelimiter(internal/ingestion/component/tag_source.go:412). This PR does not change it.