Introduction
What is RAG?
RAG (Retrieval-Augmented Generation) finds relevant snippets from your documents before calling the LLM, then sends those snippets plus the question to the model. Generation is still a language model. Company policy, product FAQs, and yesterday’s API change come from retrieval—not from pretraining.
Without retrieval, the model only has training data and whatever you stuffed into the prompt. A larger context window does not make it cheap to paste an entire knowledge base on every turn, and private facts never appear in public weights.
Why RAG?
When not to force RAG:
- The whole corpus is two or three pages—paste it into the prompt
- You need writing style or task skill, not fact lookup → consider fine-tuning (Hugging Face Fine-tune)
- Millisecond latency and a frozen corpus → a cache or rules engine may win
RAG vs fine-tuning vs long context
You can combine them: RAG for facts, fine-tuning for output shape, long context for this turn’s retrieved chunks. This course only owns the RAG path.
This course: principles, not one framework
The same pipeline shows up as:
Once the principles are solid, switching frameworks is mostly renaming Loader / Retriever classes. Choosing a store (local files, Postgres, a dedicated service) stays the same problem.
Vocabulary
Index (offline) and query (online) must use the same embedding model. Changing models means re-embedding everything. Do not trust English leaderboards for Chinese corpora—measure on your FAQ.
Smallest intuition
No vector database yet—just “nearest neighbor.” Production code should use the ANN indexes in later chapters.
On unit-length vectors, cosine and dot product match. OpenAI and Ollama embeddings are often already normalized—check the vendor docs.
Next steps
- Pipeline — connect the table into one diagram
- Chunking — bad chunks poison everything downstream
- Embeddings — cloud or local; no GPU required