RAG (Retrieval-Augmented Generation)
RAG is an approach where the model receives a 'cheat sheet' from an external knowledge base, found semantically relevant to the query, before responding.
Why is this needed
LLM does not know your internal documents and fresh facts. Fine-tuning is not well-suited for memorizing precise data — RAG solves this problem.
How it works
flowchart LR
A[Documents] --> B[Chunking]
B --> C[Embeddings]
C --> D[Vector DB]
E[Query] --> F[Search]
D --> F
F --> G[Top fragments]
G --> H[LLM]
H --> I[Response]
- Documents are split into chunks.
- Each chunk is converted into embeddings.
- Similar fragments are searched based on the query.
- The model responds based on the found fragments.
RAG vs Fine-Tuning
| RAG | Fine-Tuning | |
|---|---|---|
| New facts | Provides from documents | Poor at memorizing |
| Update | Replace documents | Re-train |
| Model style | Almost unchanged | Changes |
| Deployment | Quick | Requires data |
More details — in RAG vs Fine-Tuning comparison.