PythonBeta
ChronoChunk
A Discord bot for my KMUTT classes. It answers course questions from the real class material (lecture recordings, slides, assignments, and files the professors upload) and says where each answer came from.
Result
People use it a lot, mostly to TL;DR a Discord channel in UniCorp (it reads the messages and images too), and also for advice and study guides. Course answers come from about 183 hours of lecture transcripts plus slides and assignments across 9 courses, and each one cites the page, slide, or lecture timestamp it used.
Built with
- Python
- SQLite
- Docker
- Azure
- GitHub Actions
- discord.py
- Azure OpenAI
- sqlite-vec
The problem
Finding the answer to one course question meant scrolling through hours of lecture recordings and slide decks spread across Teams and SharePoint. A general chatbot answers from memory and can make things up. I wanted one place to ask that answers from our own material and cites it, so anyone can check the answer.
What I built
Solo project. I built the sync that pulls class material into a searchable database, the search itself, the step that decides when a question needs course material, study mode, and the deployment on Azure.
How it works
- A sync on my PC pulls lecture transcripts, slides, and assignments from Teams and SharePoint. Transcripts are cut into chunks of about 75 seconds and slides into one chunk per page.
- Search combines meaning-based search (embeddings in sqlite-vec) with keyword search (SQLite FTS5) and merges the two rankings. Adding keyword search is what got the English test set to 9 out of 10.
- Slide pages are also read as images so tables and charts can be found, and Thai slides are translated to English.
- Study mode writes quizzes of up to 100 questions with an answer key, PDF study guides, and system diagrams.
- It also plays music, sums up a channel with /tldr, and can search the web.
Key decisions
- 01
SQLite for everything
Vectors, keyword search, and bot data all live in SQLite, so there is no separate database server to run on a small VM.
- 02
Spending caps
AI calls have daily, monthly, and per-user limits, so one heavy user cannot run up the bill.
- 03
Docker Compose on one small Azure VM
The bot runs on a VM with 1 GiB of RAM. A health check runs every minute and the database is backed up daily, keeping the newest 7.
By the numbers
- About 3 to 5 classmates use it regularly.
- Two courses alone came to 3,944 chunks, embedded for about $0.015.
- Search takes about 51 ms over 50,000 chunks.
- 995 tests, run with ruff and pyright on every push.
The hard part
Handling massive context. A busy channel, hours of lectures, and a pile of slides are way more than the model can take in at once. At first I kept patching problems, like old topics coming back and the bot repeating itself.
What I learned
I should have designed the data handling first, and how the AI would use it. What actually fixed it was putting everything in SQLite, describing each slide once and saving it, and having the bot read only as much of a channel as the question needs.