Repository navigation
feat(go): add length split strategy with overlap to chunk pipeline - #16047
Conversation
📝 WalkthroughWalkthrough
ChangesLength Split Strategy
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
🧹 Nitpick comments (1)
internal/ingestion/chunk/split.go (1)
240-248: 💤 Low valueConsider documenting the Size semantics difference.
Sizeis set to the rune count here, whereasPostprocessOperator(per context snippet atpostprocess.go:180-183) re-indexes and setsSize = len(GetContent()), which is byte count. If a pipeline includes postprocessing, the value is normalized; if not, consumers receive rune-based sizing.This is consistent with the fact that other split strategies don't explicitly set
Size, but worth a brief inline comment noting "rune count; postprocess normalizes to bytes if present" to avoid future confusion.🤖 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/chunk/split.go` around lines 240 - 248, Add an inline comment in the ChunkData struct creation (where Size is set to end - start) to document that the Size field represents a rune count at this point in the pipeline, and that the PostprocessOperator will normalize it to a byte count (via len(GetContent())) if postprocessing is applied. This clarifies the semantics for future maintainers and explains why other split strategies don't explicitly set Size while this one does.
🤖 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.
Nitpick comments:
In `@internal/ingestion/chunk/split.go`:
- Around line 240-248: Add an inline comment in the ChunkData struct creation
(where Size is set to end - start) to document that the Size field represents a
rune count at this point in the pipeline, and that the PostprocessOperator will
normalize it to a byte count (via len(GetContent())) if postprocessing is
applied. This clarifies the semantics for future maintainers and explains why
other split strategies don't explicitly set Size while this one does.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c8673fd8-355e-4eb2-9242-52ed1109b12d
📒 Files selected for processing (2)
internal/ingestion/chunk/split.gointernal/ingestion/chunk/split_test.go
71eb174 to
4fee3f2
Compare
|
@yingfeng @JinHai-CN pls review this pr. |
|
This code is being actively migrated and will be fully migrated to go. For now we don't have plan to change inside task_executor_refactor folder. Thank you. |
4fee3f2 to
e61feda
Compare
What problem does this PR solve?
The Go ingestion chunk pipeline's
SplitOperator(internal/ingestion/chunk/split.go) supported onlysentence,char, andparagraphstrategies, but not fixed-size (length) chunking with overlap — the canonical RAG strategy for bounding chunk length while preserving cross-boundary context.This adds a
lengthstrategy alongside the existing ones, configurable via DSLparams:chunk_size— target window size in runes (rune-aware: multi-byte/CJK text is windowed by character, never split mid-rune).overlap— runes carried from the end of each window into the next.The window advances by
chunk_size - overlap.chunk_sizefalls back to a default (256) when unset/non-positive, andoverlapis clamped to[0, chunk_size-1]so the window always advances and the operation terminates. Implementation follows the existingsplitByChar/splitByParagraphpattern and reusesDetectLanguagefor chunk metadata.It also adds
split_test.go— the first unit tests for thechunkpackage — covering basic windowing, overlap, overlap clamping/termination, rune-awareness (CJK), default sizing, no-overlap reconstruction, empty input, and DSL param parsing.Validation:
gofmtclean,go vet ./internal/ingestion/chunk/clean,go buildok,go test ./internal/ingestion/chunk/— all tests pass.Closes #16046
Type of change