Problem
The app has a long startup time because heavy libraries (FAISS, torch, open_clip, cuML) are being imported at module load time, even when they aren't needed immediately.
Evidence from logs
[2026-01-29 11:14:11] INFO [faiss.loader] Loading faiss with AVX512 support.
[2026-01-29 11:14:11] INFO [faiss.loader] Successfully loaded faiss with AVX512 support.
These messages appear during app startup before any user action.
Expected behavior
Heavy libraries should only be loaded when explicitly needed:
- FAISS: only when user selects FAISS backend or auto-resolution chooses it
- torch/open_clip: only when user runs embedding generation
- cuML: only when user selects cuML backend
Root cause
Multiple files have module-level imports of heavy libraries:
shared/utils/clustering.py - imports sklearn, UMAP at module level
shared/utils/models.py - imports open_clip at module level
shared/services/embedding_service.py - imports torch and open_clip at module level
shared/components/clustering_controls.py - imports faiss and cuml for availability check
shared/utils/backend.py - availability checks aren't cached
Potential solution
Implement lazy loading pattern:
- Convert module-level imports to lazy-load functions
- Cache availability checks to avoid repeated imports
- Only import heavy libraries when their functionality is actually invoked
Notes
An initial lazy loading implementation was attempted but reverted as it caused other issues. A more careful approach is needed.
Problem
The app has a long startup time because heavy libraries (FAISS, torch, open_clip, cuML) are being imported at module load time, even when they aren't needed immediately.
Evidence from logs
These messages appear during app startup before any user action.
Expected behavior
Heavy libraries should only be loaded when explicitly needed:
Root cause
Multiple files have module-level imports of heavy libraries:
shared/utils/clustering.py- imports sklearn, UMAP at module levelshared/utils/models.py- importsopen_clipat module levelshared/services/embedding_service.py- importstorchandopen_clipat module levelshared/components/clustering_controls.py- importsfaissandcumlfor availability checkshared/utils/backend.py- availability checks aren't cachedPotential solution
Implement lazy loading pattern:
Notes
An initial lazy loading implementation was attempted but reverted as it caused other issues. A more careful approach is needed.