Offline Sovereign AI Lab: Local Gemma 4 + SQLite RAG on GCP IAM Documentation
Regulated Canadian organizations (healthcare, finance, energy, public sector) keep asking the same question: can we run a useful AI assistant completely offline, with zero external API calls and strict local data residency?
Most online demos answer "yes" using a couple of PDFs and forgiving questions. That hides all the hard parts. To test where offline AI actually works and where it falls apart, I benchmarked a local 4-bit Gemma 4 E4B model (4.8 GB Metal VRAM, 5.4 GB RAM on an Apple M5 Pro) against 14,435 canonical GCP IAM permissions and 2,420 predefined roles extracted from an 8.0 GiB local SQLite documentation corpus.
Constraints
- Zero external APIs: Everything runs locally on an Apple M5 Pro (
48 GBunified memory). No OpenAI, no hosted Vertex/Azure endpoints, and zero data leaving the machine. - Zero-tolerance accuracy: Inventing a fake permission name or missing a required binding is a hard fail. All five runs were scored against the same
45-question golden set (15exact permission,15least-privilege role,15unanswerable/refusal). - Lean local stack: One SQLite database (dual FTS5 exact/Porter indexes plus
BAAI/bge-small-en-v1.5384-dim embeddings in a63 MiBhybrid index built in99.96s) paired withmlx-community/gemma-4-E4B-it-4bit(temp=0.0,max_tokens=1536).
Architecture Overview
[Public GCP IAM Docs (901 deduplicated docs → 19,480 structured chunks)]
│
▼
[SQLite: Dual FTS5 (tokenchars '._/-' + Porter) + 384-dim MPS Vectors]
│
Weighted RRF Fusion (top_k=5)
│
▼
[User IAM Query] ──▶ [Local Gemma 4 E4B 4-bit (Base or MLX LoRA)]
│
▼
[Zero-Tolerance Eval vs. 14,435 Permissions / 2,420 Roles]
Measured Results
| Run | Exact Perm Recall | Exact Perm Match | Role Recall | Refusal Rate | Doc Citation Acc. | Hard Fail Rate | Latency P50 / P95 |
|---|---|---|---|---|---|---|---|
| Exp A: Naive Vector | 78.33% | 66.67% | 70.00% | 100.0% | 53.33% | 2.22% | 11.49s / 18.87s |
| Exp B: Hybrid v1 | 90.00% | 76.67% | 86.67% | 100.0% | 76.67% | 2.22% | 11.59s / 15.94s |
| Exp B2: Hybrid v2 | 90.00% | 86.67% | 93.33% | 100.0% | 90.00% | 0.00% | 13.71s / 27.42s |
| Exp C: LoRA (iter 200) | 71.67% | 56.67% | 86.67% | 93.33% | 63.33% | 6.67% | 1.22s / 2.03s |
| Exp C2: Thought LoRA | 90.00% | 80.00% | 86.67% | 93.33% | 76.67% | 4.44% | 2.02s / 8.48s |
When Offline Wins (And When Regional Cloud Is Better)
All five benchmark runs (Exp A, B, B2, C, C2) are complete and reproducible on a single 4.8 GB VRAM footprint. The numbers show a clear boundary: an air-gapped local box earns its hardware and maintenance overhead when strict zero-egress security is mandatory and teams can accept either 13.71s median latency (0.00% hard fails on base Hybrid v2) or 2.02s interactive speed backed by deterministic validators (Concise-Thought LoRA, 4.44% residual hard fails).
If a regulated team needs multi-user throughput, frontier reasoning, or does not want to maintain local GPU hardware and eval suites, I do not recommend shipping an offline box just to check a sovereignty checkbox. In that case, the better architecture is a locked-down Canadian regional landing zone (northamerica-northeast1 or Azure Canada Central) with private endpoints, VPC Service Controls, zero-retention provider contracts, and automated DLP. Read the full failure-mode breakdown and under-the-hood mechanics in Offline GCP IAM Assistant With Local Gemma 4 and SQLite.