0% found this document useful (0 votes)
81 views23 pages

Module 4 - RAG (Retrieval Augmented Generation) - PEC GenAI Course

The PEC Generative AI Training Program focuses on Retrieval-Augmented Generation (RAG), which combines retrieval systems with generative AI models to enhance response accuracy and relevance. The program covers key components of RAG, including retrievers, generators, and feedback loops, alongside various RAG workflows such as Standard, Corrective, Speculative, and Agentic RAG. Additionally, it compares RAG with fine-tuning methods, highlighting their respective strengths and weaknesses in application development.

Uploaded by

regata4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views23 pages

Module 4 - RAG (Retrieval Augmented Generation) - PEC GenAI Course

The PEC Generative AI Training Program focuses on Retrieval-Augmented Generation (RAG), which combines retrieval systems with generative AI models to enhance response accuracy and relevance. The program covers key components of RAG, including retrievers, generators, and feedback loops, alongside various RAG workflows such as Standard, Corrective, Speculative, and Agentic RAG. Additionally, it compares RAG with fine-tuning methods, highlighting their respective strengths and weaknesses in application development.

Uploaded by

regata4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

PEC Generative AI Training

Training Program
Module 4: Training Generative AI Application to Your Needs,
May 05, 2025
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Module 3: Building Generative AI Applications


To Your Needs
➢ What is RAG ?
➢ Why we need RAG
➢ Important Terminologies in RAG (Key Components)
➢ How RAG works ? (WorkFlow in RAG)
➢ Types
➢ Comparison
➢ Fine Tuning (Alternative Of RAG)
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

What is RAG?
➢ RAG stands for Retrieval-Augmented Generation.
➢ It combines retrieval systems with Generative AI
models to produce accurate and relevant
responses.
➢ It is particularly useful for applications that require
up-to-date, fact-based, or domain-specific
responses.​
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Why we need RAG ?


➢ Hallucination (Incorrect Information), when an AI model
generates incorrect or misleading results. This can
happen in any type of AI model, including natural
language processing (NLP) models and computer vision
models.
➢ Data Staleness The model's inability to provide updated
information because it was trained on a fixed dataset that
does not include newer data.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Important Terminologies in RAG (Key Components)


Retriever:
(But there is something which is done before, Let’s See that First)

➢ Searches for relevant information from external knowledge bases or


datasets.

Generator:

➢ Uses the retrieved information to create coherent and accurate responses.

Feedback Loop: (Optional)

➢ Optional mechanism to refine outputs iteratively.


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Preprocessing Before Retrieval


1. Chunking
• What it is:
Breaking large documents or datasets into smaller,
manageable pieces (chunks).
• Why it’s needed:
• Large text blocks are difficult to process efficiently.
• Helps maintain context and relevance in retrieval.
• Example:
• A 10,000-word article might be divided into 500-word chunks.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

2. Tokenization
• What it is:
Splitting text into smaller units called tokens (e.g., words,
phrases, or characters).
• Why it’s needed:
• Allows text to be processed numerically for embedding and search.
• Prepares the text for the embedding model.
• Example:
• "Retrieval-Augmented Generation" →
["Retrieval", "-", "Augmented", "Generation"]
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

3. Embedding
• What it is:
Converting text chunks into dense numerical vectors using pre-
trained models (e.g., Sentence Transformers, OpenAI
Embedding API).
• Why it’s needed:
• Vectors represent semantic meaning, enabling efficient similarity
search.
• These embeddings capture the context of the text.
• Where it's stored:
• Store embeddings in vector databases (e.g., FAISS, Pinecone,
Weaviate, ChromaDB).
• These databases allow quick and efficient similarity searches.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Important Terminologies in RAG (Key Components)


Retriever
● The retriever is responsible for finding the most relevant
information from an external knowledge base, database, or
document store.
● It uses methods like vector similarity search (e.g., FAISS,
ElasticSearch) or traditional keyword matching to locate data
relevant to the input query.
● Why it’s important:
○ Ensures the generative model has access to accurate and
contextually appropriate information to base its response.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Important Terminologies in RAG (Key Components)


Generator
● The generator is a pre-trained language model (e.g., GPT, BERT,
T5 or from Groq) that creates responses by incorporating the
retrieved information.
● It synthesizes retrieved data and transforms it into human-like,
coherent text.
● Why it’s important:
○ Acts as the "voice" of the system, converting raw retrieved
data into usable, conversational, or actionable outputs.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Important Terminologies in RAG (Key Components)

Feedback Loop (Optional)


● A mechanism to iteratively refine the output by re-querying the
retriever or adjusting the generator’s response based on user
feedback or model evaluation.
● Why it’s important:
○ Helps improve the accuracy and relevance of responses over
time.
○ Critical for applications requiring high precision, like healthcare
or legal advisory systems.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

How RAG works


( WorkFlow Diagram )
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Standard RAG
➢ Combines retrieval with generation in a straightforward manner.

Workflow:

1. Input query.
2. Retrieve relevant documents.
3. Generate response using retrieved documents.

Use Case:
● Question answering using enterprise knowledge bases

(Already Seen Above)


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Corrective RAG
➢ Enhances response accuracy by correcting errors in real-time.

Workflow:

1. Generate an initial response.


2. Identify errors using retrieval.
3. Correct errors based on retrieved facts.

Use Case:
● Customer support chatbots with high accuracy requirements.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Corrective RAG
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Speculative RAG
➢ Prioritizes efficiency by speculating which documents are relevant
without full retrieval.
Workflow:

1. Model predicts relevance without actual retrieval.


2. Generates speculative output.

Advantages:
● Faster responses at the cost of potential accuracy.

Use Case:
● Real-time conversational AI with high-speed requirements.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Speculative RAG
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Agentic RAG
➢ Adds decision-making capabilities to the RAG model.

Workflow:

1. Retrieve information.
2. Evaluate context and goals.
3. Generate adaptive and strategic responses.

Use Case:
● Virtual assistants for decision-making tasks.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Agentic RAG
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Comparison

Technique Focus Strengths Weaknesses


Standard RAG Simplicity Easy to implement Limited adaptability

Corrective RAG Accuracy Error correction in real- Slower responses


time

Speculative RAG Efficiency Faster responses Risk of inaccuracies

Agentic RAG Decision-making Strategic outputs Higher complexity


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Fine Tuning VS RAG


Aspect Fine Tuning RAG
Definition Modifies a pre-trained model by Combines a pre-trained model with
training it on new data. external knowledge retrieval

Purpose Customizes the model for a specific Enhances responses dynamically with
task external information.

Data Dependency Requires training on task-specific Uses external data stored in a vector
data. database or index.

Flexibility Requires retraining for updates or Dynamically updates responses without


new data. retraining.

Computational Cost High, due to additional training Low, as it uses pre-trained models with
requirements, High GPU, CPU req. retrieval.

Example Use Case Creating a specialized application for Answering questions about frequently
a specific domain e.g (health care) updated knowledge (e.g., news, chatbot).
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Practical
Demo
RAG
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Trainer: Sajjad Ahmad, Inam ur Rehman


LinkedIn:
https://www.linkedin.com/in/muhammmad-talha/

You might also like