Skip to content

πŸ₯ MediVault β€” 100% offline iOS app for personal medical document management. Scan prescriptions & lab results, then ask questions in natural language. Powered by on-device RAG with CoreML embeddings and Qwen 2.5 LLM. Your health data never leaves your phone. Privacy by design.

License

Notifications You must be signed in to change notification settings

Junaed29/MediVault-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

iOS 26.2+ Swift 5.0 SwiftUI MIT License

πŸ₯ MediVault

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.


🎯 What is MediVault?

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.


✨ Key Features

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.

πŸ—οΈ Architecture

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            β”‚
β”‚                                                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Query Flow

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]
Loading

πŸš€ Getting Started

Prerequisites

  • 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

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/MediVault.git
    cd MediVault
  2. 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

  3. Open in Xcode

    open MediVault.xcodeproj
  4. Build and run on your iOS device

First Launch

On first launch, MediVault will:

  1. Load the CoreML embedding model
  2. Initialize the SQLite vector database
  3. Load the Qwen LLM into memory

This may take 15-30 seconds depending on your device.


πŸ“± Usage

Scanning Documents

  1. Navigate to the Documents tab
  2. Tap Scan Document to use your camera, or Import from Photos for existing images
  3. The app will:
    • Extract text using OCR
    • Split into semantic chunks
    • Generate embeddings
    • Store in the local vector database

Asking Questions

  1. Navigate to the Chat tab
  2. Ask any question about your medical history
  3. 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

Example Queries

  • "What was my hemoglobin level?"
  • "When was my last vaccination?"
  • "Summarize my visit to Dr. Smith"
  • "What medications am I currently taking?"

πŸ› οΈ Tech Stack

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

πŸ” Privacy & Security

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.


πŸ§ͺ Technical Highlights

Embedding Pipeline

  • Model: MiniLM-L6 (float16 CoreML)
  • Dimensions: 384
  • Sequence Length: 128 tokens
  • Compute: CPU/GPU/Neural Engine

LLM Configuration

  • 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.

Vector Search

  • Algorithm: Brute-force cosine similarity (optimized with Accelerate)
  • Threshold: 0.5 minimum similarity
  • Results: Top 3 most relevant chunks

Text Chunking

  • Chunk Size: 500 characters
  • Overlap: 50 characters
  • Boundary Detection: Sentence-aware splitting

πŸ“‚ Project Structure

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

πŸ—ΊοΈ Roadmap

  • 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)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments


Built with ❀️ for privacy-conscious healthcare

About

πŸ₯ MediVault β€” 100% offline iOS app for personal medical document management. Scan prescriptions & lab results, then ask questions in natural language. Powered by on-device RAG with CoreML embeddings and Qwen 2.5 LLM. Your health data never leaves your phone. Privacy by design.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages