Skip to content

fix: correct RecursiveDocumentSplitter split_idx_start for word overlap ending in a separator - #12757

Closed
anishmehta24 wants to merge 1 commit into
deepset-ai:mainfrom
anishmehta24:fix/recursive-splitter-word-overlap-offset
Closed

anishmehta24 wants to merge 1 commit into
deepset-ai:mainfrom
anishmehta24:fix/recursive-splitter-word-overlap-offset

Conversation

@anishmehta24

Copy link
Copy Markdown

Related Issues

Proposed Changes:

With split_unit="word" and split_overlap > 0, RecursiveDocumentSplitter._run_one advanced the running position by len(chunk) - len(overlap_str). In word mode _get_overlap rebuilds 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 had split_idx_start shifted, and the _split_overlap ranges (derived from the same position) inherited the error. The repro from #11710 still showed this on main.

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 returns len(overlap) for the other units. current_position now 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:

chunk split_idx_start before after text.index(content)
"one. This is sentence" 18 17 17
"sentence two. This is" 31 30 30
"is sentence three. This" 50 49 49
"This is sentence four." 69 68 68

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 a split_unit="char" control. A shared helper asserts text[split_idx_start:] starts with every chunk and that the _split_overlap ranges of consecutive chunks select the same text. The two word-mode tests fail on main and pass with this change; the whole module (63 tests) passes. ruff check, ruff format --check and mypy are clean on the changed files.

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

…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
anishmehta24 requested a review from a team as a code owner September 15, 2026 03:24
@anishmehta24
anishmehta24 requested review from anakin87 and removed request for a team September 15, 2026 03:24
@vercel

vercel Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

@anishmehta24 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Sep 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @anishmehta24, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from anakin87 September 15, 2026 04:32
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Sep 15, 2026
@HaystackBot
HaystackBot marked this pull request as draft September 15, 2026 04:32
@HaystackBot
HaystackBot marked this pull request as ready for review September 15, 2026 13:51
@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Sep 15, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @anishmehta24! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

@anishmehta24

Copy link
Copy Markdown
Author

@anakin87 CLA is signed now, so this should be ready for review.

@github-actions github-actions Bot added the type:documentation Improvements on the docs label Oct 1, 2026
@anakin87

anakin87 commented Oct 1, 2026

Copy link
Copy Markdown
Member

Thank you!

This was superseded by #13006

@anakin87 anakin87 closed this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RecursiveDocumentSplitter split_idx_start is off by the trailing separator with split_unit="word" and split_overlap > 0

4 participants