Skip to content

fix(chunker): keep the CSV two-cell QA contract on the JSON item path - #19635

Closed
devYRPauli wants to merge 1 commit into
infiniflow:mainfrom
devYRPauli:fix/qa-csv-strict-pairs-json-path
Closed

devYRPauli wants to merge 1 commit into
infiniflow:mainfrom
devYRPauli:fix/qa-csv-strict-pairs-json-path

Conversation

@devYRPauli

Copy link
Copy Markdown
Contributor

Summary

Fixes #19006 again. The fix from #19008 stopped running on main.

Python rag/app/qa.py:365 reads a CSV row as a Q&A pair only when the row holds exactly two fields. #19008 ported that rule into extractQATable as the strictPairs flag. The QA chunker set it from isCSV(upstream.Name) on the PayloadFormatHTML branch.

#19467 changed csv_parser.go to return OutputFormat: spreadsheetOutputFormat, which is "json". I checked all 30 OutputFormat: sites in internal/parser/parser and none of them is "html" now. CSV therefore lands in the default branch, which called extractQAJSON. That function hardcoded extractQATable(txt, false), so the rule stopped running and isCSV was left with no live caller.

The change passes the flag down. extractQAJSON takes strictPairs and hands it to extractQATable. The call site derives it with the existing isCSV helper.

The workbook path does not change. Python's Excel class takes the first two non-empty cells of a row, so xlsx and xls keep strictPairs false. The second new test pins that.

Measurement

CGO_ENABLED=0 go test ./internal/ingestion/component/chunker/... with TIKTOKEN_CACHE_DIR pointed at a directory holding cl100k_base. macOS arm64, Go 1.27.1. bash build.sh --test cannot run on this host because office_oxide ships a Linux x86_64 static library only, and this package is pure Go.

tree rc passing tests
main at 58035bdfe, unmodified 0 391
main plus the two new tests, fix reverted 1 392
main plus the whole change 0 393

The middle row is the mutation test. With the fix reverted, TestQAChunker_CSVJSONItemsKeepStrictPairs fails and reports two chunks:

qa_csv_strict_test.go:30: chunk 0: "问题:q1\t回答:a1"
qa_csv_strict_test.go:30: chunk 1: "问题:question\t回答:extra"
qa_csv_strict_test.go:32: want 1 pair from the two-field row, got 2

The second chunk is the defect #19006 reported. The row is question,,extra, which has three fields. TestQAChunker_XLSXJSONItemsStayLenient passes in every row of the table, so the failure is CSV only.

gofmt -l and go vet are clean on the package.

Note on #19611

#19611 rewrites this file. It re-adds the contract on its new typed row path, and its HTML fallback still calls extractQATable(txt, false). This change is two lines on the current main, so it is easy to drop or rebase when that lands.

Python qa.py:365 reads a CSV row as a Q&A pair only when the row holds
exactly two fields. infiniflow#19008 ported that rule into extractQATable as the
strictPairs flag, reached through the PayloadFormatHTML branch of the QA
chunker.

infiniflow#19467 changed csv_parser.go to return OutputFormat "json". No parser in
internal/parser/parser emits "html" any more, so CSV now lands in the
default branch, which called extractQAJSON. That function hardcoded
strictPairs false, so the rule stopped running and a row like
"question,,extra" produced a pair again.

Pass the flag down. extractQAJSON takes strictPairs and hands it to
extractQATable. The call site derives it with the existing isCSV helper,
which had no live caller left.

The workbook path is unchanged. Python's Excel class takes the first two
non-empty cells of a row, so xlsx and xls keep strictPairs false.

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

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: b2460b11-10fc-49fa-a4c5-9b50f3386c2d

📥 Commits

Reviewing files that changed from the base of the PR and between 58035bd and ab3cc0b.

📒 Files selected for processing (2)
  • internal/ingestion/component/chunker/qa.go
  • internal/ingestion/component/chunker/qa_csv_strict_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The QA chunker now passes the source format into JSON table extraction. CSV inputs use strict two-field pairing, while XLSX inputs retain lenient pairing. Tests cover both behaviors.

Changes

CSV QA pairing

Layer / File(s) Summary
Source-specific table pairing
internal/ingestion/component/chunker/qa.go, internal/ingestion/component/chunker/qa_csv_strict_test.go
extractQAJSON receives the CSV flag and forwards it to table extraction. Tests verify that CSV rows with extra fields are dropped, while XLSX rows remain accepted.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: xugangqiang

Merge Risk: ⚪ Minimal · up to ab3cc

The CSV-specific pairing change and XLSX compatibility coverage do not show an unresolved merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. 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 clearly identifies the main change: preserving the CSV two-cell QA contract on the JSON item path.
Description check ✅ Passed The description includes the required Summary section and clearly explains the defect, root cause, implementation, format-specific behavior, tests, and validation results.
Linked Issues check ✅ Passed The change satisfies #19006. The JSON path now passes isCSV(upstream.Name) to extractQAJSON. Table extraction receives this value, so CSV rows use strict pairing and question,,extra does not pro…
Out of Scope Changes check ✅ Passed The changes stay within #19006. They update QA format propagation and table extraction, and add focused CSV and XLSX regression tests. No unrelated source path or behavior is changed.
  • Fix all pre-merge checks with AI

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

I twitch my nose at pairs in line
Two CSV cells must now align
Extra fields hop away
XLSX keeps its way
A tidy burrow, neat and fine

Comment @coderabbitai help to get the list of available commands.

@devYRPauli

Copy link
Copy Markdown
Contributor Author

One more defect in the same function, found while measuring this change. It sits on main at 58035bdfe, and this PR neither causes it nor fixes it.

recordsToHTMLTableChunkList writes the header row into every chunk of a sheet at office_table_render.go:192. buildHeaderRow renders that row as <th>, and tableRows at qa.go:246 reads <th> like <td>. So in QA mode the sheet's first row becomes one pair per chunk.

Measured end to end through CSVParser and the QA chunker. The input is five rows, q0,a0 through q4,a4.

chunk_rows Go pairs Python pairs
unset 5 5
2 6 5
1 8 5

At chunk_rows: 1 the extra pairs are three more copies of q0/a0. Python reads the CSV once with csv.reader at rag/app/qa.py:359, so the first row gives one pair.

chunk_rows has no default, no UI field and no docs entry, so only a hand-written Parser DSL reaches it. I can send the fix after this PR lands, because both changes touch the same two lines in extractQAJSON.

@xugangqiang

Copy link
Copy Markdown
Contributor

pls check #19467 -- all output from parser will be in "JSON" format and decide if any changes needed for this PR.

@devYRPauli

Copy link
Copy Markdown
Contributor Author

Closing this. #19611 landed the change while it was open.

extractQAJSON on main at a3b398453 takes the file type, derives strictCSV from it, and calls extractQATable(txt, strictCSV). That is what this PR asked for.

I ran qa_csv_strict_test.go from this branch against main. TestQAChunker_XLSXJSONItemsStayLenient passes, so the CSV and workbook split holds. TestQAChunker_CSVJSONItemsKeepStrictPairs fails, and the failing assert is "drop the three-field row". #19611 appends that row to the previous answer instead of dropping it. That is a deliberate upstream choice, so the assert is out of date rather than the code.

@xugangqiang this also answers your question on #19235. #19235 is now the only open PR that touches if itemDocType(item) == "table", so the two do not conflict.

@devYRPauli devYRPauli closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QA chunker: the Go HTML table path pairs across an empty cell where the Python CSV path rejects the row

2 participants