Skip to main content

1. What is RAG?

RAG (Retrieval-Augmented Generation) is a technique that combines an LLM with an external knowledge source. Instead of depending only on information learned during model training, the LLM retrieves relevant information and uses it to generate an answer.

2. Why RAG is Needed

LLMs can have limitations such as:
  • Outdated knowledge
  • Hallucinations
  • Lack of private or domain-specific information
  • Limited access to external databases
  • Knowledge cutoff limitations
RAG addresses these problems by retrieving information from an external knowledge source.

3. RAG + LLM Architecture

A typical RAG system contains:

4. RAG Pipeline

Step 1: Collect Documents

Documents can come from:
  • PDFs
  • Websites
  • Databases
  • Text files
  • Company documents
  • Documentation
  • Knowledge bases

Step 2: Document Chunking

Large documents are divided into smaller pieces called chunks.
Chunking makes retrieval more efficient.

Step 3: Create Embeddings

Each chunk is converted into a numerical vector.
For example:
Similar meanings should produce vectors that are close together.

5. Vector Database

The embeddings are stored in a vector database. Examples include:
  • FAISS
  • Chroma
  • Pinecone
  • Weaviate
  • Milvus
The vector database allows relevant information to be retrieved efficiently.

6. Retrieval

When a user asks a question, the question is also converted into an embedding.
For example:

7. Augmentation

The retrieved documents are added to the user’s question as context.
Example:

8. Generation

The LLM receives the question and retrieved context.
Example:

9. RAG vs Traditional LLM


10. RAG vs Fine-Tuning

RAG and fine-tuning solve different problems.

RAG

Used when external knowledge needs to be retrieved.

Fine-Tuning

Used to modify model behavior or specialize its responses.
A system can also use both:

11. Types of RAG

Basic RAG

Hybrid RAG

Combines different retrieval methods.

Graph RAG

Uses a knowledge graph to represent relationships between entities.

Multimodal RAG

Retrieves information from multiple data types.

12. RAG and Hallucination

A hallucination occurs when an LLM generates information that is unsupported or incorrect. RAG can help ground an answer using retrieved information.
However, RAG does not automatically eliminate hallucinations. Problems can still occur if:
Therefore, both retrieval and generation need to be evaluated.

13. RAG Evaluation

Important evaluation areas include:

Retrieval

Generation

System

Overall:

14. RAG Applications

RAG is commonly used for:
  • Document question answering
  • Customer support
  • Enterprise search
  • Research assistants
  • Code documentation
  • Legal document search
  • Medical knowledge systems
  • Educational assistants
  • Internal company knowledge bases
Example:

15. RAG With Your Previous FAISS Learning

A simple RAG system can use the same components studied earlier:
For example:

16. Complete RAG Flow


17. Important RAG Components


18. Key Takeaway

The relationship can be remembered as:
The LLM provides the language understanding and generation, while RAG provides access to external knowledge.