The RAG Pattern
Retrieval-Augmented Generation (RAG) is the architecture you reach for when an AI feature must answer from a body of knowledge that changes β policy documents, a product catalogue, a help centre, or the lessons you're reading now. Instead of hoping the facts live in the model's frozen weights, you retrieve the relevant passages at query time, ground the prompt in them, and let the model generate an answer from that evidence. The AI Tutor in LyraLearn is a working RAG system, and this module is its blueprint.

Retrieve, ground, generate
Every RAG request runs the same three steps:
- Retrieve β embed the user's question and pull back the handful of passages most likely to contain the answer (vector search plus keyword matching).
- Ground β place those passages into the prompt as labelled reference data and instruct the model to answer only from them.
- Generate β the model writes the answer and cites which passage each claim came from.
When you ask the Tutor a question, that is exactly the path it takes: your question is embedded,
the closest lesson chunks come back from SQL Server, they are graded for relevance, and only then
is the model asked to answer with [Source N] citations. The model never reaches past the
evidence you handed it.
Why RAG beats fine-tuning for changing knowledge
A tempting alternative is fine-tuning β retraining the model on your documents. For knowledge that changes, this is usually the wrong tool:
- Freshness. Edit a lesson and RAG reflects it on the next ingestion run. Fine-tuning means retraining and redeploying the whole model.
- Traceability. RAG can point to the exact passage behind every claim. A fine-tuned model blends your data into its weights, so you can't show your work β a non-starter in public-sector and regulated settings.
- Cost and control. Re-embedding a changed document is cheap and runs on your own hardware. Fine-tuning is expensive, slow, and hard to undo.
- Refusal. RAG can detect that nothing relevant was retrieved and decline to answer. A fine-tuned model has no equivalent signal and will improvise.
Fine-tuning still earns its place for teaching style, format, or tone β how the model should sound, not what facts it should know. The rule of thumb: fine-tune behaviour, retrieve knowledge.
What the rest of the module covers
The three steps each get their own lesson. Ingestion prepares your documents β chunking, embedding, and storing them so retrieval is fast and only changed content is re-processed. Retrieval and evidence grading finds the right chunks and decides whether they're strong enough to answer at all. Citations and evaluation make every answer auditable and let you measure quality over time. Together they are the difference between a demo and a system you can put in front of citizens.