# AI Search Expanded File Support Phase 6A: OCR Foundation Prompt

**Status:** Implemented for standalone PNG/JPEG OCR; PDF OCR deferred
**Priority:** Low
**Dependencies:** Phase 1 PDF, Phase 2 DOCX, Phase 3 XLSX, Phase 4 PPTX, Phase 5 Google Workspace Export

---

## Implementation Summary

Phase 6A adds the OCR foundation for AI indexing under
`src/lib/search/ai/extraction`. OCR is disabled by default and can only run when
`AI_SEARCH_OCR_ENABLED=true` or when tests inject an OCR config/provider.

### Implemented

- Provider-agnostic OCR port and typed `OcrExtractionError`.
- Namespaced OCR config:
  - `AI_SEARCH_OCR_ENABLED`
  - `AI_SEARCH_OCR_PROVIDER`
  - `AI_SEARCH_OCR_TIMEOUT_MS`
  - `AI_SEARCH_OCR_MIN_CONFIDENCE`
  - `AI_SEARCH_OCR_MAX_PAGES`
  - `AI_SEARCH_OCR_MAX_IMAGES`
- Local Tesseract.js OCR adapter using dynamic import.
- Standalone PNG/JPEG OCR extraction when OCR is enabled.
- OCR metadata preservation on successful extracted documents.
- Renderer-unavailable unsupported result for scanned PDF OCR fallback.
- Deterministic unit, extraction integration, and runner tests using mocked OCR providers.

### Deferred

Scanned PDF OCR and Google Drawing PDF OCR fallback are deferred. The existing
`pdfjs-dist` dependency can extract embedded text, but page rendering in Node
uses `@napi-rs/canvas`, which adds native dependency and deployment validation
requirements for Windows, Vercel, and Fly.io.

### Unsupported In Phase 6A

- GIF, TIFF, BMP, WebP, HEIC
- Office embedded images
- Full rendered PPTX slide OCR
- Handwriting as a guaranteed feature
- Complex table structure extraction
- Form field detection
- Mathematical equation extraction
- Image preprocessing
- Cloud OCR providers
- OCR caching

### Verification Scope

Normal tests must mock OCR provider responses and must not call real OCR,
Google Vision, AWS Textract, Azure Computer Vision, or network OCR services.
