Repository navigation
fix(chunk): number paragraph chunks by their position - #21823
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Consecutive chunk indices internal/parser/chunk/split.go, internal/parser/chunk/split_by_paragraph_test.go |
The splitter assigns each emitted chunk an index based on its position in the output. Tests check blank-line filtering, consecutive indices, and empty or whitespace-only input. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: xugangqiang
Merge Risk: 
Minimal · up to 0d853
-
The paragraph indexing fix is ready to merge with no identified blocking risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the defect, the behavior change, the affected code path, the tests, and validation results. It does not use the template's "### Summary" heading, but it provides the required summary content in the "### What happens" and "### Change" sections.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit checks each chunk in line
Blank spaces leave no gaps behind
The indices hop in order true
Three tests watch the outputs through
Then carrots mark the review done
Harsh23Kashyap
left a comment
There was a problem hiding this comment.
Verified in-tree at 0d8536f and approving.
Red/green both reproduce cleanly here. With just the splitByParagraph hunk reverted, TestSplitByParagraphIndexMatchesPosition fails: the three chunks of the test document come back indexed 0, 3, 5 through the blank lines, exactly the holes described. At this head the full chunk package suite passes, including the three new tests. Two runs each way, identical results.
The instability claim checks out as well: PostprocessOperator.Execute re-numbers every chunk, so with a merge or filter stage configured the same document reports 0, 1, 2, and without one it reported 0, 3, 5. Nothing outside the package consumes SplitChunks.Index, and the merge bookkeeping in postprocess only uses it as a boundary marker, so numbering by output position is safe here.
|
LGTM |
yuzhichang
left a comment
There was a problem hiding this comment.
Reviewed merge-base..head (2 commits, 2 files).
Change: splitByParagraph replaced the paragraph's slice position with len(chunks) so the emitted Index values are dense and 0-based, matching splitSentences, splitByChar and splitByLength. Blank lines are already skipped by the trimmed == "" guard, so gaps were guaranteed on any text containing an empty line.
Call-chain check
ChunkData.Indexconsumers inside the package:PostprocessOperator.ExecuterewritesIndexunconditionally (internal/parser/chunk/postprocess.go:96), andmergeChunksonly uses it as a provisional carry-over before that rewrite. Both are unaffected by the change, and the postprocess path now receives a correct input sequence instead of relying on the rewrite to paper over gaps.Run()exposesSplitChunksasResultChunkswhen no postprocess stage is configured (internal/parser/chunk/execute.go:90); that path was the one leaking0,3-style holes, and it is now dense.- The only production caller of
chunk.Runis the CLI chunk command (internal/cli/user_command.go:3324), which printsIndexverbatim. The ingestion pipeline usesinternal/ingestion/component/chunker, not this splitter, so no persistedchunk_index/chunk-id identity shifts. - No map or slice is keyed by
ChunkData.Indexanywhere in the tree, so no dedupe or position-mapping path depends on the old sparseness.
Tests: the new file pins the three behaviors that matter — blank-line skipping, dense positional index, and empty/whitespace-only input returning zero chunks — and matches the existing runLength helper style in split_test.go.
No blocking findings.
What happens
splitByParagraphnumbers each chunk with the paragraph's position instrings.Split(text, "\n"):Blank lines are skipped, so the index keeps the holes they left. For
Run(text, ChunkOptions{SplitStrategy: "paragraph"})returns two chunks indexed0and3— andRunhandsSplitChunksstraight to the caller when no postprocess stage is configured (execute.go), so that is what thechunkCLI command prints:The number is also unstable across configurations: with
MergeTargetSizeorFilterMinLengthset,PostprocessOperator.Executere-numbers every chunk (chunks[i].Index = i), so the same input reports0, 1in one case and0, 3in the other.Every other strategy builds its index from the chunk's own position (
Index: len(chunks)insplitSentences,splitByCharandsplitByLength), andsplit_test.goasserts exactly that for thelengthstrategy.Change
splitByParagraphnumbers chunks by their position in the output, matching the other strategies and the postprocess re-index.Tests
New
internal/parser/chunk/split_by_paragraph_test.go:TestSplitByParagraphSkipsBlankLines— blank and whitespace-only lines are dropped (the strategy had no test at all).TestSplitByParagraphIndexMatchesPosition— fails onmainwithchunk 1 ("第二段") Index = 3, want 1.TestSplitByParagraphBlankInput— empty and whitespace-only input produce no chunks.go test ./internal/parser/chunkpasses (unit tier, no external services) andgo vet ./internal/parser/chunkis clean.AI assistance
This change was prepared with AI assistance: the defect was reproduced locally, the fix written, and the tests run against this tree. The change was reviewed before submission.