Skip to content

fix: populate _split_overlap metadata for word/token units in RecursiveDocumentSplitter - #11825

Merged
sjrl merged 4 commits into
deepset-ai:mainfrom
Osamaali313:fix/recursive-splitter-word-token-overlap-metadata
Jul 6, 2026
Merged

fix: populate _split_overlap metadata for word/token units in RecursiveDocumentSplitter#11825
sjrl merged 4 commits into
deepset-ai:mainfrom
Osamaali313:fix/recursive-splitter-word-token-overlap-metadata

Conversation

@Osamaali313

Copy link
Copy Markdown
Contributor

Related Issues

None — found while reviewing RecursiveDocumentSplitter overlap handling (a follow-up to the split_idx_start family, #11710/#11711, which fixed a different site).

Proposed Changes

_add_overlap_info computed the overlap length with self._chunk_length(prev_doc.content), which returns a word/token count for split_unit="word"/"token", while curr_pos and split_idx_start are character offsets. Mixing units made overlap_length negative, so the if overlap_length > 0 guard never fired and the _split_overlap metadata was silently left empty for word/token splitting with overlap (char units were unaffected, since there len == _chunk_length).

Fix: measure the overlap and ranges in characters via len(prev_doc.content).

# before (word unit, split_overlap=1): every chunk's _split_overlap == []
# after: overlap provenance is populated for all overlapping chunks

How did you test it?

Added test_run_split_by_dot_and_overlap_1_word_unit_split_overlap_metadata, which fails on main (empty metadata) and passes after the fix. Full test_recursive_splitter.py: 49 passed. Release note added under releasenotes/notes/.

Checklist


Disclaimer: this PR was prepared with AI assistance (Claude). I reviewed the change and verified it RED→GREEN against the real component before submitting.

…veDocumentSplitter

_add_overlap_info computed the overlap length with self._chunk_length(prev_doc.content), which returns a word/token count for word/token split units, while curr_pos and split_idx_start are character offsets. Mixing units made overlap_length negative, so the guard never fired and the _split_overlap metadata was silently left empty for word/token splitting with overlap (char units were unaffected). Measure the overlap and ranges in characters via len(prev_doc.content). Adds a regression test and a release note.
@Osamaali313
Osamaali313 requested a review from a team as a code owner June 29, 2026 19:09
@Osamaali313
Osamaali313 requested review from Copilot and sjrl and removed request for a team and Copilot June 29, 2026 19:09
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Osamaali313 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 Jun 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sjrl sjrl self-assigned this Jun 30, 2026
Comment thread test/components/preprocessors/test_recursive_splitter.py Outdated
@sjrl

sjrl commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Hey @Osamaali313 thanks for opening the PR! Please address the failing CI issues.

Comment thread test/components/preprocessors/test_recursive_splitter.py Outdated
Comment thread haystack/components/preprocessors/recursive_splitter.py Outdated
@sjrl

sjrl commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Hey @Osamaali313 are you able to work on this, this week?

- Shorten the _add_overlap_info comment (per review).
- Rename test to test_word_unit_split_populates_split_overlap_metadata
  and drop the docstring paragraph referencing the old behavior.
- Use double backticks for inline code in the release note (reST) so the
  release-notes RST check passes.
- Run ruff format (collapse the _split_overlap dict literal) to fix the
  format check.
Copilot AI review requested due to automatic review settings July 6, 2026 06:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Osamaali313

Copy link
Copy Markdown
Contributor Author

Thanks @sjrl — yes, done. Pushed a commit addressing all the review points and the CI:

  • Comment wording (recursive_splitter.py): shortened to your suggested two-liner.
  • Test name: renamed to test_word_unit_split_populates_split_overlap_metadata.
  • Test docstring: removed the paragraph referring to the old behavior; it now just states the expected behavior.
  • Release note: switched inline code to double backticks (reST), which clears the release-notes RST formatting check.
  • format check: ran ruff format (it collapsed the _split_overlap dict literal).

Locally: ruff check + ruff format --check are clean, reno lint . passes, and the full test_recursive_splitter.py suite passes (49 passed). The only remaining red check is the Vercel preview deploy, which needs a maintainer to authorize the external-fork deploy. Let me know if you'd like anything else.

@github-actions github-actions Bot added the type:documentation Improvements on the docs label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/preprocessors
  recursive_splitter.py
Project Total  

This report was generated by python-coverage-comment-action

Comment thread test/components/preprocessors/test_recursive_splitter.py
Per review: replace the word-unit test's loose assertions with direct
asserts on the exact chunk contents and _split_overlap ranges, and add a
matching token-unit test. Values verified against the splitter output.
@Osamaali313

Copy link
Copy Markdown
Contributor Author

Done — thanks for the concrete suggestions. Both applied:

  • test_word_unit_split_populates_split_overlap_metadata now asserts the exact chunk contents and _split_overlap ranges for all 5 chunks.
  • Added test_token_unit_split_populates_split_overlap_metadata with the exact ranges for chunks 0, 1, and 7.

I ran the splitter against the actual output to confirm the expected values before committing (all of your suggested contents/ranges match). Both tests pass, the full test_recursive_splitter.py suite is green (50 passed), and ruff check + ruff format --check are clean.

Comment thread test/components/preprocessors/test_recursive_splitter.py

@sjrl sjrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sjrl
sjrl merged commit 1216c61 into deepset-ai:main Jul 6, 2026
23 of 24 checks passed
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.

4 participants