fix: skip complexity check when strategy is explicitly fast#4280
Open
AlonNaor22 wants to merge 1 commit intoUnstructured-IO:mainfrom
Open
fix: skip complexity check when strategy is explicitly fast#4280AlonNaor22 wants to merge 1 commit intoUnstructured-IO:mainfrom
AlonNaor22 wants to merge 1 commit intoUnstructured-IO:mainfrom
Conversation
The is_pdf_too_complex() check introduced in Unstructured-IO#4268 skips text extraction for complex PDFs. But when strategy="fast" is explicitly passed, this leaves extracted_elements empty, causing _partition_pdf_with_pdfparser() to return an empty list. Now the complexity check is bypassed when the user explicitly requests the fast strategy. Closes Unstructured-IO#4260 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
partition_pdf(strategy="fast")returns an empty list for PDFs flagged as "too complex"is_pdf_too_complex()check added in Add a check for complex pdfs #4268 skips text extraction when a PDF is complex, but whenstrategy="fast"is explicitly set, the strategy isn't changed — so_partition_pdf_with_pdfparser()receives emptyextracted_elementsand returns[]is_pdf_too_complex()check entirely whenstrategy="fast", since the user explicitly requested text-based extraction. The complexity check is only relevant forstrategy="auto"where it decides between fast and hi_res.Files changed
unstructured/partition/pdf.py— addedstrategy != PartitionStrategy.FASTguard before callingis_pdf_too_complex()test_unstructured/partition/pdf_image/test_pdf.py— added test verifying fast strategy bypasses complexity check and returns non-empty resultsTest plan
test_partition_pdf_fast_strategy_bypasses_complexity_check— mocksis_pdf_too_complexto return True, verifies it's never called when strategy is fast, verifies elements are extractedtest_partition_pdf_with_fast_strategy,test_partition_pdf_with_fast_strategy_from_file,test_partition_pdf_with_fast_groups_text)