nishchaljs/MobiRAG
À propos
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.
Données et analyseWhat you can do
- 🔐 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.
Progression mesurée des étoiles
- in 24h
- Historique en cours
- in 7 days
- Historique en cours
- in 15 days
- Historique en cours
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
Original📱 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-v2model - 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-v2model - 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
- Open in Android Studio
- Add your embedding ONNX + tokenizer to
assets/all-minilm-l6-v2/ - Place your
.ggufLLM file insideAndroid/data/com.mobirag/files/
📦 Key Dependencies
✅ TODO
Refactor to MVC architecture
Reorganize app code into cleanModel-View-Controllerseparation for maintainability and testingImprove SLM Inference speed
llama.cppuses android cpu - tends to be very slow for long prompts. Need to explore alternatives likemlc llmto utilize GPUs for inference on androidImprove 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 tradeoffImprove system prompt
Design a robust, guardrailed prompt template that guides the SLM to avoid hallucinations and respect query constraintsReuse 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 shutdownLower 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 contextUse the system document picker instead of all-files access
ReplaceMANAGE_EXTERNAL_STORAGEwith the Storage Access Framework, and raisetargetSdkVersionfrom 28 to a current levelBuild
libcommon.afrom the llama.cpp submodule
The prebuilt 46 MB static libraries underjniLibs/could be built by CMake from the pinned submodule instead of being committed
⚡ Credits
📄 License
This project is licensed under the MIT License.
Explorer des projets similaires
Chargement…