AI Engineering
Understanding RAG Architecture from First Principles
Separate indexing, retrieval, and generation. Make each boundary observable and testable.
Why retrieval exists
A language model does not automatically know your private or recently updated documents. Retrieval-augmented generation supplies selected context at request time. It changes the inputs, not the model's trained weights.
The indexing path
- Load and validate approved documents.
- Split text into coherent chunks and retain source identifiers.
- Generate embeddings with a versioned model.
- Store vectors with access rules, timestamps, and source metadata.
The query path
Authorize the visitor first. Embed the question, retrieve only eligible chunks, optionally rerank, and fit the selected context into a bounded prompt. Keep citation identifiers intact.
The generation boundary
Instruct the model to answer from the supplied sources and say when the context is insufficient. Treat retrieved text as untrusted data, not as commands. A prompt is not an authorization boundary: filter access before retrieval.
Evaluate two systems, not one
Retrieval tests check whether the right sources are present. Answer tests check faithfulness, completeness, and valid citations. A fluent answer cannot fix missing evidence.
Exercise
Draw a diagram with separate indexing and query paths. Mark where a tenant identifier is checked, where model versions are stored, and what happens when no authorized evidence is found.