01The Engineering Reality
The Engineering Reality: Air-Gapped Constraints
The Aadhaar ecosystem operates under stringent air-gapped security guidelines. There are no external cloud calls, no managed vector database clusters, and no commercial API keys. Every binary, neural network weight, and database engine must execute locally inside an isolated network perimeter.
02The OCR Problem
The OCR Problem: 50MB Scanned PDFs Across 12 Languages
Incoming documents arrived as heavy multi-page scans with varying DPI, coffee-cup ring stains, and skewed orientations. To extract usable text across 12 distinct Indic scripts (including Devanagari, Bengali, Tamil, Telugu, and Gurmukhi), we built an OpenCV preprocessing pipeline:
- Adaptive thresholding and morphological deskewing.
- Connected-component noise removal to clean speckled backgrounds.
- Custom Tesseract OCR tiling that splits heavy scans into manageable bounding boxes, preventing memory blow-ups on 50MB files.
03Search Architecture
Search Architecture: Hybrid FAISS + BM25 with Cross-Encoder
Standard vector search struggles when an operator searches for a specific 12-digit reference number or a narrow date stamp. To solve this without hallucination:
1. BM25 indexes exact tokens and document serial numbers.
2. FAISS IndexFlatIP handles semantic sentence queries.
3. A local cross-encoder reranks the top 25 merged results down to 5 precision passages passed to a quantized Ollama language model.
04High-Throughput SQLite WAL ETL Pipeline
High-Throughput SQLite WAL ETL Pipeline
Operators frequently uploaded 100,000-row tracking workbooks. Initial attempts to parse these synchronously blocked the event loop. We re-engineered the ingest with:
- FastAPI background worker tasks streaming live progress updates over WebSockets.
- Direct streaming with openpyxl in read-only mode to avoid loading whole sheets into RAM.
- SQLite configured with WAL mode (Write-Ahead Logging), synchronous=NORMAL, and 5,000-row batch transactions. Ingestion time dropped from over 4 minutes to 5–15 seconds.
05Security & Access Control
Security & Access Control
For 1,000+ operators, we implemented scoped JWT authentication with bcrypt password hashing and row-level SQLite query guards, ensuring regional operators could only query records within their assigned administrative boundaries.
06Postmortem
Lessons from the trenches
- –Edge and on-premise AI requires defensive programming against memory leaks. Always test with production-sized 50MB PDFs, not clean 1-page sample files.
- –SQLite WAL with chunked batching is capable of enterprise-scale ingestion on commodity hardware.
- –Hybrid search (dense vector + sparse keyword) is mandatory for document systems with real numbers and codes.
Next

