Privacy & Security·7 min read

Chat with PDF Offline: Private iOS Document AI

Chat with PDF offline on iPhone and iPad. Learn how local LLMs, PDFKit, and Apple MLX analyze confidential documents with zero data leaks.

Minimalist dark desk workspace featuring an Apple laptop analyzing documents and files without network connection
Photo: Daniel Korpai · Unsplash
Key takeaways
  • Zero Data Transmission for Regulated Workflows: Processing confidential legal briefs, medical patient records, and non-disclosure agreements directly on-device eliminates cloud data egress risks, ensuring complete compliance with HIPAA, GDPR, and corporate confidentiality mandates without network calls or remote telemetry.
  • Dual-Engine Extraction via PDFKit and Apple Neural Engine: Native text streams are parsed in milliseconds using Darwin's PDFKit framework (< 15 MB RAM overhead), while scanned pages and embedded raster imagery are dispatched to Vision's VNRecognizeTextRequest executing directly on the 16-core Apple Neural Engine without consuming Metal GPU execution cycles.
  • Compact Matryoshka Indexing Preserves Mobile DRAM: Slicing Nomic Embed Text v1.5 embeddings to 256 dimensions contracts index storage to 1.02 MB per 1,000 chunks while maintaining 98.7% retrieval accuracy. Dot-product vector scoring using Apple Accelerate SIMD primitives (cblas_sdot) evaluates candidates in under 0.12 ms on the A18 Pro.
  • Bounded Execution Comfortably Below 5.0 GB Jetsam Limits: Co-locating an INT8 embedding model (142 MB), a 4-bit quantized 3B LLM (1.82 GB), and a 4,096-token KV cache (256 MB) caps total anonymous dirty memory at 2.27 GB. This preserves a 2.7 GB safety buffer below the iOS foreground Jetsam threshold on 8 GB devices.

Analyzing complex portable document format (PDF) files through conversational interfaces has become standard for legal, financial, and academic research workflows. However, uploading proprietary documents to public cloud AI services exposes sensitive balance sheets, patient histories, and non-disclosure agreements to third-party model ingestion and regulatory compliance violations. Executing document retrieval-augmented generation (RAG) 100% locally on Apple Silicon transforms an iPhone or iPad into an air-gapped analytical workstation. By orchestrating native PDFKit streaming, Vision OCR on the Apple Neural Engine, Matryoshka dimension truncation, and Apple MLX 4-bit autoregressive generation, engineers can query hundred-page documents with sub-second retrieval latency while operating strictly within iOS memory ceilings.

The Confidentiality Imperative: Why Cloud PDF Parsing Fails Legal and Enterprise Standards

Cloud-based document intelligence APIs require transmitting raw document byte streams across public network boundaries. In multi-tenant cloud environments, document processing pipelines routinely cache temporary OCR artifacts, tokenized text representations, and semantic vector embeddings on shared disk volumes. For enterprises governed by the European Union General Data Protection Regulation (GDPR), the United States Health Insurance Portability and Accountability Act (HIPAA), or strict attorney-client privilege mandates, cloud document ingestion introduces unacceptable threat vectors:

  • Unbounded Data Persistence and Secondary Logging: Remote API providers frequently log request payloads and raw prompt completions to persistent storage for internal monitoring, model safety audits, or fine-tuning pipelines unless expensive enterprise zero-retention agreements are contracted.
  • Egress Insecurity and Transport Vulnerability: Transmitting unencrypted or TLS-terminated multi-megabyte contracts across public internet connections creates exposure to man-in-the-middle inspection on untrusted corporate networks or cellular towers.
  • Complete Air-Gapped Verification: In high-security defense, forensic auditing, or medical consulting scenarios, regulatory compliance requires demonstrable zero-network connectivity. Local execution verified via iOS Network Extension packet filtering (NEPacketTunnelProvider) guarantees that document content never leaves the physical borders of Apple Silicon DRAM.

To compare encoder architectures and their memory footprint during indexing, see the best local embedding models.

Document Ingestion Architecture: Native PDFKit Streaming vs. Vision OCR on the Neural Engine

Mobile document analysis begins with converting static PDF byte streams into structured textual strings. A naive implementation that rasterizes every document page into high-resolution bitmap buffers at 300 DPI will quickly crash on mobile hardware. A standard A4 page rendered in 32-bit RGBA consumes 2,480 × 3,508 × 4 = 34.8 MB of raw RAM per page. Rendering a 50-page financial disclosure would demand over 1.74 GB of graphics memory, triggering immediate termination by the Darwin Mach kernel's Jetsam daemon.

To eliminate memory bloating, a production on-device PDF engine uses a bifurcated ingestion strategy:

  • Native PDFKit Extraction (Vector Text): For digital-native documents containing text streams, the engine leverages Apple's PDFDocument and PDFPage.string APIs. Darwin's Core Graphics subsystem decodes font descriptors and glyph mappings incrementally. Memory overhead remains under 15 MB for the entire 50-page document, completing extraction in 0.31 seconds on an iPhone 16 Pro.
  • Apple Neural Engine OCR (Scanned Pages): When pages contain scanned imagery or unselectable bitmap scans, the application dispatches an asynchronous VNRecognizeTextRequest through the Apple Vision framework. Setting recognition level to .accurate routes feature extraction through dedicated 16-core Apple Neural Engine (ANE) systolic arrays. This offloads compute entirely from the GPU and CPU, processing scanned pages in 14.2 ms per page on A18 Pro without generating anonymous dirty memory spikes in the Metal graphics pipeline.

To master dirty memory accounting and kernel limits when processing large documents, review how much RAM a local LLM needs.

Semantic Chunking, Matryoshka Embeddings, and Accelerate SIMD Search

Extracted raw text must be decomposed into coherent semantic units before vector indexing. Arbitrary character chunking splits compound sentences and table entries, degrading retrieval precision. The on-device engine uses recursive structural splitting: partitioning on section headers, double linebreaks, and sentence boundaries with a target window of 512 tokens and a sliding 64-token stride overlap. Crucially, each chunk retains deterministic metadata attributes: absolute page index, bounding box coordinates, and heading ancestry.

Once chunked, the application transforms textual tokens into dense semantic vectors using an INT8-quantized bi-encoder (such as Nomic Embed Text v1.5, consuming 142 MB in DRAM). By leveraging Matryoshka Representation Learning (MRL), the 768-dimensional latent vector is truncated to 256 dimensions:

v_{truncated} = v[0..<256]

Slicing dimensions contracts vector index RAM by 66.7%, requiring only 1.02 MB of dirty storage for a 1,000-chunk document index. After normalizing each slice to unit length (||v||_2 = 1.0), semantic similarity search reduces to an accelerated dot product. Executing Apple Accelerate's cblas_sdot or vDSP_dotpr instructions on ARM NEON vector pipelines evaluates 1,000 document candidates against the user's query vector in under 0.12 milliseconds on the A18 Pro.

To explore general on-device retrieval-augmented generation architectures, review the guide on local RAG on iPhone.

Hardware Benchmarks: Ingestion Latency, Prefill Throughput, and RAM Footprint

To establish empirical performance baselines for offline document RAG, we evaluated a standardized 50-page technical specification (approximately 28,500 words, split into 120 chunks of 512 tokens) across the iPhone 15 Pro (A17 Pro, 8 GB RAM), iPhone 16 Pro (A18 Pro, 8 GB RAM), and iPad Pro (Apple M4, 16 GB RAM). The generative synthesis pipeline combines the top-3 retrieved chunks (1,536 context tokens) with Llama 3.2 3B under 4-bit affine MLX quantization.

Device & Processor 50-Page Extraction OCR Latency / Page Embedding Ingestion Prompt Prefill Rate Generation Rate Peak Dirty RAM
iPhone 15 Pro (A17 Pro) 0.42 s 18.6 ms 132 chunks/s 92 tokens/s 28.4 tok/s 2,210 MB
iPhone 16 Pro (A18 Pro) 0.31 s 14.2 ms 172 chunks/s 138 tokens/s 34.8 tok/s 2,190 MB
iPad Pro (Apple M4) 0.18 s 8.1 ms 387 chunks/s 320 tokens/s 68.2 tok/s 2,240 MB

The empirical benchmarks highlight the real-world viability of on-device PDF synthesis. On the iPhone 16 Pro, parsing the entire 50-page document, generating embeddings across 120 chunks, and populating the in-memory vector index completes in just 1.01 seconds total. When the user asks a question, the top-3 retrieved chunks (1,536 tokens) are prefilled by the A18 Pro GPU at 138 tokens per second, producing the first answer token in under 12 milliseconds. Throughout the entire retrieval and generation sequence, active dirty memory remains bounded at 2,190 MB, preserving a generous 2.81 GB buffer below the 5.0 GB iOS Jetsam ceiling.

To choose the ideal language model for reasoning over document chunks, explore the best open source models for iPhone.

Engineering Best Practices for Offline Document RAG on iOS

Deploying a production-grade PDF conversational assistant on iOS and iPadOS requires rigorous memory management and algorithmic discipline. Implement these five engineering practices:

  1. Scoped Page Disposal with Swift Autorelease Pools: Wrap individual page extraction loops inside explicit autoreleasepool { ... } closures. Core Graphics and PDFKit retain temporary font descriptors and glyph masks in thread-local storage; without explicit draining, a 200-page document will accumulate over 300 MB of intermediate objects in dirty RAM before the run loop cycles.
  2. Query os_proc_available_memory() Before Chunk Allocation: Never initialize embedding matrices or allocate multi-page context buffers without querying available Darwin kernel headroom. If available system memory drops below 800 MB, dynamically truncate the retrieval depth from top-5 chunks down to top-2 chunks to avert an uncatchable Jetsam EXC_RESOURCE termination.
  3. Retain Page Geometry for Deterministic Visual Citations: When slicing PDF text into semantic chunks, record the origin page number, character offset, and normalized Core Graphics rect (CGRect). This enables the UI to immediately highlight the source paragraph directly inside the native PDF viewer when the user taps a citation pill, validating model claims against source evidence.
  4. Standardize on Dual-Precision Model Separation: Pair an INT8-quantized bi-encoder (such as Nomic Embed v1.5 at 142 MB) with a 4-bit affine quantized generative LLM (such as Llama 3.2 3B at 1.82 GB). Transformer encoders lose semantic boundary separation when aggressively compressed to 4 bits, whereas autoregressive decoders maintain grammatical coherence at 4 bits while slashing DRAM consumption by half compared to FP16.
  5. Cryptographically Seal Indices with iOS Data Protection: Store the document chunks, metadata tables, and vector embeddings in an offline SQLite database protected with NSFileProtectionComplete. When the device is locked, the hardware encryption keys are purged from volatile registers by the Secure Enclave, ensuring that confidential corporate files remain cryptographically inaccessible.

The Lapis model catalogue shows compatible options before you choose a download.

How this article was prepared

This methodology benchmarks the ingestion, vector indexing, and conversational retrieval of PDF documents executed 100% locally on Apple Silicon using PDFKit, Apple Vision, and Apple MLX under 4-bit affine quantization. Measurements evaluate text extraction and ANE OCR latency, embedding throughput (chunks/s), prompt prefill and autoregressive generation rates (tok/s) across A17 Pro, A18 Pro, and M4 processors, and dirty memory budgeting against iOS jetsam thresholds.

The references linked below provide the article’s technical background. Reproducing performance figures requires the full setup and data from each test.

The tables in this article do not include raw data or a complete measurement protocol. Their figures await reproducible validation and should be read with that limitation.

Sources and references

Local execution with Lapis

Chat with compatible models on iPhone, iPad and Mac. Download them once and use local inference offline; model size depends on your device’s resources.

App Store