AI RAG architecture
This course treats Retrieval-Augmented Generation as an architecture, built in Rails on top of Postgres. It begins with why retrieval suits facts better than fine-tuning, and why a RAG system is two pipelines: indexing and querying. Lessons cover chunking with contextual prefixes and metadata, embedding models and their dimensions, quantization and lock-in, and vector storage with pgvector and ANN indexes. Later lessons add hybrid retrieval with Reciprocal Rank Fusion, cross-encoder reranking, prompt assembly with citations and caching, and a full pipeline with its failure modes and evaluation.
What you'll learn
- ✓Why retrieval supplies facts while fine-tuning teaches behavior
- ✓Chunking by document structure, with contextual prefixes and metadata
- ✓Embedding dimensions, quantization, input types and model lock-in
- ✓Storing and searching vectors in Postgres with pgvector and HNSW
- ✓Hybrid retrieval with Reciprocal Rank Fusion and cross-encoder reranking
- ✓Prompt assembly with citations, caching and evaluation of the pipeline
Why retrieval beats fine-tuning
A support engineer asks your app: "does the Pro plan include audit logs?" The model answers, confidently, that it does. It doesn't. Nobody wrote that sentence anywhere. The model produced a plausible continuation of the question, and plausible is all it was ever optimizing for.
Read the full lesson free →Curriculum
7 lessonsWhy retrieval beats fine-tuning
Compares fine-tuning with retrieval and splits a RAG system into separate index-time and query-time pipelines.
Chunking: what a chunk must carry
Covers chunk sizing, structural splitting, contextual prefixes, and the source and tenant metadata each chunk must store.
Embeddings as an architectural choice
Explains cosine similarity, dimensions, quantization and input types, and why storing the model name prevents lock-in outages.
Storing and retrieving vectors in Postgres
Stores vectors in Postgres with pgvector and the neighbor gem, using filtered queries and HNSW or IVFFlat indexes.
Hybrid retrieval and reranking
Combines lexical and vector search with Reciprocal Rank Fusion, then applies cross-encoder reranking to a small candidate set.
Generation: assembling a prompt
Builds a prompt that separates instructions from retrieved text, requires citations, allows a no-answer path and uses caching.
Putting it together: a RAG pipeline in Rails
Assembles the pipeline as Rails objects and a job, lists silent production failures and measures retrieval and groundedness.