A native iOS application for document-based question answering using Retrieval Augmented Generation (RAG). The app combines Couchbase Lite vector search with AI-powered language models to enable intelligent conversations about your PDF documents.
This application allows users to upload PDF documents, automatically processes and indexes them using vector embeddings, and then answer questions about the content using AI. The system retrieves relevant context from the documents using semantic search and generates natural language responses.
- PDF Document Processing - Upload and automatically process PDF documents into searchable chunks
- Vector Search - Fast semantic search powered by Couchbase Lite's vector distance functions
- Multiple AI Providers - Support for Google Gemini API and local on-device models
- Secure Credential Storage - API keys stored securely in iOS Keychain
- Background Downloads - Download large language models with progress tracking and notifications
- Modern iOS Design - Built entirely with SwiftUI and Swift Concurrency
The application follows the MVVM (Model-View-ViewModel) pattern with clear separation of concerns:
Edge-PDF-RAG-iOS/
├── Models/ # Data models
│ ├── Document.swift
│ ├── Chunk.swift
│ └── LocalModel.swift
├── Services/ # Business logic layer
│ ├── DatabaseManager.swift
│ ├── KeychainManager.swift
│ ├── PDFProcessor.swift
│ ├── SentenceEmbeddingProvider.swift
│ ├── LLMService.swift
│ └── BackgroundDownloadManager.swift
├── ViewModels/ # View state management
│ ├── ChatViewModel.swift
│ ├── DocsViewModel.swift
│ ├── CredentialsViewModel.swift
│ └── LocalModelsViewModel.swift
└── Views/ # SwiftUI interface
├── ChatView.swift
├── DocsView.swift
├── CredentialsView.swift
├── LocalModelsView.swift
├── LLMProviderView.swift
└── DownloadProgressBanner.swift
- Language: Swift 6.0
- UI Framework: SwiftUI
- Database: Couchbase Lite 3.2+
- PDF Processing: PDFKit
- AI Integration: Google Gemini API
- Async Programming: Swift Concurrency (async/await)
- Security: iOS Keychain Services
- iOS 17.0 or later
- Xcode 16.4 or later
- Swift 6.0
- Google Gemini API key (free tier available)
- Clone the repository
- Open
Edge-PDF-RAG-iOS.xcodeprojin Xcode - Add the Couchbase Lite dependency:
- File > Add Package Dependencies
- Enter:
https://github.com/couchbase/couchbase-lite-ios - Version: 3.2.0 or later
- Select: CouchbaseLiteSwift
- Build and run the project
- Launch the app
- Tap the menu button (three dots)
- Select "Edit Credentials"
- Enter your Gemini API key (get one at https://aistudio.google.com/apikey)
- Save the credentials
- Navigate to the Documents tab
- Tap "Upload PDF"
- Select a PDF file from your device
- Wait for processing to complete
- Go to the Chat tab
- Type your question about the uploaded documents
- The system will search for relevant content and generate an answer
- User uploads a PDF document
- PDFProcessor extracts text content
- Text is split into smaller chunks
- Sentence embeddings are generated for each chunk
- Chunks and embeddings are stored in Couchbase Lite
- User asks a question
- System generates an embedding for the question
- Vector similarity search finds the most relevant document chunks
- Retrieved chunks are sent as context to the LLM
- LLM generates a response based on the context
- Response is displayed to the user
The app supports downloading and using local language models for offline inference:
- Qwen2.5 0.5B - Fast and lightweight (500MB)
- Qwen2.5 1.5B - Balanced performance (1.5GB)
- Qwen2.5 3B - Higher quality (3GB)
- Phi 4 Mini - Microsoft's compact model (2.5GB)
Note: Local model inference requires MediaPipe LiteRT, which is expected to be available for iOS in early 2025. The download and model management features are fully functional.
The application requires a Google Gemini API key for cloud-based inference. Keys are stored securely in the iOS Keychain and never leave your device except for authorized API calls.
You can obtain a free Gemini API key from Google AI Studio: https://aistudio.google.com/apikey
xcodebuild test -scheme Edge-PDF-RAG-iOS \
-destination 'platform=iOS Simulator,name=iPhone 16 Pro'xcodebuild -scheme Edge-PDF-RAG-iOS \
-destination 'platform=iOS Simulator,name=iPhone 16 Pro' \
clean build- Embeddings use a simplified implementation. Production deployments should use CoreML models
- Local model inference awaits MediaPipe LiteRT iOS release
- Large PDFs may take time to process depending on device capabilities
- CoreML-based sentence embeddings for improved performance
- On-device LLM inference when MediaPipe LiteRT becomes available
- Support for additional document formats (DOCX, TXT, etc.)
- Multi-document conversations
- Export conversation history