Skip to content

fix(chunker): glue delimiter to preceding segment instead of emitting it as a standalone chunk - #17168

Merged
xugangqiang merged 2 commits into
infiniflow:mainfrom
euvre:fix/chunker-delimiter-standalone-chunk
Jul 23, 2026
Merged

xugangqiang merged 2 commits into
infiniflow:mainfrom
euvre:fix/chunker-delimiter-standalone-chunk

Conversation

@euvre

@euvre euvre commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

In Go mode, the ingestion TokenChunker emitted the configured delimiter (e.g. 666) as its own chunk: splitKeepingDelim kept each matched delimiter as a standalone element in the split stream, and every caller emitted stream elements as chunks directly.

This PR mirrors Python token_chunker._split_text_by_pattern (rag/flow/chunker/token_chunker.py): each delimiter is glued to the end of the preceding text segment, and a delimiter with no preceding text (a leading delimiter or one adjacent to another) is dropped together with the empty segment. The delimiter therefore never surfaces as a standalone chunk, matching the Python-mode behavior.

A regression test (TestTokenChunker_DelimNeverStandaloneChunk) covers the standalone-delimiter case.

… it as a standalone chunk

splitKeepingDelim kept each matched delimiter as its own element in the
output stream, and every caller emitted stream elements as chunks
directly, so a custom delimiter (e.g. `666`) surfaced as a chunk
containing only the delimiter text.

Mirror Python token_chunker._split_text_by_pattern: each delimiter is
appended to the end of the preceding text segment, and a delimiter with
no preceding text (leading or adjacent delimiters) is dropped together
with the empty segment. Adds a regression test covering the standalone
delimiter case.
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 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

Run ID: 7057e889-48f8-4a3f-aa45-4e67503d798c

📥 Commits

Reviewing files that changed from the base of the PR and between 87417d0 and 952f156.

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

📝 Walkthrough

Walkthrough

Delimiter splitting now attaches matched delimiters to preceding text and ignores standalone or adjacent delimiter matches. A regression test verifies the expected two-chunk output for delimiter 666.

Changes

Delimiter chunking

Layer / File(s) Summary
Split delimiters and validate chunk boundaries
internal/ingestion/component/chunker/common.go, internal/ingestion/component/chunker/token_test.go
splitKeepingDelim uses delimiter match indices to preserve delimiters with preceding text, and the regression test verifies that no standalone delimiter chunk is produced.

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

Suggested reviewers: yuzhichang

Poem

I’m a rabbit, hopping through the text,
Keeping delimiters where they belong best.
No lonely 666 chunks in sight,
Two tidy pieces, boundaries right.
Carrots and tests make the flow just right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Clear and specific summary of the chunker delimiter behavior change.
Description check ✅ Passed Includes the required Summary section and explains the bug, behavior change, and regression test.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

@euvre euvre added the ci Continue Integration label Jul 21, 2026
@euvre
euvre requested a review from wangq8 July 21, 2026 08:06

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix. Switching from FindAllStringSubmatchIndex to FindAllStringIndex and gluing delimiters to the end of the preceding segment matches Python's _split_text_by_pattern exactly. The regression test covers the exact bug case (delimiter as standalone chunk). LGTM.

@wangq8

wangq8 commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

@euvre fix the CI build.

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:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants