AidAILine / ARCHITECTURE.md
J-Barrert's picture
Upload 14 files
585cfd5 verified
|
Raw
History Blame Contribute Delete
5.93 kB

A newer version of the Gradio SDK is available: 6.20.0

Upgrade

Personal Document Intel & Archiver β€” Architecture Plan

Overview

Local-first PDF RAG tool for caregivers. Upload medical documents, ask questions, get answers. Runs entirely offline.

Track & Badges

  • Track: Backyard AI
  • Badge targets: Off the Grid (no cloud), Llama Champion (llama.cpp), Off-Brand (custom UI), Field Notes (blog post)

Tech Stack

Component Choice Why
Runtime llama.cpp (llama-cpp-python) Off the Grid + Llama Champion badges
Model Qwen 2.5 14B GGUF (Q4_K_M) ≀32B, strong on document reasoning, ~8GB RAM
Embeddings all-MiniLM-L6-v2 via sentence-transformers Small, fast, no cloud, runs locally
Vector store FAISS (in-memory, persisted to disk) Lightweight, no server needed
PDF parser PyMuPDF (fitz) Pure Python, fast, no cloud deps
Text splitter LangChain's RecursiveCharacterTextSplitter Clean chunking with overlap
UI Gradio (custom theme) Required by hackathon rules
Frontend polish Custom CSS + gr.ChatInterface Off-Brand badge

File Structure

personal-doc-archiver/
β”œβ”€β”€ app.py                  # Gradio entry point
β”œβ”€β”€ rag_engine.py           # RAG pipeline (embed β†’ retrieve β†’ generate)
β”œβ”€β”€ pdf_loader.py           # PDF parsing + text chunking
β”œβ”€β”€ config.py               # Paths, model name, chunk settings
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ models/
β”‚   └── (download target for Qwen GGUF)
β”œβ”€β”€ data/
β”‚   └── documents/          # Uploaded PDFs go here
β”œβ”€β”€ cache/
β”‚   β”œβ”€β”€ index.faiss         # Persisted FAISS index
β”‚   └── chunks.json         # Chunk metadata
β”œβ”€β”€ assets/
β”‚   └── (custom CSS / branding)
└── README.md               # Submission notes

Data Flow

User uploads PDF
    ↓
pdf_loader.py extracts text (PyMuPDF)
    ↓
Text splitter chunks with overlap (500 chars, 50 overlap)
    ↓
sentence-transformers embeds each chunk
    ↓
FAISS stores embeddings in index
    ↓
User asks question
    ↓
Question embedded with same model
    ↓
FAISS searches top-3 chunks
    ↓
Context + question β†’ llama.cpp model β†’ answer
    ↓
Answer displayed in Gradio chat

Chunk Strategy

  • Size: 500 characters
  • Overlap: 50 characters
  • Why: Medical documents have dense info; small chunks keep retrieval precise

Model Settings (llama.cpp)

  • Context: 4096 tokens (enough for Qwen 14B with chunked context)
  • Temperature: 0.1 (low β€” we want factual, not creative)
  • GPU layers: depends on VRAM. RTX 5070 = all layers GPU. Fallback: CPU-only.
  • Prompt format: Qwen 2.5 chat template

System Prompt (for the model)

You are a medical document assistant. You help caregivers find information in uploaded medical documents.
Answer using ONLY the provided context. If the answer isn't in the context, say "I couldn't find that in your documents."
Be concise and specific β€” cite dates, names, and numbers when available.

UI Layout (Gradio)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ₯ Personal Document Intel & Archiver    β”‚
β”‚  ─────────────────────────────────────── β”‚
β”‚  [⚠️ System: Offline β€” No data leaves    β”‚
β”‚   this computer]                         β”‚
β”‚                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ πŸ“       β”‚  β”‚                      β”‚  β”‚
β”‚  β”‚ Upload   β”‚  β”‚   Chat Interface     β”‚  β”‚
β”‚  β”‚ Documentsβ”‚  β”‚                      β”‚  β”‚
β”‚  β”‚          β”‚  β”‚  "What did Dr. Chen  β”‚  β”‚
β”‚  β”‚ [Doc 1]  β”‚  β”‚   say about my       β”‚  β”‚
β”‚  β”‚ [Doc 2]  β”‚  β”‚   blood work?"       β”‚  β”‚
β”‚  β”‚          β”‚  β”‚                      β”‚  β”‚
β”‚  β”‚ Status:  β”‚  β”‚  "Your March labs   β”‚  β”‚
β”‚  β”‚ βœ… 2 docsβ”‚  β”‚   showed elevated    β”‚  β”‚
β”‚  β”‚ loaded   β”‚  β”‚   cholesterol..."    β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                          β”‚
β”‚  Examples: [What did Dr. Chen say...]    β”‚
β”‚  [When is the next cardiology appt?]     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Development Phases

Phase 1 β€” Core (today/tomorrow)

  • Set up Gradio skeleton with custom theme
  • Build PDF parser + chunker
  • Wire up sentence-transformers + FAISS
  • Integrate llama.cpp with Qwen 14B
  • End-to-end: upload PDF β†’ ask question β†’ get answer

Phase 2 β€” Polish (middle week)

  • Off-Brand UI polish (custom CSS, icons, status indicators)
  • Document management (list, delete, re-index)
  • Better error handling (bad PDFs, no model, empty context)
  • Performance: multi-document search, file type detection

Phase 3 β€” Ship (last 2 days)

  • Full test cycle on target hardware (mom's laptop / user's PC)
  • Demo video recording
  • Social media post
  • Field Notes blog post in Obsidian
  • Submit to build-small-hackathon org on HF Spaces
    • Note: Gradio app goes on HF Spaces for submission
    • Model itself stays local (badge requirement)
    • Space will use a placeholder model or OpenRouter for the demo
    • The "real" offline version is what runs on local machine

Questions for Mom

(To be filled once she sends them β€” placeholder structure)

  • Category: Appointments
  • Category: Medications
  • Category: Lab Results
  • Category: Insurance / Billing
  • Category: Doctor Instructions