Skip to content

fix(chunker): honor bare (non-backtick) delimiters in TokenChunker (#17723) - #18182

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:fix/chunker-bare-delimiter
Aug 12, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:fix/chunker-bare-delimiter

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

Go's TokenChunker previously ignored bare (non-backtick) delimiters such as ::, ., or ;. compileDelimPattern compiled them with keepBare=false, so a bare delimiter produced a nil pattern and the payload was routed to the single-section merge that never split on it — diverging from Python's naive_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

  • compileDelimPattern now calls CompileDelimiterPatternList(delims, true) so bare entries are active.
  • invokeTextPayload routes active delimiters correctly:
    • custom (backtick-wrapped) delimiter → one chunk per segment, no token merge (chunkPerSegment);
    • bare delimiter → split into paragraphs (delimiter dropped, each paragraph rebuilt with a leading "\n" that preserves the original surrounding whitespace), then merge 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 unchanged.

Test plan

  • New bare_delimiter_test.go locks 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_ExtractsPerEntryIndependently updated for the keepBare=true semantics.
  • token_delim_contract_test.go updated to assert bare delimiters are honored.
  • Existing golden-parity and merge-parity tests (Go vs Python) pass.
  • ./internal/ingestion/component/... and ./internal/parser/chunk/... suites pass with no regression.

…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).
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 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: 0b411ddf-9e5e-4345-bf4f-7c0b14322248

📥 Commits

Reviewing files that changed from the base of the PR and between 207e2ea and c32bed4.

📒 Files selected for processing (7)
  • internal/ingestion/component/chunker/bare_delimiter_test.go
  • internal/ingestion/component/chunker/common.go
  • internal/ingestion/component/chunker/delimiter_case_sensitive_test.go
  • internal/ingestion/component/chunker/token.go
  • internal/ingestion/component/chunker/token_delim_contract_test.go
  • internal/ingestion/component/chunker/token_strict_cap_test.go
  • internal/ingestion/component/chunker/token_test.go

📝 Walkthrough

Walkthrough

Changes

Bare 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

Layer / File(s) Summary
Delimiter activation and contracts
internal/ingestion/component/chunker/common.go, internal/ingestion/component/chunker/delimiter_case_sensitive_test.go, internal/ingestion/component/chunker/token_delim_contract_test.go
Non-empty bare delimiters compile as active patterns. Tests verify delimiter extraction and delimiter removal.
Delimiter-aware chunking and merging
internal/ingestion/component/chunker/token.go
Text processing separates inactive, bare, and custom delimiter paths. Bare-delimited paragraphs become token-merge units while oversized units remain standalone.
Bare delimiter behavior coverage
internal/ingestion/component/chunker/bare_delimiter_test.go, internal/ingestion/component/chunker/token_strict_cap_test.go, internal/ingestion/component/chunker/token_test.go
Tests cover delimiter variants, text and JSON ingestion, custom delimiters, normalization, empty segments, fallback behavior, and the revised merge signature.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

Possibly related PRs

Suggested labels: ci, 🧪 test

Suggested reviewers: jay77721, yuzhichang

Poem

A rabbit hops through delimiters bright,
Turns bare marks into newlines of light.
Chunks merge softly, tokens align,
Backticks keep their old design.
Tests bloom wide—carrot cheers tonight! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely states that bare delimiters are now honored in TokenChunker.
Description check ✅ Passed The description includes the required Summary section and provides clear background, implementation details, objectives, and test coverage.
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.

@xugangqiang xugangqiang added the ci Continue Integration label Aug 12, 2026
@xugangqiang
xugangqiang requested a review from yuzhichang August 12, 2026 12:56
@yuzhichang
yuzhichang merged commit b505437 into infiniflow:main Aug 12, 2026
9 checks passed
@xugangqiang
xugangqiang deleted the fix/chunker-bare-delimiter branch September 23, 2026 07:17
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants