Skip to content

Final Year ProjectOctober 2025 to June 2026

BahasaBot

An AI Malay language learning platform with a retrieval-augmented tutor.

Live demo. The backend sleeps on a free tier, so the first load may take a minute.

Problem

BahasaBot is built for international students at Malaysian public universities. Its primary use case is the mandatory Bahasa Malaysia subject.

Content follows DBP-standardised Malaysian Malay.

System study

The tutor answers through retrieval. A learner's question becomes a 768-dimension embedding, which finds the matching chunks among the 72 Malay corpus chunks in pgvector. The question and those chunks form the prompt for the Google Gemini API, and the reply streams back over Server-Sent Events.

BahasaBot tutor retrieval pipelineA learner question becomes a 768-dimension embedding and retrieves matching chunks from the 72-chunk Malay corpus in pgvector. The question and those chunks form the prompt for the Google Gemini API, and the reply streams back over Server-Sent Events.qQuestionEmbedding768-dimpgvector72 chunksMatching chunksPromptquestion + chunksLLMGemini APIReplySSE
Fig. 1. Retrieval path from learner question to streamed reply.

The store holds each corpus chunk with its gemini-embedding-001 embedding, L2-normalised. The chunks nearest the question's embedding are the ones retrieved.

Semantic field of corpus chunksAn illustrative two-dimensional field of Malay corpus chunks, drawn as points in three loose clusters. A learner question, marked q, sits among them; its three nearest chunks are ringed and joined to it by dashed lines. The coordinates are drawn, not measured.qnearest chunkslearnerquestion
Fig. 2. An illustrative semantic field: a learner question, q, and its three nearest corpus chunks.

What was built

  1. A RAG chatbot tutor built with LangChain over a pgvector store of 72 Malay corpus chunks with 768-dimension embeddings. Replies stream over Server-Sent Events, with session memory and automatic vocabulary and grammar extraction.

  2. A course generator that turns any topic into modules, classes and quizzes through concurrent Gemini calls.

  3. An adaptive quiz engine that personalises questions from tracked weak points and recalculates the learner's level on the BahasaBot Proficiency Scale (BPS-1 to BPS-4) from the last three attempts.

  4. Learning roadmaps of 4 to 18 milestones, and pronunciation playback.

  5. XP, daily streaks, a weekly leaderboard and two word games with Leitner-weighted word selection.

  6. An admin panel with per-user activity tracking, a token-usage dashboard and CSV export.

  7. Security through bcrypt, JWT access and refresh tokens, Google OAuth, Redis rate limiting and Sentry monitoring.

Architecture

Frontend
Next.js 14 with Tailwind CSS, shadcn/ui and Framer Motion, on Vercel. NextAuth v5 handles sign-in with silent token refresh.
Backend
FastAPI on Python 3.12, on Render.
Data
PostgreSQL 15 with pgvector on Neon, in a 23-table schema managed with SQLAlchemy and Alembic. Redis backs rate limiting.
Retrieval
pgvector stores gemini-embedding-001 embeddings at 768 dimensions with L2 normalisation. LangChain retrieves matching corpus chunks for the tutor.
Streaming
Replies stream over Server-Sent Events.
Course generation
Modules generate concurrently through asyncio.gather with Semaphore(2).
Authentication
Dual JWT, with a 15-minute access token and a 7-day refresh token, plus bcrypt and Google OAuth.
pgvector store of corpus chunksA query vector searches the pgvector store, which holds the 72 Malay corpus chunks with their 768-dimension embeddings. The nearest chunks return as matching chunks. The rows and matches drawn are illustrative.query vectorsearchcorpus chunksembeddingspgvectormatching chunks
pgvector store of corpus chunksA query vector searches the pgvector store, which holds the 72 Malay corpus chunks with their 768-dimension embeddings. The nearest chunks return as matching chunks. The rows and matches drawn are illustrative.query vectorsearchcorpus chunksembeddingspgvectormatching chunks
Fig. 3. Retrieval from the pgvector store: a query vector finds the nearest corpus chunks.

Key decisions

  1. Server-Sent Events over WebSocket for streaming replies.

  2. Rule-based proficiency scoring over AI assessment.

  3. Course deduplication by template cloning. A repeat course is cloned from a template, not generated again.

  4. Prompt separation and RAG grounding against dialect drift. Generated courses slipped into Indonesian Malay phrasing because the prompt did not separate the instruction language from the taught language. The fix separated the two and grounded generation on a curated Malaysian Malay corpus.

  5. Token usage logged for every model call, by user and feature.

  6. Built with Claude Code from a phased plan, governed by CLAUDE.md, PHASES.md and STATUS.md.

Evidence

  1. Silver Award, PIXEL 2026, the final-year project showcase of the USM School of Computer Sciences, 20 June 2026.

  2. A repeat course takes about 280 milliseconds and zero tokens, down from about 78 seconds and 21,300 tokens.

  3. Streaming load test with 10 concurrent users: median time to first token 3.6 s, 95th percentile 5.1 s, against a 3.2 s single-user baseline.

  4. 46 documented functional test cases with a defect register and integration testing. All 46 passed after defect correction.

  5. 8 cross-feature integration scenarios. 9 latency endpoints measured, 7 met target. More than 100 test cases executed in total.

  6. Evaluated with 30 users through an in-app rating: average 4.3 out of 5.

  7. Projected running cost of about USD 0.11 per active user per month, from logged token usage.

  8. A solo Agile Scrum delivery over 27 sprints and 76 recorded development sessions.

Screenshots

BahasaBot AI Tutor showing a welcome message, six suggested questions about Malay and the message box.
AI Tutor
BahasaBot Courses page showing the Generate New Course dialog, with its topic field, over the learner's generated courses.
Course generator

Technology

  • Next.js 14
  • FastAPI (Python 3.12)
  • LangChain
  • Google Gemini API
  • PostgreSQL 15 with pgvector on Neon
  • Redis
  • NextAuth v5
  • SQLAlchemy
  • Alembic
  • Tailwind CSS
  • shadcn/ui
  • Framer Motion
  • Sentry
  • Resend

Deployed on Vercel and Render.

Limitations and status

The backend sleeps on a free tier when idle, so the first load of the live demo may take a minute.

The figure of USD 0.11 per active user per month is a projection.