Skip to content
المشاريع

حول

Private, offline chat with the PDFs on your Android phone: on-device embeddings, FAISS product-quantized vector search and a local SLM via llama.cpp.

البيانات والتحليلات

كيف تُقاس هذه الأرقام

ما يمكنك فعله

  • 🔐 100% On-Device - No cloud calls. No telemetry. Your data never leaves your phone.
  • 🧠 Embeddings via ONNX - Runs all-MiniLM-L6-v2 model for fast, good-quality sentence embeddings on phone.
  • 📚 PDF Discovery & Parsing - Detects and processes all PDFs on device using PDFBox.
  • 🔎 Semantic Search with FAISS - PQ-compressed embeddings enable scalable vector search on-device.

النمو المقاس للنجوم

خلال 24 ساعة
جارٍ جمع السجل
خلال 7 أيام
جارٍ جمع السجل
خلال 15 يومًا
جارٍ جمع السجل
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

📱 MobiRAG

MobiRAG (Mobile Retrieval-Augmented Generation) is a lightweight, privacy-first Android app that enables users to chat with any PDF file stored on their phone — entirely offline. With on-device embedding generation, vector compression, and SLM inference, MobiRAG brings the power of AI search and summarization directly to your pocket.

No internet, no cloud servers, and no telemetry — everything runs natively on your phone, ensuring complete data privacy and zero leakage. Whether you’re reviewing research papers, legal documents, or ebooks, MobiRAG offers a seamless way to search, ask questions, and summarize content using optimized RAG for mobile devices.


🎥 Demo

🔺️ YT Video


✨ Features

Feature Description
🔐 100% On-Device No cloud calls. No telemetry. Your data never leaves your phone.
🧠 Embeddings via ONNX Runs all-MiniLM-L6-v2 model for fast, good-quality sentence embeddings on phone.
📚 PDF Discovery & Parsing Detects and processes all PDFs on device using PDFBox.
🔎 Semantic Search with FAISS PQ-compressed embeddings enable scalable vector search on-device.
💬 SLM Chat with Context On-device Small LM like Qwen 0.5B generates answers grounded in PDF context.
🔁 Hybrid RAG Combines FAISS vector similarity with TF-IDF keyword overlap.
🖼️ Lightweight UI Responsive and optimized for phones with minimalistic design.

🚀 How it Works

1. PDF Indexing

  • Extracts text from each page using PDFBox
  • Splits text into sentences, then groups them into chunks:
    • PDFs you pick: semantic chunking. A new chunk starts when consecutive sentences' embedding similarity drops below 0.70
    • "Use all PDFs on device": sliding windows of ~1024 characters with a 1-sentence overlap
  • Encodes all chunks using ONNX all-MiniLM-L6-v2 model
  • Compresses embeddings using FAISS Product Quantization (PQ)
  • Stores only metadata (PDF URI, page, character offsets) and the chunk's TF-IDF keywords, not the chunk text itself

2. Query Execution

  • User query is embedded using ONNX all-MiniLM-L6-v2 model
  • FAISS returns the top-5 chunk IDs by PQ-compressed vector similarity (nearest neighbours)
  • Each chunk's TF-IDF keywords are matched against the query's keywords
  • The 2 best semantic matches and the 2 best keyword matches are combined, and their text is re-extracted from the PDFs
  • Combined context is used to prompt a local SLM (Qwen) to generate the answer

This reduces memory footprint and ensures that deleted PDFs cannot be queried later (privacy by design).


🛠️ Technical Highlights

  • ✨ Efficient Compression: FAISS PQ (48 sub-quantizers × 8 bits) stores each 384-dim float vector in 48 bytes instead of 1,536, a 32x reduction. 2.4 MB holds ~50,000 chunks (about 1,000 PDFs at ~50 chunks each). Up to 97x is possible with a quality trade-off.
  • ✨ FAISS Tradeoff: Slight drop in search quality from PQ vs flat index — but acceptable for mobile efficiency.
  • ✨ Metadata-Only Storage: Chunk text is not stored, only chunk ID, PDF location, offsets and keywords. Text is extracted on demand.
  • ✨ Privacy by Design: If a PDF is deleted from storage, its chunks become inaccessible.

🚨 Requirements

  • Android 8.0+
  • ARM64 device (with >=4GB RAM recommended)
  • LLM file: qwen2.5-0.5b-instruct-q4_k_m.gguf

📆 Getting Started

🔧 Setup

git clone https://github.com/nishchaljs/MobiRAG.git
cd MobiRAG
git submodule update --init --recursive

📲 Build Instructions

  1. Open in Android Studio
  2. Add your embedding ONNX + tokenizer to assets/all-minilm-l6-v2/
  3. Place your .gguf LLM file inside Android/data/com.mobirag/files/

📦 Key Dependencies


✅ TODO

  • Refactor to MVC architecture
    Reorganize app code into clean Model-View-Controller separation for maintainability and testing

  • Improve SLM Inference speed
    llama.cpp uses android cpu - tends to be very slow for long prompts. Need to explore alternatives like mlc llm to utilize GPUs for inference on android

  • Improve hybrid RAG scoring
    Replace naive combination of vector similarity + keyword overlap with a unified scoring function (e.g., z-score normalization, weighted distances)

  • Optimize FAISS PQ & SLM inference
    Experiment with different PQ training sizes, nprobe settings, and SLM decoding strategies for best quality-performance tradeoff

  • Improve system prompt
    Design a robust, guardrailed prompt template that guides the SLM to avoid hallucinations and respect query constraints

  • Reuse the llama.cpp context across questions
    Each inference call currently creates a new 30K-token context and sampler without freeing the previous ones. Create them once at model load, clear the KV cache between questions, and free them on shutdown

  • Lower sampling temperature for grounded answers
    Sampling uses temperature 0.9; a lower value (about 0.2) suits answers that must stay close to the retrieved context

  • Use the system document picker instead of all-files access
    Replace MANAGE_EXTERNAL_STORAGE with the Storage Access Framework, and raise targetSdkVersion from 28 to a current level

  • Build libcommon.a from the llama.cpp submodule
    The prebuilt 46 MB static libraries under jniLibs/ could be built by CMake from the pinned submodule instead of being committed


⚡ Credits


📄 License

This project is licensed under the MIT License.

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…