fix: populate _split_overlap metadata for word/token units in RecursiveDocumentSplitter - #11825
Conversation
…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 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey @Osamaali313 thanks for opening the PR! Please address the failing CI issues. |
|
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.
|
Thanks @sjrl — yes, done. Pushed a commit addressing all the review points and the CI:
Locally: |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
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.
|
Done — thanks for the concrete suggestions. Both applied:
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 |
Related Issues
None — found while reviewing
RecursiveDocumentSplitteroverlap handling (a follow-up to thesplit_idx_startfamily, #11710/#11711, which fixed a different site).Proposed Changes
_add_overlap_infocomputed the overlap length withself._chunk_length(prev_doc.content), which returns a word/token count forsplit_unit="word"/"token", whilecurr_posandsplit_idx_startare character offsets. Mixing units madeoverlap_lengthnegative, so theif overlap_length > 0guard never fired and the_split_overlapmetadata was silently left empty for word/token splitting with overlap (char units were unaffected, since therelen == _chunk_length).Fix: measure the overlap and ranges in characters via
len(prev_doc.content).How did you test it?
Added
test_run_split_by_dot_and_overlap_1_word_unit_split_overlap_metadata, which fails onmain(empty metadata) and passes after the fix. Fulltest_recursive_splitter.py: 49 passed. Release note added underreleasenotes/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.