Repository navigation
fix(chunker): stop emitting a redundant chunk at the end of every file - #333
Merged
yoanbernabeu merged 1 commit intoOct 24, 2026
Conversation
Chunk steps back by the overlap after every chunk, including the one that already reaches the end of the content. The loop then runs once more and emits a final chunk made only of the last overlap-sized tail of the chunk before it. Every file longer than the overlap (200 characters with the default overlap of 50 tokens) was indexed with this extra chunk, which cost one more embedding request per file and competed in search with the chunk it duplicated. ReChunk has the same loop and the same problem. Stop once a chunk reaches the end of the content. Chunks before that point are unchanged, so existing chunk IDs and hashes stay the same. Co-Authored-By: Claude Opus 5.5 <[email protected]>
MaxFreedomPollard
force-pushed
the
fix/redundant-trailing-chunk
branch
from
October 23, 2026 02:28
2c7a425 to
67c9443
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #333 +/- ##
===========================================
+ Coverage 27.16% 51.05% +23.89%
===========================================
Files 32 104 +72
Lines 3711 17630 +13919
===========================================
+ Hits 1008 9001 +7993
- Misses 2620 7725 +5105
- Partials 83 904 +821 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Chunker.Chunk(indexer/chunker.go) steps back by the overlap after every chunk, including the chunk that already reaches the end of the content. The loop then runs once more and emits a final chunk holding only the lastoverlap × 4characters of the chunk before it. Nothing in that chunk is new.With the default settings (
size: 512,overlap: 50, so 2048/200 characters), a 1,000-character file of ten 100-character lines is indexed as two chunks: lines 1-10, then lines 9-10 again. Every file longer than 200 characters gets this extra chunk, which means one more embedding request, one more vector in the store, and a second search hit for the same lines. Withsearch.dedupon (the default), the short tail can take the file's slot instead of the full chunk.On this repository's own
.gofiles, 236 of 243 files get the extra chunk: 1,425 chunks where 1,189 cover the same content, so about 17% of embedding requests are redundant. I measured this with a line-by-line Python port ofChunk, not by running grepai.ReChunkhas a copy of the same loop and the same problem.The fix: after emitting a chunk, stop if it reaches the end of the content. Earlier chunks keep the same boundaries, IDs and hashes, so existing indexes stay valid. A file's leftover tail chunk is removed the next time that file is re-indexed, because re-indexing deletes the file's chunks first.
Related Issue
No open issue covers this. I found it while reading the chunker.
Type of Change
How Has This Been Tested?
TestChunker_NoRedundantTrailingChunkis table-driven and covers files that fit in one, two and three chunks.TestChunker_ReChunkNoRedundantTrailingChunkcoversReChunk. Both check the exact chunk count, that the last chunk ends on the file's last line, and that every chunk ends after the one before it. I took the expected values from the Python port. Onmainthe same inputs give 2, 3 and 4 chunks and 4 sub-chunks, and in each case the last chunk only repeats lines the previous chunk already covers.What I did not run: I had no Go toolchain, so I did not run
go test,go vet,gofmtorgolangci-linton this branch. I formatted the code by hand to gofmt style and checked both files with a tree-sitter Go parser, which checks syntax only. The existing chunker and indexer tests only assert lower bounds on chunk counts, so they should still pass, but CI will be the first real run.Test Configuration:
Checklist
golangci-lint runand fixed any issues (not run, no Go toolchain)Additional Notes
The CHANGELOG entry has no PR number yet.
🤖 Generated with Claude Code