AI Models Deep Dive
Hybrid AI
LAFINA uses small, fast AI on the phone for everything that must work offline, and large online AI for open conversation and natural voice. The app always works without the online part.
The Pipeline
On-Device Models Offline
🎙️ Whisper.cpp: Speech-to-Text
| Property | Detail |
|---|---|
| Model | OpenAI Whisper tiny.en, quantized (q5_1) |
| Runtime | whisper.cpp (C++), called through a native Android module |
| Helper | Silero VAD (voice activity detection) detects when the student stops talking |
| Used for | Push-to-talk voice input, reminder call replies, offline Call LAFINA, lecture transcription |
Whisper runs entirely on the phone, so voice commands work without internet. The tiny model keeps transcription fast enough for a live call. The trade-off is lower accuracy in noisy places, so buttons and typing always remain available.
🧠 The Intent Pipeline: Understanding Requests
LAFINA does not send every message to a language model. It uses layers, cheapest first:
- Fast-path parser (rules). Instantly reads clear commands such as “remind me tomorrow at 5 PM”, “wake me up at 6”, or “what’s on my schedule today”. If the reading is confident (≥ 0.85) and clean, it is used as is.
- Optional on-device model. For unclear, Taglish, or casual phrasing, a small GGUF model run by llama.cpp reads the request.
- DeepSeek (online only). With Online Mode on, DeepSeek can also extract planner commands. If it fails, LAFINA keeps the local result.
Every result is validated. Invalid output becomes plain conversation, which never changes data.
Selectable on-device models:
| Model | Size | Recommended RAM | Notes |
|---|---|---|---|
| Fast-Path Only | none | 2 GB | Built-in rules, always available |
| SmolLM2-135M-Instruct | ~105 MB | 3 GB | Smallest model, for 3–4 GB phones |
| Gemma 3 270M | ~253 MB | 4 GB | Better title and phrasing extraction |
| Qwen 2.5 0.5B | ~491 MB | 4 GB | Multilingual, better with Taglish |
| Gemma 3 1B | ~806 MB | 6 GB | Most accurate, needs a strong phone |
🔊 Phone Text-to-Speech
Offline, LAFINA speaks with the phone’s own speech engine through react-native-tts. It is already installed, starts quickly, and uses little memory. The original design used Kokoro-82M, but it was replaced for speed and size.
Online Models Online Mode
All online requests go through the LAFINA backend, so API keys never sit in the app.
DeepSeek: Conversation and Planning Help
Powers LAFINA as a companion: small talk, general and trivia questions, explanations, and study help, streamed word by word. As the Chat agent, it can use tools that run on the phone to look up your planner (up to 4 steps) and prepare one review card. It also writes Ask USTP answers from retrieved sources and generates quizzes, summaries, and documents.
ElevenLabs: Natural Voice
Provides more natural spoken replies and the live voice used in online Call LAFINA. The backend issues a short-lived signed session, and the phone streams microphone audio only during a call the student started, with consent. If it fails, LAFINA falls back to the phone’s voice.
Pinecone: Handbook Retrieval
A vector database that finds relevant USTP Student Handbook passages for online Ask USTP answers. Offline, LAFINA uses its own local knowledge pack with SQLite full-text search instead.
Why This Design?
| Choice | Reason |
|---|---|
| Rules before models | Instant, predictable, and nearly free on battery and memory. Important during a ringing call |
| Optional, selectable on-device model | Students choose based on their phone’s RAM and storage |
| Large online model for conversation | Small on-device models can’t reliably answer trivia or hold open conversation |
| Phone TTS instead of Kokoro | Already installed, faster first audio, lower memory |
| Everything validated, changes confirmed | AI mistakes become corrections on a card, not wrong data |