Skip to content

feat(go): add length split strategy with overlap to chunk pipeline - #16047

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
Crystora:feat/go-chunk-length-split
Jul 6, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
Crystora:feat/go-chunk-length-split

Conversation

@Crystora

@Crystora Crystora commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

The Go ingestion chunk pipeline's SplitOperator (internal/ingestion/chunk/split.go) supported only sentence, char, and paragraph strategies, but not fixed-size (length) chunking with overlap — the canonical RAG strategy for bounding chunk length while preserving cross-boundary context.

This adds a length strategy alongside the existing ones, configurable via DSL params:

  • 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_size falls back to a default (256) when unset/non-positive, and overlap is clamped to [0, chunk_size-1] so the window always advances and the operation terminates. Implementation follows the existing splitByChar/splitByParagraph pattern and reuses DetectLanguage for chunk metadata.

It also adds split_test.go — the first unit tests for the chunk package — covering basic windowing, overlap, overlap clamping/termination, rune-awareness (CJK), default sizing, no-overlap reconstruction, empty input, and DSL param parsing.

Validation: gofmt clean, go vet ./internal/ingestion/chunk/ clean, go build ok, go test ./internal/ingestion/chunk/ — all tests pass.

Closes #16046

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

SplitOperator gains a "length" strategy that chunks text into fixed-size rune windows with configurable overlap. NewSplitOperator parses chunk_size and overlap from params using a new toInt coercion helper. splitByLength clamps overlap to guarantee forward progress and emits ChunkData per window. A new test file covers windowing, overlap, clamping, rune-awareness, defaults, and empty input.

Changes

Length Split Strategy

Layer / File(s) Summary
SplitOperator fields, param parsing, dispatch, and splitByLength core
internal/ingestion/chunk/split.go
Adds chunkSize and overlap fields plus defaultLengthChunkSize constant to SplitOperator; extends NewSplitOperator with a toInt helper to coerce float64/int params; adds "length" case to the strategy switch; appends chunk_size and overlap to String(); implements splitByLength as a rune-slice sliding window that clamps overlap, advances by chunkSize - overlap, and emits ChunkData with Size and Index.
Unit tests for length strategy
internal/ingestion/chunk/split_test.go
Adds runLength test helper and eight test functions covering basic windowing, overlap output, overlap clamping/termination safety, default chunk size (chunk_size <= 0), CJK rune-aligned chunking, no-overlap full reconstruction, empty-input zero chunks, and float64 param parsing via NewSplitOperator.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hop, hop, through the rune-wide field,
Each chunk a window neatly sealed,
Overlap clamps so we don't stall,
CJK glyphs — we count them all!
With tests in tow, no edge left bare,
The rabbit chunks with rune-aware care. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately and concisely describes the main feature: adding a length-based split strategy with overlap support to the chunk pipeline.
Linked Issues check ✅ Passed The PR implementation meets all coded requirements from issue #16046: length strategy with chunk_size and overlap params, rune-aware windowing, proper defaults and clamping, and comprehensive unit tests.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the issue #16046 requirements: split operator enhancements and unit test suite for the chunk package. No extraneous modifications detected.
Description check ✅ Passed The PR description comprehensively addresses the template requirements with clear problem statement, implementation details, testing strategy, and validation confirmation.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/ingestion/chunk/split.go (1)

240-248: 💤 Low value

Consider documenting the Size semantics difference.

Size is set to the rune count here, whereas PostprocessOperator (per context snippet at postprocess.go:180-183) re-indexes and sets Size = 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

📥 Commits

Reviewing files that changed from the base of the PR and between e7c0687 and 71eb174.

📒 Files selected for processing (2)
  • internal/ingestion/chunk/split.go
  • internal/ingestion/chunk/split_test.go

@Crystora
Crystora force-pushed the feat/go-chunk-length-split branch from 71eb174 to 4fee3f2 Compare June 15, 2026 14:23
@Crystora

Copy link
Copy Markdown
Contributor Author

@yingfeng @JinHai-CN pls review this pr.

@Haruko386
Haruko386 requested a review from xugangqiang June 16, 2026 09:35
@xugangqiang

Copy link
Copy Markdown
Contributor

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.

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 6, 2026
@yuzhichang
yuzhichang force-pushed the feat/go-chunk-length-split branch from 4fee3f2 to e61feda Compare July 6, 2026 05:47
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 6, 2026
@yuzhichang yuzhichang added the ci Continue Integration label Jul 6, 2026
@yuzhichang
yuzhichang merged commit 4effc24 into infiniflow:main Jul 6, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: add fixed-size (length) split strategy with overlap to the Go chunk pipeline

3 participants