Repository navigation
fix: correct RecursiveDocumentSplitter split_idx_start for word overlap ending in a separator - #12757
anishmehta24 wants to merge 1 commit into
Conversation
…umentSplitter split_idx_start With split_unit="word" the overlap string is rebuilt by joining the last words with single spaces, so it does not include the whitespace that follows those words in the previous chunk. Subtracting its length from the chunk length therefore overshot the next chunk's split_idx_start by the trailing separator, and the _split_overlap ranges inherited the error. Measure the overlap from the first overlapping word to the end of the chunk instead. Character and token modes are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DakLsFtFd23piCzmyiDngh
|
@anishmehta24 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @anishmehta24, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
|
Thanks for signing the CLA, @anishmehta24! 🎉 This PR is now ready for review again and the reviewer has been re-assigned. |
|
@anakin87 CLA is signed now, so this should be ready for review. |
|
Thank you! This was superseded by #13006 |
Related Issues
Proposed Changes:
With
split_unit="word"andsplit_overlap > 0,RecursiveDocumentSplitter._run_oneadvanced the running position bylen(chunk) - len(overlap_str). In word mode_get_overlaprebuilds the overlap as" ".join(last_words), which has no trailing whitespace, while in the chunk those words are followed by the separator (" "with the default separators). The subtraction therefore left the position one separator past where the next chunk starts, so every chunk after the first hadsplit_idx_startshifted, and the_split_overlapranges (derived from the same position) inherited the error. The repro from #11710 still showed this onmain.This PR adds
_overlap_char_length, which for word mode measures the overlap from the first overlapping word (found with\S+positions) to the end of the chunk, trailing whitespace included, and returnslen(overlap)for the other units.current_positionnow lands on the first overlapping word, which is where the next chunk begins. Character and token splitting are unchanged.Before / after for
split_length=4, split_overlap=1, split_unit="word"on the #11710 sentence:split_idx_startbeforetext.index(content)"one. This is sentence""sentence two. This is""is sentence three. This""This is sentence four."How did you test it?
Three new unit tests in
test/components/preprocessors/test_recursive_splitter.py: the #11710 sentence with an explicit" "separator (asserting exact chunk contents and offsets), a plain-text run with the default separators, and asplit_unit="char"control. A shared helper assertstext[split_idx_start:]starts with every chunk and that the_split_overlapranges of consecutive chunks select the same text. The two word-mode tests fail onmainand pass with this change; the whole module (63 tests) passes.ruff check,ruff format --checkandmypyare clean on the changed files.Notes for the reviewer
page_number; the hunks are adjacent but distinct.releasenotes/notes/.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.