Repository navigation
fix(chunker): glue delimiter to preceding segment instead of emitting it as a standalone chunk - #17168
Conversation
… 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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughDelimiter 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 ChangesDelimiter chunking
Estimated code review effort: 2 (Simple) | ~10 minutes 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 |
wangq8
left a comment
There was a problem hiding this comment.
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.
|
@euvre fix the CI build. |
Summary
In Go mode, the ingestion TokenChunker emitted the configured delimiter (e.g.
666) as its own chunk:splitKeepingDelimkept 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.