← All projects Thesis · AI chatbot

AmBOT

Answers student questions straight from the handbook.

Thesis · AI · RAG · Python · FastAPI · React · 2025–2026

Before

Students had to know which of a dozen documents held a rule before they could find it.

After

A chatbot answers from those documents and names its source.

The Project

EARIST (Eulogio "Amang" Rodriguez Institute of Science and Technology) is a state college in Manila. What a student needs to know, like attendance rules, offenses and sanctions, enrollment steps, office services or who the dean of a college is, is spread across the Student Handbook, the Citizen's Charter, the Registrar and Library manuals, curriculum files and Facebook announcements. Finding one rule means knowing which document it's in.

AmBOT (short for Amang Bot) is a chatbot that answers those questions from the school's own documents. It retrieves the passages that match the question, has a language model write the answer from those passages only, and names the document the answer came from. If nothing relevant is found, it says it can only help with EARIST academic questions instead of guessing.

It was our thesis. Everything runs locally on open models, with no paid AI API: a fine-tuned embedding model, a reranker and Mistral 7B on one GPU.

The backend needs a GPU and isn't hosted right now, so the screens on this page come from the frontend running locally. The answers shown are ones the system generated during our evaluation runs, replayed instead of generated live, and the admin screen uses sample file data.


Key Features

Answers grounded in school documents

The default knowledge base holds 225 chunks, each written around one topic and tagged with its source, category and topic: the Student Handbook 2021, the Citizen's Charter 2025, the Registrar and Library manuals, the curriculum, faculty and officials lists, the academic calendar and other campus information. The prompt limits the model to those passages and tells it to name the source, so an answer reads "According to the EARIST Student Handbook 2021…" rather than a confident guess.

Follow-up questions and Taglish

Students don't ask in clean, standalone English. When there's chat history, the model first rewrites the new message into a standalone English question using the last two turns. For example, "Pano kung Wednesday?" after a question about the uniform policy becomes "What is the uniform policy for Wednesday?" before retrieval runs.

Streaming answers and a mascot that reacts

Answers stream in token by token over server-sent events, so the student sees text within seconds instead of waiting for the full answer. Next to the chat, a 3D fox mascot rendered with React Three Fiber switches animations as the user types, while the bot answers, and when it has to decline a question.

A knowledge base the school can maintain

Admins sign in to an Info Manager. They can upload a PDF with its source, category and topic, which is extracted, cleaned and split into 1,200-token chunks with a 200-token overlap. They can also switch individual knowledge base files off. Restarting the system rebuilds the search indexes from whatever is enabled.


My Contribution

AmBOT was a team thesis. I built the system: every commit in the repository is mine, from the first retrieval notebooks to the final version. The research and the paper were team work, and this page covers the system.

  • The FastAPI backend and the whole RAG pipeline: query rewriting, hybrid FAISS and BM25 retrieval, reranking, the relevance threshold, prompt assembly under a token budget, and token streaming.
  • The retrieval experiments that led there, from the first notebooks through fine-tuned embeddings, a reranker and different chunk sizes.
  • The training data for the embedding model: 8,432 question and passage pairs, prepared in the same "Source; Category; Topic; Content" format the live index uses.
  • The React and TypeScript frontend: the chat, settings, roles, local chat history, the 3D mascot's state handling, and the admin dashboard with PDF upload and knowledge base toggles.
  • The test automation that sent the evaluation questions to the running system and recorded each answer and its latency next to the expected answer, with BLEU, ROUGE-L and METEOR scoring built in.

The Challenge

The Problem

These are questions where a wrong answer has consequences: whether something is a major offense, how many failures lead to dismissal, what an INC grade counts as. A 7B model running on one local GPU will answer anything confidently, and the school's documents are full of terms a general-purpose search model doesn't know well, like OSAS, CCS, INC or a specific office name. If retrieval brings back the wrong passage, the model writes a fluent wrong answer.

The Decision

I made retrieval do most of the work, in layers. I fine-tuned the nomic-embed-text-v1.5 embedding model on 8,432 question and passage pairs from our own documents. Each question searches both FAISS (meaning) and BM25 (exact keywords), and the top 10 from each are merged. A cross-encoder reranker scores every candidate against the question and keeps the best 5. If even the best score is below a set threshold, the request stops there and AmBOT declines before any answer is generated. Only then does Mistral 7B write the answer, at temperature 0.1, from a prompt that forbids outside knowledge.

The Tradeoff

Every question now passes through three models plus a keyword index, which costs time: in our evaluation, answers took roughly 7 to 10 seconds on a local GPU, longer for harder questions. Streaming hides part of that wait, but not all of it. The threshold also means AmBOT sometimes declines a question it could have answered when the wording is far from the documents. For a school assistant, I'd rather it say "I can't help with that" than invent a policy. Writing the knowledge base as topic-sized chunks also took manual work, so admin uploads fall back to automatic token chunking to keep adding documents practical.

The Result

We tested the system with 84 questions at three difficulty levels and four types: direct, paraphrased, scenario-based and adversarial (questions built on a wrong premise, like "I'm on the varsity team, so my grades don't matter as much, right?"). Across 250 runs, each answer was saved with its latency and compared against a ground-truth answer. Off-topic questions are declined instead of answered, and answers name the document they come from.


Technical Details

The backend is a FastAPI service. Mistral-7B-Instruct v0.2 runs as a quantized GGUF model (Q5_K_M) through llama-cpp-python, with every layer offloaded to the GPU and a 6,144-token context. The reranker also runs on the GPU. Once the index exists, the fine-tuned embedding model runs on the CPU to leave GPU memory for the LLM. Simple greetings skip the pipeline entirely.

The /chat/stream endpoint sends one metadata event with the retrieved and reranked chunks, then one event per generated token, then a done event. Before generating, the backend tokenizes the full prompt and drops the least relevant chunk until it fits within the 4,484 tokens left after reserving room for the answer. An earlier version also ran a fine-tuned BART model to condense the retrieved context. The final pipeline passes the reranked chunks straight to Mistral instead.

The frontend is React 19 with TypeScript, Vite and Tailwind CSS, and the mascot is a glTF model rendered with React Three Fiber. Admin accounts and uploaded PDFs live in MongoDB, behind JWT authentication.

Python FastAPI Mistral 7B llama.cpp Sentence Transformers FAISS BM25 PyTorch React TypeScript Tailwind CSS Three.js MongoDB

What I'd change today

I'd show the sources in the chat. The backend already streams the exact passages each answer was built from, but the frontend only logs them to the console for admins. Showing them under the answer would let a student check the rule themselves, which matters more than anything the model says.

I'd measure retrieval on its own. Our evaluation scored the final answers, which mixes retrieval mistakes with generation mistakes. The training data already links every question to its correct passage, so a held-out set of those pairs could report whether the right passage made the top 5, and every change to the embedder, the BM25 merge or the threshold would get a number before anyone reads an answer.

I'd also move reindexing out of the request. Restarting the system deletes the indexes and reloads every model inside one admin request, and the models live in global state. A background job that rebuilds the index and swaps it in when it's ready would keep the bot answering while the knowledge base changes.