Repository navigation
fix(chunker): keep oversize text/markdown unit whole (OVER_CAP alignment) - #17854
Conversation
…ent) Python's naive_merge (_merge_paragraph_groups, rag/nlp/__init__.py) never atom-splits an oversize unit under either OVER_CAP or UNDER_CAP: a paragraph larger than chunk_token_size becomes its own standalone chunk and the model layer truncates it later. The Go text/markdown path (mergeByTokenSize) instead called splitOversizedUnit unconditionally, emitting Go-only sub-chunks that diverged from the Python reference (parity cases token__text_long_paragraph and token__markdown_long: Python 1 chunk, Go 3-4). Pass the oversize unit through addChunk, which mergeDecision already forces to startNewChunk (token.go:514), so it stands alone exactly like Python. The JSON path already does this via subSplitOversize=false (infiniflow#17739); this completes the OVER_CAP alignment on the text/markdown path. Add TestTokenChunker_OversizeUnitKeptWhole to pin the contract: a single unbroken line with no delimiter yields one standalone chunk on both the text and markdown paths. Co-authored-by: xugangqiang <>
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe token chunker now retains oversized text and Markdown units as standalone chunks. New Go tests cover standalone oversized paragraphs and oversized paragraphs that follow in-budget paragraphs. ChangesOversized token retention
Estimated code review effort: 2 (Simple) | ~10 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/ingestion/component/chunker/token.go (1)
613-621: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove migration-history details from these comments.
Keep the current runtime contract and remove references to previous Go behavior and named parity cases.
internal/ingestion/component/chunker/token.go#L613-L621: describe that oversized units pass toaddChunkand start a new chunk.internal/ingestion/component/chunker/token_oversize_whole_test.go#L23-L30: describe the current regression case only.As per coding guidelines, keep package and doc comments aligned with the current runtime path rather than migration history.
🤖 Prompt for 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. In `@internal/ingestion/component/chunker/token.go` around lines 613 - 621, Update the comments at internal/ingestion/component/chunker/token.go#L613-L621 to describe only the current behavior: oversized units are passed to addChunk, which starts a new chunk; remove references to prior Go behavior, Python implementation details, and parity cases. Also revise the comment at internal/ingestion/component/chunker/token_oversize_whole_test.go#L23-L30 to describe only the current regression case, without migration-history details.Source: Coding guidelines
🤖 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_oversize_whole_test.go`:
- Around line 55-71: Add a regression case to
TestTokenChunker_OversizeUnitKeptWhole with an in-budget unit before the
oversized unit and a sentenceDelimiter-accepted separator, then assert the
output contains two chunks with the expected text so the addChunk merge path
invokes mergeDecision.
---
Nitpick comments:
In `@internal/ingestion/component/chunker/token.go`:
- Around line 613-621: Update the comments at
internal/ingestion/component/chunker/token.go#L613-L621 to describe only the
current behavior: oversized units are passed to addChunk, which starts a new
chunk; remove references to prior Go behavior, Python implementation details,
and parity cases. Also revise the comment at
internal/ingestion/component/chunker/token_oversize_whole_test.go#L23-L30 to
describe only the current regression case, without migration-history details.
🪄 Autofix
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: 251e7ebb-87ca-4625-b992-a789db15d401
📒 Files selected for processing (2)
internal/ingestion/component/chunker/token.gointernal/ingestion/component/chunker/token_oversize_whole_test.go
…h test Follow-ups to infiniflow#17854 from review: - Drop stale doc comment claiming oversize units are atom-split via splitOversizedUnit; they are now kept whole (Python OVER_CAP). - Inline the now-redundant addUnit wrapper into addChunk. - Add TestTokenChunker_OversizeUnitStandsAloneAfterInBudgetUnit, which exercises mergeDecision's oversize branch (in-budget unit followed by an oversize paragraph) that the lone-oversize test never reached.
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_oversize_whole_test.go`:
- Around line 128-131: Update the first-chunk assertion in the token oversize
test to require exact equality with inBudget rather than substring containment,
while preserving the existing failure context.
🪄 Autofix
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: f982e556-6a0f-4d59-b250-8f7e363b17be
📒 Files selected for processing (2)
internal/ingestion/component/chunker/token.gointernal/ingestion/component/chunker/token_oversize_whole_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/ingestion/component/chunker/token.go
…served - Remove TestMergeByTokenSize_UnbrokenAtomStrictCap: it pinned the removed atom-split (splitOversizedUnit) behavior, which blocked the unit tier. - Trim migration-narrative doc comment in TestTokenChunker_OversizeUnitKeptWhole. - Strengthen TestTokenChunker_OversizeUnitKeptWhole to assert the oversize unit's content is preserved (not just the chunk count), comparing trailing whitespace on both sides. Co-authored-by: CodeBuddy <[email protected]>
Strengthen TestTokenChunker_OversizeUnitStandsAloneAfterInBudgetUnit: use exact equality (first != inBudget) instead of substring containment, so the test catches a regression where the oversize paragraph is wrongly merged into the previous chunk. The final-output TrimSpace (token.go:657) guarantees first is exactly "Hello world.". Co-authored-by: CodeBuddy <[email protected]>
|
LGTM |
…OVER_CAP) The EmbeddingModel BatchSize port (infiniflow#17881) landed on a pre-infiniflow#17854 base and dropped the OVER_CAP alignment: mergeByTokenSize still atom-split oversize units via splitOversizedUnit, and the old token_strict_cap_test.go (which covered the removed strict-cap behavior) was left behind while the new token_oversize_whole_test.go was dropped. Restore infiniflow#17854: - mergeByTokenSize routes oversize units through addChunk and keeps them whole as standalone chunks (Python OVER_CAP; model layer truncates later) instead of calling splitOversizedUnit. - Add token_oversize_whole_test.go, delete token_strict_cap_test.go. Co-authored-by: Jack <[email protected]>
After rebasing onto upstream/main (which merged infiniflow#17739/infiniflow#17835/infiniflow#17854/infiniflow#17868): - Remove 4 go_bug rules now resolved by merged fixes: token-json-per-item-merge, token-json-custom-delim-drops-newline, token-json-single-item-oversize, token-text-overlap-split. - Delete their go_snapshot files; also drop 4 orphaned tokenizer go_snapshot files that the harness never reads (strict-compare path). - Refresh the 3 remaining ratcheted snapshots for token-custom-delim-newline-and-field (html/markdown/text_backtick), whose Go output shifted under the merged delimiter/children-split fixes but the divergence itself persists. The 4 tokenizer-count cases (text/html/markdown_default_delim, text_token_liveness) now match the Python golden strict-compare with no rule, i.e. the tokenizer count mismatch is resolved. Harness is green under both plain and -update runs.
What
The Go
TokenChunkertext/markdown path (mergeByTokenSize) unconditionallycalled
splitOversizedUniton any unit that exceededchunk_token_size,emitting Go-only sub-chunks. Python's
naive_merge(_merge_paragraph_groups,rag/nlp/__init__.py) never atom-splits an oversize unit under eitherOVER_CAPorUNDER_CAP: a paragraph larger than the budget becomes its ownstandalone chunk and the model layer truncates it later.
This aligns the text/markdown path with the structured JSON path
(
invokeJSONPayload→mergeByTokenSizeFromJSON(..., subSplitOversize=false),#17739). It completes the OVER_CAP alignment started in #17835.
Cases fixed (chunker parity)
token__text_long_paragraph: Python 1 chunk, Go was 3 → now 1.token__markdown_long: Python 1 chunk, Go was 4 → now 1.How
An oversize unit is passed through
addChunk, whichmergeDecisionalreadyforces to
startNewChunk(token.go:514) when the incoming unit exceeds thetarget, so it stands alone exactly like Python. No atom-split on the
text/markdown path. The
addUnitwrapper was inlined intoaddChunk.Note
This is one step of the broader chunker-parity alignment. Remaining divergences
are tracked separately:
json_children_delimpath.subSplitOversize=trueatom-split branch is dead code in production,not a live divergence. On the text/markdown path a backtick-wrapped delimiter
short-circuits at
hasCustomDelim(token.go:330) and returns one chunk persegment (matching Python
naive_merge), while a bare delimiter(
\n!?。;!?) early-returns tomergeByTokenSize(token.go:306). The onlycaller passing
true(token.go:337) is therefore unreachable, and the liveJSON path passes
false(token.go:719, fix(chunker): JSON path merges globally and keeps over-budget items whole #17739). Removing the dead branch istracked separately as a hygiene cleanup (Go TokenChunker still atom-splits oversize units / carries dead atom-split code, diverging from #17808 OVER_CAP contract #17865), not a parity bug. The fix
above applies to the common (bare-delimiter) case.