Docling's own OCR engine swaps (tesseract, rapidocr) and table_mode
(fast vs accurate) were all benchmarked against the same problem page
and made no difference - confirmed the table-structure model itself
(TableFormer), not the OCR engine, is the bottleneck (see CLAUDE.md).
app/raw_ocr_extract.py sidesteps TableFormer entirely: runs OCR
directly (tesserocr) for raw per-word text+position, then reuses
table_extract.py's own column-geometry logic (_find_zones/_classify_
money/etc) to derive columns from word positions, the same way it
already does for native PDFs. Two real adaptations: pixel-to-point
scaling (exact for a scanned PDF via its own known point dimensions,
heuristic for a bare photo), and cross-page zone sharing (a page with
one-sided data, e.g. zero debits, can't reliably resolve its own
columns alone - confirmed for real on HSBC page 1 - so zones resolve
from whichever page is most complete and apply across the whole
document, deterministically fixing the sign-assignment bug a single
page alone can't).
Wired into reconcile._run_ocr_only as a PER-PAGE fallback, not
document-level - confirmed necessary for real: Docling succeeded on
one page and silently missed another's table in the same conversion
call, which a document-level "did any page work" check would have
missed entirely (10 real transactions, including debits, would have
vanished with no error).
Verified end-to-end through the real running app on a genuine 2-page
scanned test file (docs/scanned_statement_2page.pdf, built from real
HSBC pages 1+2): 17/17 transactions, correct signs and balances,
date_sanity correctly flagged the one real OCR misread. measure.py
confirms zero regression on the existing text-PDF corpus.
New dependencies: tesserocr, pypdfium2, pillow (Python) plus
tesseract-ocr/libtesseract-dev/libleptonica-dev (OS, Dockerfile).
TESSDATA_PREFIX must be set explicitly - tesserocr doesn't reliably
auto-discover Debian's tessdata path on its own.
Known limitation, documented not hidden: the one-sided-data edge case
is only reliably fixed with a second page to borrow zones from - a
true single-page photo upload has no such fallback and stays a close
geometric call.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Bettersight Statement Extractor as of Phase 1 build: bank-agnostic pdfplumber
extraction, Docling cross-check, the 6+1 checks, Excel export, and the
minimal web UI - all built and working.
Adds the measurement harness (measure.py) from the plan's step 10: runs
every fixtures/*.pdf with a matching *_ground_truth.xlsx against the real
pipeline, diffs date/description/amount/balance per transaction, and logs
a dated JSON result under results/. Also adds hand-verified ground truth
for the HSBC Sep statement and a new RBC fixture (RBC-CAD-Aug26.pdf, sourced
from docs/) with its own hand-verified ground truth - RBC extraction now has
regression coverage it previously lacked.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>