Skip to content

fix(chunker): drop delimiter from chunk text on primary and children splits - #17868

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:fix/chunker-delim-drop
Aug 5, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:fix/chunker-delim-drop

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

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 (token_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.

This change switches 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. The now-unused splitKeepingDelim helper is removed.

Changes

  • Children split (splitByChildren / applyChildrenDelim / applyChildrenDelimText) now drops the delimiter.
  • Primary JSON split (chunkFromItem) now drops the delimiter — this also resolves the token__json_backtick parity divergence.
  • Remove dead splitKeepingDelim helper.
  • TestCustomDelimJSONKeepsNewline → TestCustomDelimJSONDropsDelimiter; add TestTokenChunker_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

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4770b7cd-ca19-4db3-99c7-b1bbae4d6ac7

📥 Commits

Reviewing files that changed from the base of the PR and between 583ba3c and c4e68f8.

📒 Files selected for processing (4)
  • internal/ingestion/component/chunker/common.go
  • internal/ingestion/component/chunker/custom_delim_test.go
  • internal/ingestion/component/chunker/token.go
  • internal/ingestion/component/chunker/token_children_delim_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • internal/ingestion/component/chunker/common.go
  • internal/ingestion/component/chunker/token_children_delim_test.go
  • internal/ingestion/component/chunker/custom_delim_test.go
  • internal/ingestion/component/chunker/token.go

📝 Walkthrough

Walkthrough

Delimiter 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 mom.

Changes

Delimiter Dropping

Layer / File(s) Summary
Delimiter removal implementation
internal/ingestion/component/chunker/common.go, internal/ingestion/component/chunker/token.go
Chunking paths now discard delimiters when creating text and child chunks.
Text and JSON delimiter tests
internal/ingestion/component/chunker/custom_delim_test.go, internal/ingestion/component/chunker/token_children_delim_test.go
Tests verify delimiter-free text and JSON chunks. JSON tests also verify complete source text in mom.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: 🧪 test

Suggested reviewers: yuzhichang, jinhai-cn, yingfeng

Poem

I nibbled delimiters away,
So clean chunks form today.
Text and JSON align,
Source memories remain fine,
Tidy pieces hop and play.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes dropping delimiters during primary and child chunk splits.
Description check ✅ Passed The description includes the required summary and provides clear context, implementation details, tests, and scope.
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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between fd6d5fa and fa11d41.

📒 Files selected for processing (4)
  • internal/ingestion/component/chunker/common.go
  • internal/ingestion/component/chunker/custom_delim_test.go
  • internal/ingestion/component/chunker/token.go
  • internal/ingestion/component/chunker/token_children_delim_test.go

Comment on lines +72 to +77
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)
}
}

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.

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

Suggested change
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.
@xugangqiang
xugangqiang force-pushed the fix/chunker-delim-drop branch from fa11d41 to c4e68f8 Compare August 5, 2026 08:34
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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.

@xugangqiang xugangqiang added the ci Continue Integration label Aug 5, 2026
@yuzhichang
yuzhichang merged commit 0227b26 into infiniflow:main Aug 5, 2026
6 checks passed
@xugangqiang
xugangqiang deleted the fix/chunker-delim-drop branch August 7, 2026 12:27
xugangqiang added a commit to xugangqiang/ragflow that referenced this pull request Aug 10, 2026
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.
xugangqiang added a commit to xugangqiang/ragflow that referenced this pull request Aug 11, 2026
…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.
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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants