Repository navigation
fix(chunker): drop delimiter from chunk text on primary and children splits - #17868
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughDelimiter splitting now removes matched delimiters across common, token, child, text, and JSON chunking paths. Tests update JSON output and verify delimiter-free child chunks while preserving complete source text in ChangesDelimiter Dropping
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@internal/ingestion/component/chunker/token_children_delim_test.go`:
- Around line 72-77: Update TestTokenChunker_ChildrenDelimiterDroppedText to
assert each chunk’s mom field equals "alpha one. alpha two. alpha three."
alongside the existing text assertion, preserving the current focused per-chunk
validation.
🪄 Autofix
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: d3767d7e-c7c2-4daf-a732-6cf54d71b966
📒 Files selected for processing (4)
internal/ingestion/component/chunker/common.gointernal/ingestion/component/chunker/custom_delim_test.gointernal/ingestion/component/chunker/token.gointernal/ingestion/component/chunker/token_children_delim_test.go
| for i, w := range want { | ||
| got := chunks[i]["text"].(string) | ||
| if got != w { | ||
| t.Errorf("chunk[%d] text: want %q got %q", i, w, got) | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert mom in the text child-delimiter test.
TestTokenChunker_ChildrenDelimiterDroppedText states that each child retains its parent segment in mom, but Lines 72-77 only assert text. A regression that clears or changes mom will pass. Assert that every chunk has mom == "alpha one. alpha two. alpha three.".
As per coding guidelines, preserve still-valid behavior with focused tests.
Proposed test update
for i, w := range want {
got := chunks[i]["text"].(string)
if got != w {
t.Errorf("chunk[%d] text: want %q got %q", i, w, got)
}
+ if m, _ := chunks[i]["mom"].(string); m != "alpha one. alpha two. alpha three." {
+ t.Errorf("chunk[%d] mom: want %q got %q", i, "alpha one. alpha two. alpha three.", m)
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| for i, w := range want { | |
| got := chunks[i]["text"].(string) | |
| if got != w { | |
| t.Errorf("chunk[%d] text: want %q got %q", i, w, got) | |
| } | |
| } | |
| for i, w := range want { | |
| got := chunks[i]["text"].(string) | |
| if got != w { | |
| t.Errorf("chunk[%d] text: want %q got %q", i, w, got) | |
| } | |
| if m, _ := chunks[i]["mom"].(string); m != "alpha one. alpha two. alpha three." { | |
| t.Errorf("chunk[%d] mom: want %q got %q", i, "alpha one. alpha two. alpha three.", m) | |
| } | |
| } |
🤖 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 `@internal/ingestion/component/chunker/token_children_delim_test.go` around
lines 72 - 77, Update TestTokenChunker_ChildrenDelimiterDroppedText to assert
each chunk’s mom field equals "alpha one. alpha two. alpha three." alongside the
existing text assertion, preserving the current focused per-chunk validation.
Source: Coding guidelines
…splits
Go's TokenChunker kept the captured delimiter glued to the preceding
segment on both the primary (chunkFromItem) and secondary
(children_delimiters) split paths, while Python's reference
token_chunker drops it via _split_text_by_pattern
(tok_chunker.py:79-93, used by both _build_json_chunks and
_split_chunk_docs_by_children). The divergence leaked the delimiter
into every emitted chunk's text.
Switch the four split call sites to splitDroppingDelim so chunk text
reads 'first sentence here' without the trailing delimiter, matching
Python. The full source is still preserved in the 'mom' key. Remove
the now-unused splitKeepingDelim helper.
- Children split (splitByChildren / applyChildrenDelim /
applyChildrenDelimText) now drops the delimiter.
- Primary JSON split (chunkFromItem) now drops the delimiter, which
also resolves the token__json_backtick parity divergence.
- Update TestCustomDelimJSONKeepsNewline -> TestCustomDelimJSONDropsDelimiter
and add TestTokenChunker_ChildrenDelimiterDropped{JSON,Text} (TDD).
Python side is intentionally untouched; this aligns Go to the existing
Python reference.
fa11d41 to
c4e68f8
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
After rebasing onto upstream/main (which merged infiniflow#17739/infiniflow#17835/infiniflow#17854/infiniflow#17868): - Remove 4 go_bug rules now resolved by merged fixes: token-json-per-item-merge, token-json-custom-delim-drops-newline, token-json-single-item-oversize, token-text-overlap-split. - Delete their go_snapshot files; also drop 4 orphaned tokenizer go_snapshot files that the harness never reads (strict-compare path). - Refresh the 3 remaining ratcheted snapshots for token-custom-delim-newline-and-field (html/markdown/text_backtick), whose Go output shifted under the merged delimiter/children-split fixes but the divergence itself persists. The 4 tokenizer-count cases (text/html/markdown_default_delim, text_token_liveness) now match the Python golden strict-compare with no rule, i.e. the tokenizer count mismatch is resolved. Harness is green under both plain and -update runs.
…wline-and-field The rule reason described pre-infiniflow#17868 behaviour: Go kept the backtick delimiter via splitKeepingDelim. Since infiniflow#17868 Go uses splitDroppingDelim on both the text/markdown/html and JSON paths, so chunk text now matches Python exactly. The only remaining divergence is the extra doc_type_kwd:'text' field Go emits on this path, which Python's text-path output never includes. Update the reason and tracking note to reflect the single Go-only field.
Summary
Go's
TokenChunkerkept the captured delimiter glued to the preceding segment on both the primary (chunkFromItem) and secondary (children_delimiters) split paths, while Python's referencetoken_chunkerdrops it via_split_text_by_pattern(token_chunker.py:79-93, used by both_build_json_chunksand_split_chunk_docs_by_children). The divergence leaked the delimiter into every emitted chunk'stext.This change switches the four split call sites to
splitDroppingDelimso chunktextreadsfirst sentence herewithout the trailing delimiter, matching Python. The full source is still preserved in themomkey. The now-unusedsplitKeepingDelimhelper is removed.Changes
splitByChildren/applyChildrenDelim/applyChildrenDelimText) now drops the delimiter.chunkFromItem) now drops the delimiter — this also resolves thetoken__json_backtickparity divergence.splitKeepingDelimhelper.TestCustomDelimJSONKeepsNewline→TestCustomDelimJSONDropsDelimiter; addTestTokenChunker_ChildrenDelimiterDropped{JSON,Text}(TDD: written failing, then made green).Test plan
bash build.sh --test ./internal/ingestion/component/chunker/— all pass, including the new children/primary delimiter-drop tests and the existing children-delimiter count test.Scope
Go-side only. The Python reference (
rag/flow/chunker/token_chunker.py) is intentionally untouched; this PR aligns the Go implementation to the existing Python behavior.🤖 Generated with CodeBuddy Code