feat: add OCR fallback for scanned PDF pages - #40
Merged
Conversation
pypdf's text extraction returns empty text for image-only/scanned PDF pages, silently dropping their content during ingestion. Pages whose extracted text falls below OCR_MIN_CHARS_PER_PAGE are now rasterized with pypdfium2 and read with Tesseract via pytesseract; OCR failures (e.g. missing tesseract binary) fall back to the original text instead of raising. Adds OCR_ENABLED/OCR_LANGUAGE/OCR_MIN_CHARS_PER_PAGE settings, installs tesseract-ocr in the Docker image, and documents the feature in docs/ocr.md.
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
pypdftext extraction, which silently returns empty text for scanned/image-only pages.OCR_MIN_CHARS_PER_PAGEare now rasterized withpypdfium2and OCR'd with Tesseract viapytesseract. OCR failures (e.g. missingtesseractbinary) fall back to the original text rather than raising.OCR_ENABLED(defaulttrue),OCR_LANGUAGE(defaulteng),OCR_MIN_CHARS_PER_PAGE(default20).tesseract-ocr.docs/ocr.md, plus updates todocs/architecture.md/docs/agent-navigation.mdper the repo's doc-maintenance rule.Test plan
uv run pytest -q— 93 passed (addstests/test_pdf_ocr.py, 4 new unit tests with mocked OCR/pdfium)uv run ruff format --check ./uv run ruff check .— cleanuv run mypy localrag/ --ignore-missing-imports --no-strict-optional— cleantesseractis installed and onPATHparse_pdfinside the container — OCR correctly extracted the embedded text end-to-end