Your Medical Documents. Your Device. Your Privacy.
A privacy-first iOS application that brings the power of AI to your personal medical recordsβ
100% offline, zero data leaves your device.
MediVault is a fully on-device Retrieval-Augmented Generation (RAG) system designed for personal medical document management. Scan your prescriptions, lab results, and medical records, then ask questions in natural languageβall powered by AI running entirely on your iPhone.
"What was my blood pressure at my last checkup?"
"Show me my cholesterol levels over time."
"What medications was I prescribed in January?"
MediVault retrieves relevant information from your scanned documents and generates accurate, cited answersβwithout ever connecting to the internet.
| Feature | Description |
|---|---|
| π 100% Offline | No network calls, no cloud storage, no telemetry. Your medical data never leaves your device. |
| π· Smart Document Scanning | Scan multi-page documents using your camera with automatic edge detection. |
| πΌοΈ Photo Import | Import existing photos of medical documents from your library. |
| π§ On-Device AI | Powered by Qwen 2.5-1.5B running locally via llama.cppβno API keys needed. |
| π Semantic Search | Find information using natural language, not keywords. Ask questions like you would ask a doctor. |
| β Grounded Answers | Every response is validated against your actual documents with cited sources. |
| π‘οΈ Medical Safety Guardrails | The AI is explicitly designed to never provide medical diagnoses or treatment advice. |
| π¬ Multi-Turn Conversations | Context-aware follow-up questions for deeper exploration of your records. |
MediVault implements a complete RAG pipeline optimized for mobile:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MediVault Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β π± UI Layer (SwiftUI) β
β βββ ChatView - Conversational interface β
β βββ DocumentsTab - Document management β
β βββ ScannerView - VisionKit document capture β
β β
β π§ RAG Orchestrator β
β βββ EmbeddingService - CoreML MiniLM (384-dim vectors) β
β βββ VectorStore - SQLite + cosine similarity search β
β βββ Phi4MiniService - Qwen 2.5-1.5B via llama.cpp β
β βββ PromptBuilder - Context-aware prompt engineering β
β βββ GroundingValidator- Claim verification against sources β
β βββ SafetyFilter - Medical safety guardrails β
β β
β π Ingestion Pipeline β
β βββ VisionOCRService - Apple Vision accurate text recognition β
β βββ TextChunker - Semantic chunking with overlap β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
graph LR
A[User Question] --> B[Embed Query<br>MiniLM 384d]
B --> C[Vector Search<br>Top 3 Chunks]
C --> D[Build Prompt<br>Context + Query]
D --> E[LLM Generate<br>Qwen 2.5-1.5B]
E --> F[Validate<br>Grounding Check]
F --> G[Safety Filter]
G --> H[Display Answer<br>with Citations]
- Xcode 26.2+
- iOS 26.2+ device (iPhone only, simulator not recommended due to ML models)
- ~1GB storage for models
- Hugging Face CLI for model download
-
Clone the repository
git clone https://github.com/yourusername/MediVault.git cd MediVault -
Download the LLM model (~986MB)
mkdir -p MediVault/Resources/Models hf download \ enacimie/Qwen2.5-1.5B-Instruct-Q4_K_M-GGUF \ "qwen2.5-1.5b-instruct-q4_k_m-00001-of-00001.gguf" \ --local-dir MediVault/Resources/Models/π‘ Tip: Install Hugging Face CLI with
pip install huggingface_hub -
Open in Xcode
open MediVault.xcodeproj
-
Build and run on your iOS device
On first launch, MediVault will:
- Load the CoreML embedding model
- Initialize the SQLite vector database
- Load the Qwen LLM into memory
This may take 15-30 seconds depending on your device.
- Navigate to the Documents tab
- Tap Scan Document to use your camera, or Import from Photos for existing images
- The app will:
- Extract text using OCR
- Split into semantic chunks
- Generate embeddings
- Store in the local vector database
- Navigate to the Chat tab
- Ask any question about your medical history
- View the AI's response with:
- Confidence indicator (green/orange/red)
- Source count showing how many documents were referenced
- Sources button to view the exact text snippets used
- "What was my hemoglobin level?"
- "When was my last vaccination?"
- "Summarize my visit to Dr. Smith"
- "What medications am I currently taking?"
| Component | Technology | Purpose |
|---|---|---|
| UI Framework | SwiftUI | Declarative, modern iOS UI |
| State Management | @Observable |
Swift 5.9+ observation framework |
| Concurrency | Swift Actors | Thread-safe services |
| Database | GRDB.swift | SQLite with Swift-native API |
| Embeddings | CoreML + MiniLM | 384-dimensional text vectors |
| Tokenization | swift-transformers | HuggingFace tokenizers |
| LLM Inference | swift-llama-cpp | Optimized on-device inference |
| OCR | Apple Vision | Accurate text recognition |
| Document Scanning | VisionKit | Native camera-based scanning |
MediVault is designed with privacy as the foundational principle:
| Aspect | Implementation |
|---|---|
| Data Storage | All data stored locally in app sandbox |
| Network Access | Zero network callsβcompletely offline |
| ML Inference | All models run on-device using CoreML and llama.cpp |
| Medical Safety | AI explicitly cannot provide diagnoses or treatment advice |
| No Analytics | No telemetry, no crash reporting, no user tracking |
β οΈ Disclaimer: MediVault is a document retrieval tool, not a medical device. Always consult healthcare professionals for medical decisions.
- Model: MiniLM-L6 (float16 CoreML)
- Dimensions: 384
- Sequence Length: 128 tokens
- Compute: CPU/GPU/Neural Engine
- Model: Qwen 2.5-1.5B Instruct (Q4_K_M quantization)
- Context: 4096 tokens
- Batch Size: 256
- Output: Structured JSON with citations
π‘ Model Evolution: Initially developed with Phi-3 Mini 3.8B (4-bit), later migrated to Qwen 2.5-1.5B for improved performance on medical terminology and better structured JSON output compliance.
- Algorithm: Brute-force cosine similarity (optimized with Accelerate)
- Threshold: 0.5 minimum similarity
- Results: Top 3 most relevant chunks
- Chunk Size: 500 characters
- Overlap: 50 characters
- Boundary Detection: Sentence-aware splitting
MediVault/
βββ App/
β βββ MediVaultApp.swift # App entry point
βββ Features/
β βββ Chat/ # Conversational UI
β βββ Embedding/ # CoreML embedding service
β βββ Generation/ # LLM inference
β βββ Home/ # Tab navigation
β βββ Ingestion/ # OCR & document import
β βββ RAG/ # Core AI orchestration
β β βββ Grounding/ # Answer validation
β β βββ Orchestrator/ # Query coordination
β β βββ Prompt/ # Prompt engineering
β β βββ Protocols/ # Service interfaces
β β βββ Safety/ # Medical guardrails
β βββ VectorDB/ # Vector storage
βββ Resources/
β βββ Models/ # ML models (see setup)
βββ Assets.xcassets/ # App assets
- iPad support with split-view
- Document categories and tagging
- Export reports as PDF
- Apple Watch companion for quick queries
- Multi-language OCR support
- iCloud backup (encrypted)
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- GRDB.swift - A toolkit for SQLite databases
- swift-transformers - Swift implementation of HuggingFace tokenizers
- swift-llama-cpp - Swift bindings for llama.cpp
- Qwen - The Qwen team for the open-source LLM
Built with β€οΈ for privacy-conscious healthcare