Repository navigation
fix(chunker): preserve inter-line trailing space in text-path overlap prefix - #17748
xugangqiang wants to merge 1 commit into
Conversation
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe token chunker preserves trailing whitespace from sentence-split fragments during merging and overlap calculation. A regression test verifies exact multi-line chunks and Python-compatible overlap boundaries. ChangesToken overlap whitespace preservation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
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 |
There was a problem hiding this comment.
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_overlap_test.go`:
- Around line 34-44: Update the regression test to exercise mergeByTokenSize
directly with the existing text, token budget, and overlap inputs, rather than
invoking Invoke with a non-custom newline delimiter that routes through
mergeByTokenSizeFromJSON. Keep the assertions and test data focused on the
text-token regression and ensure the changed merge loop is covered.
🪄 Autofix (Beta)
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: 396bbef6-cf88-43bf-8f07-41b18a857d45
📒 Files selected for processing (2)
internal/ingestion/component/chunker/token.gointernal/ingestion/component/chunker/token_overlap_test.go
|
@yuzhichang @JinHai-CN @yingfeng Please help to review |
… prefix The text path of TokenChunker split the payload on sentence delimiters and TrimSpaced each fragment before merging. This dropped the trailing whitespace of each line, so the overlap prefix carved from the previous (untrimmed) chunk lost a character and diverged from Python's naive_merge by one character on every following chunk. Mirror naive_merge, which builds each unit from "\n" + sub_sec (sub_sec keeps its trailing space and is never TrimSpaced; the only post-processing is dropping the leading empty placeholder at naive_merge:1370-1375). Skip only genuinely empty fragments instead of TrimSpacing each part. Fixes the token-text-overlap-split parity divergence. Adds a regression test that drives Invoke with empty delimiters so it actually lands on the patched mergeByTokenSize: the text path only reaches that function when there is no active delimiter, so a non-empty delimiter (e.g. ["\n"]) must NOT be used — it would route to the separate mergeByTokenSizeFromJSON path, which this fix does not touch. The test pins the exact chunk texts against the Python reference.
883fd20 to
445a697
Compare
Extract a shared mergeDecision helper (mergeAction + allowBoundaryOverflow) and newChunkText, and rewrite the text (addChunk) and JSON (addTextChunk) merge paths to use it. Go now matches Python's canonical OVER_CAP default (rag/nlp MergeStrategy): greedily accumulate adjacent units, allow one boundary overflow then close the chunk, but never merge a unit that already exceeds the cap (it stands alone, mirroring Python's `if pt > cap` branch). Update the cap/overlap tests to the OVER_CAP contract (a chunk may exceed budget by at most one incoming unit) and restructure the overlap-tag test to exercise the overlap path under OVER_CAP. Part of consolidating infiniflow#17744/infiniflow#17748 into a single Go PR that syncs the chunker with Python PR infiniflow#17808 (OVER_CAP default).
Summary
token-text-overlap-splitparity divergence on the text path ofTokenChunker.mergeByTokenSizeappliedstrings.TrimSpaceto each sentence-delimiter-split fragment, dropping the trailing whitespace of each line. The overlap prefix is carved from the untrimmed previous chunk, so that dropped character made every following chunk head diverge from Python'snaive_mergeby one character (e.g. Go"eta..."vs Python"ta ...", and the chunk boundary"alpha\nbeta"vs"alpha \nbeta").naive_merge, which builds each unit from"\n" + sub_sec(sub_sec keeps its trailing space) and only strips at the final chunk output. Skip only genuinely empty fragments instead of TrimSpacing each part.Verification
token__text_overlapcase (chunk_token_size=64,delimiters=["\n"],overlapped_percent=0.1), Go output now matches Pythonrag/nlp.naive_mergebyte-for-byte across all 3 chunks (lengths 239/224/263).TestTokenChunker_TextOverlapPreservesInterLineSpace, which fails without the fix and passes with it, and pins the exact chunk texts against the Python reference../internal/ingestion/component/chunker/unit suite passes (no regression).Notes
upstream/main.strings.TrimSpace(sec)is intentionally left in place — it only affects global leading/trailing whitespace, which is stripped at final output anyway and causes no divergence.🤖 Generated with CodeBuddy Code