fix: DocumentCleaner wiped the middle page of a 3-page document - #11921
Merged
bogdankostic merged 2 commits intoJul 9, 2026
Merged
Conversation
|
@Otis0408 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
otiscuilei
force-pushed
the
fix/document-cleaner-3-page-wipe
branch
2 times, most recently
from
July 9, 2026 05:50
a06e286 to
a53b74d
Compare
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
With remove_repeated_substrings=True, header/footer detection compares the pages between the first and last. For a 3-page document that slice is a single page, and _find_longest_common_ngram reduced set.intersection over that one page's ngrams to the page's own longest ngram, which was then removed from every page, wiping the unique middle page. Require at least two sequences before deriving a common ngram.
otiscuilei
force-pushed
the
fix/document-cleaner-3-page-wipe
branch
from
July 9, 2026 07:46
a53b74d to
4d77e37
Compare
bogdankostic
approved these changes
Jul 9, 2026
bogdankostic
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix @Otis0408!
Contributor
Author
|
Thanks for the review and merge, much appreciated! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Who hits this: anyone running DocumentCleaner with remove_repeated_substrings=True over documents that use form-feed (\f) page separators and have exactly three pages — a common shape for short PDFs. The unique middle page silently disappears from the cleaned output.
Root cause: header/footer detection derives a common ngram only from the pages strictly between the first and the last (pages[n_first_pages_to_ignore:-n_last_pages_to_ignore]). For a 3-page document that slice is a single page. _find_longest_common_ngram was written to guard only the empty case, so with one sequence reduce(set.intersection, ...) returned that page's own ngram set and picked its longest ngram. That ngram was then treated as a repeated header/footer and str.replace'd out of every page, wiping the middle page's content.
Fix: require at least two sequences before deriving a "common" ngram. A single sequence shares no ngram with any other, so there is nothing to remove. Genuine repeated headers/footers (documents with two or more comparable inner pages) are still detected and stripped exactly as before.
Before/after with the public component API:
Tests: adds a regression test that runs the 3-page document through DocumentCleaner and asserts the full content round-trips unchanged — all three pages preserved in order, not merely the middle one. Verified it fails on the pre-fix code and passes with the fix. Includes a release note.