Skip to content

Fix tag CSV parser ignoring the documented TAB delimiter - #17496

Merged
xugangqiang merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/tag-csv-tab-delimiter
Jul 29, 2026
Merged

xugangqiang merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/tag-csv-tab-delimiter

Conversation

@devYRPauli

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

rag/app/tag.py documents TAB as the delimiter that separates content from tags:

If it's in csv format, it should be UTF-8 encoded. Use TAB as delimiter to separate content and tags.

The .csv branch does not honour that. It calls csv.reader with no delimiter argument, so it always splits on commas regardless of the file's actual delimiter. Two failure modes follow for a genuinely TAB-delimited file:

  1. The line is silently dropped. If the content field contains a comma, the row splits into three fields, fails the len(row) == 2 check, and is discarded.

    the quick, brown fox<TAB>animal,fox -> no rows parsed at all.

  2. Content and tags are corrupted. If only the tag field contains a comma, the row splits into exactly two fields by coincidence. The tab and the first tag are left inside the content, and that tag is lost.

    hello world<TAB>greeting,demo -> content hello world\tgreeting, tags ["demo"].

rag/app/qa.py already solves this for its own .csv branch. tag.py is its near-twin and was simply missing the same line.

Type of change

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

Change

Detect the delimiter exactly as qa.py does, and pass it to csv.reader:

delimiter = "\t" if any("\t" in line for line in lines) else ","
reader = csv.reader((line + "\n" for line in lines), delimiter=delimiter)

Verification

Parsing the two cases above through the .csv branch, before and after:

Input Before After
the quick, brown fox<TAB>animal,fox [] (row dropped) ("the quick, brown fox", "animal,fox")
hello world<TAB>greeting,demo ("hello world\tgreeting", "demo") ("hello world", "greeting,demo")
some content,tag1 (plain CSV) ("some content", "tag1") unchanged

Plain comma-delimited files are unaffected.

Note on the heuristic

This mirrors qa.py deliberately, so the two twins stay consistent. It is worth being explicit that the heuristic is permissive: a single tab anywhere in the file switches the whole file to TAB parsing, so a comma-delimited file containing one stray tab inside a quoted field would be misread. That tradeoff already exists in qa.py today and is not introduced here. If you would prefer a stricter test, the .txt branch in this same file uses a majority-vote comparison instead, and I am happy to switch both parsers to that in a follow-up.

rag/app/tag.py documents TAB as the delimiter separating content from
tags, but the .csv branch calls csv.reader without a delimiter argument,
so it always splits on commas.

A TAB-delimited file whose content field contains a comma splits into
three fields, fails the len(row) == 2 check and is silently dropped. If
only the tag field contains a comma the line splits into two fields by
coincidence, leaving the tab and the first tag inside the content and
dropping that tag.

Detect the delimiter the same way rag/app/qa.py already does for its own
.csv branch. Plain comma-delimited files are unaffected.
@dosubot dosubot Bot added size:XS This PR changes 0-9 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

CSV parsing now detects tab-separated versus comma-separated input before constructing csv.reader, while preserving the existing chunk and tag extraction flow.

Changes

CSV Parsing

Layer / File(s) Summary
Detect delimiter before CSV parsing
rag/app/tag.py
CSV input selects a tab or comma delimiter, initializes res, and passes the delimiter to csv.reader.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

I’m a rabbit with tabs in my hay,
Commas now guide the CSV way.
Rows hop in line,
Tags fall just fine,
And chunks bloom brighter each day.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change to the tag CSV parser.
Description check ✅ Passed The description provides clear context, change details, and verification, though it doesn't use the exact template heading.
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.

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: 2

🤖 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 `@rag/app/tag.py`:
- Around line 95-100: Add a module-level logger and log the delimiter selected
by the parser immediately after the delimiter assignment in the CSV parsing
flow. Include only the selected delimiter in the debug or info message, and do
not log input lines or file contents.
- Around line 95-100: Update delimiter detection in the CSV parsing flow around
csv.reader so it does not inspect raw tab characters before quote parsing;
determine whether tabs or commas form the actual field separator while
respecting quoted fields, preserving correct content/tag pairs for quoted tabs
and commas. Add regression coverage for both quoted-tab and quoted-comma rows.
🪄 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: a356f943-82f0-4f36-9edd-d577f523c1a1

📥 Commits

Reviewing files that changed from the base of the PR and between 75836cf and b060e51.

📒 Files selected for processing (1)
  • rag/app/tag.py

Comment thread rag/app/tag.py
Comment on lines +95 to +100
delimiter = "\t" if any("\t" in line for line in lines) else ","

fails = []
content = ""
res = []
reader = csv.reader((line + "\n" for line in lines))
reader = csv.reader((line + "\n" for line in lines), delimiter=delimiter)

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add logging for the new delimiter-selection flow.

This new parser mode is not observable. Add a module logger and record the selected delimiter at debug/info level without logging file contents.

🤖 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 `@rag/app/tag.py` around lines 95 - 100, Add a module-level logger and log the
delimiter selected by the parser immediately after the delimiter assignment in
the CSV parsing flow. Include only the selected delimiter in the debug or info
message, and do not log input lines or file contents.

Source: Coding guidelines


🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Do not infer the delimiter from any raw tab character.

any("\t" in line for line in lines) runs before CSV quoting is interpreted, so a comma-delimited row such as "alpha\tbeta",tag is incorrectly classified as TAB-delimited. csv.reader then sees the row as one field, causing it to be accumulated or dropped instead of producing a content/tag pair. Detect the delimiter from CSV structure and add regression coverage for quoted tabs and quoted commas.

🤖 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 `@rag/app/tag.py` around lines 95 - 100, Update delimiter detection in the CSV
parsing flow around csv.reader so it does not inspect raw tab characters before
quote parsing; determine whether tabs or commas form the actual field separator
while respecting quoted fields, preserving correct content/tag pairs for quoted
tabs and commas. Add regression coverage for both quoted-tab and quoted-comma
rows.

@yingfeng yingfeng added the ci Continue Integration label Jul 29, 2026
@yingfeng
yingfeng requested a review from xugangqiang July 29, 2026 08:39
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (75836cf) to head (b060e51).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17496      +/-   ##
==========================================
- 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.

@xugangqiang

Copy link
Copy Markdown
Contributor

LGTM

@xugangqiang
xugangqiang merged commit c3aa805 into infiniflow:main Jul 29, 2026
9 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 size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants