Worked case study: HIPAA doc-QA over 50M records
Let's run the whole framework on one prompt: "Design a clinical document Q&A assistant. Staff ask natural-language questions and get cited answers over ~50M patient documents. It must be HIPAA-compliant." This ties every module together.
1. Clarify & assumptions
- Users: clinicians; ~2,000 concurrent, ~50 QPS peak; interactive, target <2s TTFT.
- Task: grounded Q&A with citations over PHI; wrong/unsourced answers are high-cost.
- Data: 50M docs, growing; strict per-patient/role access control; HIPAA (BAA, audit, residency).
2. Success & evals
- Primary: groundedness + citation correctness + retrieval recall@k on a clinician-labeled golden set.
- Guardrails: p95 latency, cost/query, zero cross-patient leakage, refusal-when-unsure rate.
3. Architecture & AI core
AI core = RAG (grounded, citable, fresh) — not fine-tuning. Path: auth'd query → permission-filtered hybrid retrieval → rerank → grounded generation with citations → PHI-safe logging. Offline: ingestion/chunking/embedding with ACLs as metadata.
4. RAG at 50M scale, safely
- ANN (HNSW) index, sharded by facility/tenant, replicated for QPS; metadata pre-filter by patient/role ACL so forbidden docs never enter candidates.
- Hybrid search + cross-encoder rerank; recheck permissions on final chunks before the prompt.
- Incremental indexing for new records; quantization to control memory at 50M vectors.
5. Production: cost, latency, safety, observability
- Latency: stream tokens; cap output; tight retrieved-context budget for low TTFT.
- Cost: route easy queries to a small model, escalate hard ones; prefix-cache the stable system prompt; tenant-scoped semantic cache.
- Safety/PHI: retrieval-time ACLs, redact PII in logs, VPC deployment + BAA, audit log every access, treat retrieved notes as data (injection defense).
- Reliability: timeouts, backoff retries, provider fallback, graceful "insufficient evidence" answer over guessing.
- Observability: full tracing, offline evals gating deploys, online groundedness sampling + clinician thumbs feeding the feedback loop.
6. Tradeoffs (the close)
"I'm optimizing for groundedness and zero leakage over raw latency — reranking and permission rechecks add ~100-200ms I'm willing to pay in a clinical setting. If usage or cost spikes, I'd lean harder on caching and routing. I'd trust this once the golden-set groundedness and the leakage test both pass in CI."
◆ Lock it in
- Run the full framework: clarify → evals → architecture/core → deep-dive → production → tradeoffs.
- For private, cited, huge-corpus Q&A: RAG + hybrid/rerank + ANN sharding + retrieval-time ACLs.
- Win on structure + quantification + safety + honest tradeoffs, not one clever component.