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

Student speaks
Whisper.cpp + Silero VAD Speech to text, on the phone
Intent pipeline Rules first, then an on-device model, then DeepSeek if online
Planner change → review card Saved only after Confirm
Conversation → reply DeepSeek online / local reply offline
Reply spoken Phone TTS offline, ElevenLabs online

On-Device Models Offline

🎙️ Whisper.cpp: Speech-to-Text

PropertyDetail
ModelOpenAI Whisper tiny.en, quantized (q5_1)
Runtimewhisper.cpp (C++), called through a native Android module
HelperSilero VAD (voice activity detection) detects when the student stops talking
Used forPush-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:

  1. 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.
  2. Optional on-device model. For unclear, Taglish, or casual phrasing, a small GGUF model run by llama.cpp reads the request.
  3. 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:

ModelSizeRecommended RAMNotes
Fast-Path Onlynone2 GBBuilt-in rules, always available
SmolLM2-135M-Instruct~105 MB3 GBSmallest model, for 3–4 GB phones
Gemma 3 270M~253 MB4 GBBetter title and phrasing extraction
Qwen 2.5 0.5B~491 MB4 GBMultilingual, better with Taglish
Gemma 3 1B~806 MB6 GBMost 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?

ChoiceReason
Rules before modelsInstant, predictable, and nearly free on battery and memory. Important during a ringing call
Optional, selectable on-device modelStudents choose based on their phone’s RAM and storage
Large online model for conversationSmall on-device models can’t reliably answer trivia or hold open conversation
Phone TTS instead of KokoroAlready installed, faster first audio, lower memory
Everything validated, changes confirmedAI mistakes become corrections on a card, not wrong data