You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RecursiveDocumentSplitter with overlap emits chunks not present in the source #12281
RecursiveDocumentSplitter with split_overlap > 0 produces chunks that contain text not in the source document. It happens whenever the text needs more than one separator level to split, which includes the default separators. _apply_overlap runs at every level of the internal recursion, so an already-overlapped chunk gets the overlap prepended again, duplicating and rearranging text.
This is separate from the already-fixed overlap issues #11767 (overlap ignored when no separator matches) and #11710 (split_idx_start offset); here the chunk content itself is wrong.
To Reproduce
fromhaystackimportDocumentfromhaystack.components.preprocessors.recursive_splitterimportRecursiveDocumentSplittertext="Overview\nThis module handles ingestion and preprocessing of documents.\n\nDetails\nIt splits text into chunks for embedding."splitter=RecursiveDocumentSplitter(split_length=50, split_overlap=10, split_unit="char")
splitter.warm_up()
forcinsplitter.run([Document(content=text)])["documents"]:
print(c.contentintext, repr(c.content))
3 of the 6 chunks are not in the source:
False "Overview\nOverview\nThis module handles ingestion an"
False "gestion and preprocnd preprocessing rocessing of d"
Expected behavior
Every chunk should be text from the source document. Overlap should be applied once, not at each recursion level.
System:
Haystack version: 3.1.0rc0 (main)
I'm planning to open a PR that applies the overlap once, at the outermost level, so the recursive calls return non-overlapped chunks. If you'd prefer a different approach, let me know.
The root cause is _apply_overlap being called at every recursion level of _chunk_text: inner-level chunks get the overlap prepended a second time by the enclosing level, producing chunks that are not substrings of the source. The PR applies the overlap exactly once, on the fully chunked list in _run_one.
Activity
chore: add release note for single overlap application (deepset-ai#12281
style: simplify fallback return after removing per-level overlap (dee…
chore: use RST double backticks in release note (deepset-ai#12281)
Diwak4r commentedon Aug 10, 2026
Hey, I opened a PR that fixes this: #12284
The root cause is
_apply_overlapbeing called at every recursion level of_chunk_text: inner-level chunks get the overlap prepended a second time by the enclosing level, producing chunks that are not substrings of the source. The PR applies the overlap exactly once, on the fully chunked list in_run_one.