Location: src/api/routers/document.py:1004-1010
Problem: OCR is called without layout_result parameter, but extract_text() requires it
Impact: This may cause runtime errors or OCR may be using an empty dict
Fix Required: Add layout detection before OCR, or make layout_result optional
Location: src/api/routers/document.py:998-1019
Problem: All stages run sequentially
Impact: Slower processing time
Optimization: Parallelize OCR + Layout Detection
- Add LayoutDetectionService to router flow
- Ensure OCR receives proper layout_result
- Test that current flow works correctly
- Use
asyncio.gather()to run OCR and Layout Detection in parallel - Both depend on preprocessing_result, but are independent
- OCR can work with minimal/empty layout initially, then enhance later
- Create Redis cache service
- Cache status queries (30s TTL)
- Cache embeddings (24h TTL, content-hash based)
- Cache API responses (1h TTL)
- Implement SSE endpoint for real-time updates
- Replace polling with SSE connection
- Add exponential backoff fallback
- Add optimistic UI updates
- ✅
docs/architecture/PHASE2_PERFORMANCE_PLAN.md- Overall plan - ✅
src/api/services/document/parallel_executor.py- Parallel execution utilities - ✅
docs/architecture/PHASE2_IMPLEMENTATION_STATUS.md- This file
- Fix Bug: Add layout detection to router flow
- Implement Parallel: Make OCR + Layout run in parallel
- Test: Verify no regressions
- Measure: Compare processing times
- Step 1 (Fix Bug): Low risk, fixes existing issue
- Step 2 (Parallel): Low risk, independent operations
- Step 3 (Caching): Medium risk, need cache invalidation
- Step 4 (Frontend): Higher risk, user-facing changes