Blog / AI Engineering

Building a RAG System for an Educational Platform

The problem with 'chat, but for school'

A general chatbot answering a CBC question is guessing. It was not trained on your syllabus, it does not know your school's notes, and it cannot tell you which page an answer came from. For Kilele Archade the requirement was the opposite: every AI answer had to be traceable to real curriculum material.

That is the case for Retrieval-Augmented Generation. The model does not answer from memory alone — it answers from retrieved context, and says where it got it.

Ingestion: documents become searchable knowledge

Curriculum PDFs and notes go through a pipeline: text extraction, cleaning, then chunking sized for retrieval rather than for reading. Each chunk is embedded into a vector and stored in PostgreSQL with pgvector, next to the relational rows that describe the subject, level and competence it belongs to.

Storing embeddings in the same database as the documents meant one security model (Supabase row-level security) and one backup story, instead of bolting on a separate vector service.

Retrieval: nearest neighbours are only the start

A raw top-k similarity search returned chunks that were related but not always useful. Two changes mattered most: filtering candidates by curriculum metadata before vector similarity, and re-ranking the retrieved passages before they went into the prompt.

The retrieval step became: filter to the right subject and level, pull nearest chunks with a pgvector index, re-rank, then assemble only the passages that fit the context budget.

Generation: grounded answers with fallback

The prompt template instructs the model to answer only from the supplied context and cite sources. If no provider responds — outage, rate limit — the request falls through to a secondary provider rather than failing in front of a student.

The fallback layer is deliberately boring: the same prompt, a different backend, and a log line so outages are visible instead of mysterious.

What it bought us

Answers students can verify, a tutor that works across at least two AI providers without either being a single point of failure, and a pipeline where improving retrieval is an engineering task (better chunking, better ranking) rather than hoping a bigger model fixes it.