Repository navigation
fix: avoid whitespace-only and over-long chunks in RecursiveDocumentSplitter - #13693
Merged
bogdankostic merged 2 commits intoDec 2, 2026
Merged
bogdankostic merged 2 commits into
bogdankostic merged 2 commits into
Conversation
…plitter Text with runs of blank lines, common in PDF extractions, produced chunks of only whitespace in word, char and token mode. A whitespace-only chunk is now joined to a neighbouring chunk when the result fits split_length, which in word mode is always the case. The chunks still join back to the input text. In char and token mode a whitespace run longer than split_length can still form a chunk of its own, since joining it would exceed split_length. With the "sentence" separator, the whitespace after the last sentence was appended after grouping, which could push a char/token chunk past split_length. The last sentence split now runs to the end of the text so the grouping accounts for it.
Contributor
|
@MaiAditya is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
Contributor
Author
|
Gentle ping on this one when you have a moment. CI is green and the branch merges cleanly; happy to adjust anything. |
bogdankostic
approved these changes
Dec 2, 2026
bogdankostic
left a comment
Contributor
There was a problem hiding this comment.
Looks good, thanks @MaiAditya!
bogdankostic
enabled auto-merge (squash)
December 2, 2026 13:26
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.
Related Issues
Proposed Changes:
_chunk_textand before overlap is applied, a whitespace-only chunk is joined to a neighbouring chunk when the result stays withinsplit_length. In word mode whitespace counts as zero words, so it always joins. In char/token mode a whitespace run longer thansplit_lengthcan still form a chunk of its own, since joining it would exceedsplit_length. Nothing is dropped: the chunks still join back to the input, andsplit_idx_start,page_numberand_split_overlapare computed on the joined chunks."sentence"separator, the last sentence split now runs to the end of the text, so the grouping accounts for its trailing whitespace. This replaces thetrailing_textappend from feat!: alignpage_numbermetadata across splitters and fix drift in overlapping splits #13006, which added the whitespace after grouping and could produce a chunk of 16 characters forsplit_length=14("eta zeta? iota\n\n"). The trailing whitespace is still kept.How did you test it?
split_id,split_idx_start, and that the chunks join back to the input; and a test for the sentence-separator case. All fail onmain.test_run_multiple_separators_with_overlap_applies_overlap_only_oncenow expects 5 chunks instead of 6: onmainthe extra chunk was a lone"\n"after the overlap, which is now joined to the previous chunk.pytest test/components/preprocessors/test_recursive_splitter.py: 87 passed (incl. 14 integration). ruff check/format and mypy on the module pass.main.Notes for the reviewer
upgradeentry suggesting re-splitting and re-indexing.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.AI disclosure: I used Claude Code (Anthropic) to trace the splitter logic, write the comparison script, and draft the tests and this description. I reviewed the change and ran the tests above.