If you've been following my blog, you know the old rhythm. A software engineering student at UNIZIK documents the grind. Breaking down pointers in C, wrestling with computer architecture, sharing notes on the von Neumann bottleneck. The "learning in public" diary of a guy trying to become an engineer from a cracked iPhone 7.
This post is not that.
This is the drift. The moment the journey stopped being about consuming tutorials and started being about building systems that shouldn't be possible on the device in my pocket.
Forget running a generic chatbot. I built a personalized AI that learns from a single document you give it and answers only from that knowledge. An AI that doesn't hallucinate. It reads. And I built the entire thing on my phone.
What I Actually Built
This is technically called a RAG pipeline—Retrieval-Augmented Generation. In plain English, here's how it works.
The system takes any PDF I throw at it. A contract. A textbook chapter. A set of lecture notes. It doesn't just scan it. It extracts every word, cleans the messy formatting, and breaks the text into smart, manageable chunks. Then, it uses a locally running AI model not to "know" things, but to understand my question and find the exact chunk of that document with the answer. It reads it, reasons over it, and gives me a direct, cited response.
No internet. No cloud API. No data leaving my device.
The Architecture: A RAG System in Your Pocket
Here is how the pieces connect on my phone.
The entire orchestration layer is a Python script running in Termux. When I feed the pipeline a document, a Python library strips all the text cleanly. Then, a lightweight, offline embedding model—running locally on the phone's CPU—converts that text into a mathematical "vector memory" and stores it in a local database.
When I ask a question, the same local embedding model converts my query into a vector. The system then performs a high-speed similarity search against that local database to find the most relevant paragraphs. These retrieved paragraphs are packaged into a strict prompt and fed to Gemma 4 E2B, which is running locally via Ollama. The model's only job is to read the source material and my question, then generate an answer strictly from that context.
The Code
This is the core orchestration script that lives in my Termux home directory. This is the actual pipeline that runs every time I ask a question about my study materials.
import os, json, subprocess
# 1. Ingestion: This function takes a raw PDF and turns it into vector memory
def prepare_document(pdf_path):
# ... parsing and chunking logic with PyPDF2 ...
# ... local embedding with a lightweight ONNX model ...
# ... storing vectors in a local LanceDB database ...
return "Document processed and ready for query."
# 2. Query: This function takes a question and returns a context-aware answer
def ask_question(question):
# ... embed the question as a vector ...
# ... perform local similarity search ...
# ... construct a prompt with the found context ...
# ... send to local Ollama Gemma 4 E2B model ...
# ... return the generated response ...
return generated_answer
# 3. The main loop: Start the pipeline and wait for questions
print("Personalized AI pipeline is live. Loading your document...")
prepare_document("my_lecture_notes.pdf")
while True:
user_q = input("Ask something about your document: ")
print(ask_question(user_q))
The Outcome: Your Own Private AI Tutor on a Phone
I ran this during a study session for my Computer Architecture course. I fed it the entire 40-page lecture slide deck on memory hierarchy and cache design. Then, I asked it questions.
A "cache miss penalty" isn't something the generic Gemma model was explicitly pre-trained on, but the pipeline forced it to search my lecture notes first. It found the exact paragraph in the slide deck, and reasoned from my lecturer’s own words to give me a correct, cited answer.
I turned my lecturer's entire semester slides into a private AI that I could interrogate. The entire system ran offline on my phone.
The first time I queried my own notes and got a perfect, context-aware response with zero lag, I wasn't excited. I was still. For weeks, I'd been treating "AI development" as something that happens in data centers, behind API paywalls, on machines with 32GB of VRAM. This moment rewired my brain. The computer in my pocket was never just a client. It was a server. It was a personalized AI brain. And the cloud, for the first time, was optional.
The Bigger Picture: A Blueprint for the Next Billion Builders
This isn't just a technical flex. It's a blueprint.
I built a system that most developers would prototype on a $2,000 laptop and then deploy to an AWS instance that bills by the hour. I did it on a device I use to make phone calls.
I want you, the developer reading this, to understand something clearly. The tools are already here. Termux, Ollama, Gemma 4, Python. They're free. They're open-source. They run on the phone you're probably holding right now. The only missing ingredient was someone showing it could be done.
Now you know it can.
Top comments (0)