Repository navigation
Conversation
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
A page containing only stopwords still has candidate chunks, but cleaning leaves an empty BM25 vocabulary. rank_bm25 then divides by zero while calculating average IDF. Return no content when every cleaned candidate is empty.
Found from the current develop source; no corresponding issue has been filed. This PR does not claim to close an existing issue.
List of files changed and why
crawl4ai/content_filter_strategy.py: return an empty result before constructing BM25Okapi for a vocabulary with no terms.tests/unit/test_bm25_empty_corpus.py: add offline behavior regression tests.How Has This Been Tested?
The six new tests produce four failures on unchanged develop and all pass with the fix. They use the real BM25 implementation, with stemming enabled/disabled, thresholds 0/1 and mixed meaningful/empty candidates. The existing BM25 and #1213 deduplication tests produce the same 24 passes and five failures before and after this change. The unchanged failures are test_basic_extraction, test_user_query_override (outdated extract_page_query call missing body), test_header_extraction, test_no_metadata_fallback and test_large_content.
Run
python -m pytest tests/unit/test_bm25_empty_corpus.py -qfrom the repository root. The new test file and changed source block pass Black. The full source-file Black check fails on unchanged develop too; unrelated formatting is excluded.git diff --checkpasses. Browser/LLM integration tests and the full repository test suite were not run for these offline changes.Checklist:
Prepared with AI assistance; validation scope and limitations are listed above.