Repository navigation
fix(chunker): honor bare (non-backtick) delimiters in TokenChunker (#17723) - #18182
Conversation
…nfiniflow#17723) Go's TokenChunker previously ignored bare (non-backtick) delimiters such as "::", ".", or ";". compileDelimPattern used keepBare=false, so a bare delimiter compiled to a nil pattern and the payload was routed to the single-section merge that never split on it. This diverged from Python's naive_merge, which splits on bare delimiters and then merges by token size. - compileDelimPattern now calls CompileDelimiterPatternList(delims, true) so bare entries are active. - invokeTextPayload routes active delimiters correctly: a custom (backtick) delimiter still yields one chunk per segment with no token merge (chunkPerSegment), while a bare delimiter splits the text into paragraphs (delimiter dropped, each paragraph rebuilt with a leading "\n" that preserves the original surrounding whitespace) and then merges by token size. - mergeByTokenSize gains a delimPattern parameter; the bare-delimiter branch mirrors Python's naive_merge default path (rag/nlp/__init__.py:1406-1415). The no-delimiter and custom-delimiter paths keep their historical behavior. Golden-parity and merge-parity tests against Python now pass, and the new bare_delimiter_test suite locks the contract (text/JSON paths, CRLF normalization, empty/whitespace segments, and overlap interaction).
|
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 (7)
📝 WalkthroughWalkthroughChangesBare delimiters now activate delimiter patterns, split text into newline-separated paragraphs, and participate in token-size merging. Custom backtick delimiters retain one-chunk-per-segment behavior. Tests cover text, JSON, normalization, empty segments, fallback paths, and delimiter variants. Bare delimiter chunking
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related issues
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 |
Summary
Go's
TokenChunkerpreviously ignored bare (non-backtick) delimiters such as::,., or;.compileDelimPatterncompiled them withkeepBare=false, so a bare delimiter produced anilpattern and the payload was routed to the single-section merge that never split on it — diverging from Python'snaive_merge, which splits on bare delimiters and then merges by token size.This PR aligns the Go chunker with the Python contract (refs #17723).
Changes
compileDelimPatternnow callsCompileDelimiterPatternList(delims, true)so bare entries are active.invokeTextPayloadroutes active delimiters correctly:chunkPerSegment);"\n"that preserves the original surrounding whitespace), then merge by token size.mergeByTokenSizegains adelimPatternparameter; the bare-delimiter branch mirrors Python'snaive_mergedefault path (rag/nlp/__init__.py:1406-1415).The no-delimiter and custom-delimiter paths keep their historical behavior unchanged.
Test plan
bare_delimiter_test.golocks the contract across text/JSON paths, multi-char / single-char / CJK delimiters, CRLF normalization, empty & whitespace-only segments, no-delimiter fallback, and overlap interaction.TestCompileDelimPattern_BareCharIsActivePattern/TestCompileDelimPattern_ExtractsPerEntryIndependentlyupdated for thekeepBare=truesemantics.token_delim_contract_test.goupdated to assert bare delimiters are honored../internal/ingestion/component/...and./internal/parser/chunk/...suites pass with no regression.