RAG
GenAI Enterprise Accelerator Master Class
LAVANYA.AI
Fine-Tuning
Updating the weights of some or all layers of the pre-trained model to adapt it to the new task
Prompt Engineering
Prompt engineering is temporary learning during inference.
It lets us communicate with an LLM to steer its behavior without updating the model weights
RAG
For tasks that require latest knowledge after the model pretraining time cutoff or access to private knowledge base
LAVANYA.AI
RAG
LAVANYA.AI
RAG
Personalized context to the query.
Overcome the models’ context limitations
Having access to relevant information reduces hallucinations.
RAG Overview
LAVANYA.AI
Components of a RAG System
LAVANYA.AI
LAVANYA.AI
?
embed
embed
1
1
110
1
LAVANYA.AI
Building a RAG Pipeline
LAVANYA.AI
You have a dataset, and you want to build an LLM to do interesting things with it.
LAVANYA.AI
Dataset
Building an
Evaluation Dataset
LAVANYA.AI
13
Comb through the corpus and come up with questions.
Disadvantages
Manually
LAVANYA.AI
14
Use ChatGPT
LAVANYA.AI
15
Advantages
Disadvantages
Use ChatGPT
LAVANYA.AI
16
Lets you systematically generate complex questions and tweak what types of questions you want to optimize for
Use an
LLM Framework
Reasoning
Craft the question so the LLM needs to reason to answer it
Multi-Context
Create questions that need information from multiple sections for the LLM to answer them
Conditioning
Modify the question to introduce a conditional element�
If X, then → Y
LAVANYA.AI
17
Building a RAG Pipeline
LAVANYA.AI
LAVANYA.AI
Load
Dataset
20
21
LAVANYA.AI
Advanced chunking techniques that take the meaning into account
Sentence based
chunking
Advanced chunking techniques that take the meaning into account
Chunking
LAVANYA.AI
23
LAVANYA.AI
LAVANYA.AI
Vector Embedding
LAVANYA.AI
26
Embed your Chunked Documents
LAVANYA.AI
When we get a user question…
LAVANYA.AI
28
LAVANYA.AI
LAVANYA.AI
Vector Embedding
Retrieve Context
30
LAVANYA.AI
31
LAVANYA.AI
Generate Answer
32
LAVANYA.AI
Evaluate Answers
LAVANYA.AI
Evaluation Is Key
34
LAVANYA.AI
35
A
Facts
A
?
LAVANYA.AI
Red Teaming
36
Red Teaming
Goal
LAVANYA.AI
37
LLM As
A Judge
Define Our Own Rubric
LAVANYA.AI
38
LLM as a Judge
LAVANYA.AI
SPADE
39
Automatically write useful evaluation functions for custom LLM chains
Prompt
Assertion
Code
LLM�as a judge
LAVANYA.AI
40
Evaluate
One Answer
LAVANYA.AI
LAVANYA.AI
Evaluate
All Answers
42
Evaluate All Answers
43
Learn from What we got Wrong
LAVANYA.AI
Challenge
LAVANYA.AI
Beat The Leaderboard
Challenge
(30 mins)
45
1. Understand the dataset wandb.me/explore-dataset
2. Get the code wandb.me/class-rag
Beat The Leaderboard
3. Beat the leaderboard
Setup
look for # 🔵 NOTE
Feedback Survey
46
LAVANYA.AI
47
Community
LAVANYA.AI
Thank You
Learn more at lavanya.ai
3 RAG
GenAI Enterprise Accelerator Master Class
RAG
ACCELERATOR.CC
Fine-Tuning
Updating the weights of some or all layers of the pre-trained model to adapt it to the new task
Prompt Engineering
Prompt engineering is temporary learning during inference.
It lets us communicate with an LLM to steer its behavior without updating the model weights
RAG
For tasks that require latest knowledge after the model pretraining time cutoff or access to private knowledge base
ACCELERATOR.CC
RAG
ACCELERATOR.CC
RAG
Personalized context to the query.
Overcome the models’ context limitations
Having access to relevant information reduces hallucinations.
ACCELERATOR.CC
RAG Overview
ACCELERATOR.CC
Components of
a RAG system
ACCELERATOR.CC
?
embed
embed
1
1
110
1
ACCELERATOR.CC
ACCELERATOR.CC
Building a
RAG Pipeline
You have a dataset, and you want to build an LLM to do interesting things with it.
ACCELERATOR.CC
Dataset
Building an
Evaluation Dataset
ACCELERATOR.CC
62
Comb through the corpus and come up with questions.
Disadvantages
Manually
ACCELERATOR.CC
63
ACCELERATOR.CC
Use ChatGPT
64
Advantages
Use ChatGPT
Disadvantages
ACCELERATOR.CC
65
Lets you systematically generate complex questions and tweak what types of questions you want to optimize for
Use an LLM Framework
Reasoning
Craft the question so the LLM needs to reason to answer it
Multi-Context
Create questions that need information from multiple sections for the LLM to answer them
Conditioning
Modify the question to introduce a conditional element�
If X, then → Y
ACCELERATOR.CC
66
ACCELERATOR.CC
Build A RAG Pipeline
ACCELERATOR.CC
Load
Dataset
69
70
ACCELERATOR.CC
Advanced chunking techniques that take the meaning into account
Sentence based chunking
Advanced chunking techniques that take the meaning into account
ACCELERATOR.CC
Chunking
72
ACCELERATOR.CC
ACCELERATOR.CC
Vector Embedding
ACCELERATOR.CC
75
Embed your Chunked Documents
ACCELERATOR.CC
ACCELERATOR.CC
When we get a user question…
77
ACCELERATOR.CC
ACCELERATOR.CC
Vector Embedding
Retrieve Context
79
ACCELERATOR.CC
80
ACCELERATOR.CC
Generate Answer
81
ACCELERATOR.CC
ACCELERATOR.CC
Evaluate Answers
Evaluation Is Key
83
ACCELERATOR.CC
84
A
Facts
A
?
ACCELERATOR.CC
Red Teaming
85
Red Teaming
Goal
ACCELERATOR.CC
86
LLM As
A Judge
Define Our Own Rubric
87
LLM as a Judge
SPADE
88
Automatically write useful evaluation functions for custom LLM chains
Prompt
Assertion
Code
LLM�as a judge
ACCELERATOR.CC
89
Evaluate
One Answer
ACCELERATOR.CC
ACCELERATOR.CC
Evaluate
All Answers
91
Evaluate All Answers
92
Learn from What we got Wrong
93
Beat The Leaderboard
CHALLENGE
Challenge
(30 mins)
94
1. Understand the dataset wandb.me/explore-dataset
2. Get the code wandb.me/class-rag
Beat The Leaderboard
3. Beat the leaderboard
Setup
look for # 🔵 NOTE
Feedback Survey
wandb.me/feedback
95
ACCELERATOR.CC
Community
96
wandb.me/discord
ACCELERATOR.CC
Thank You
lavanya@wandb.com
@lavanyai
Challenge
(30 mins)
98
Beat The Leaderboard
Parameter | Good | Default |
chunksize | 2048 | 10000 |
embedding | text-embedding-3-small | text-embedding-3-small |
chunking strategy | simple | |
temperature | 0.5 | 1.0 |
top_k | 1 | 1000 |
k=2 | 2 | 1 |
prompt | | |
models | | |
| | |
ACCELERATOR.CC
RAG
RAG is a solution for knowledge-intensive tasks where all the available knowledge can’t be input into the model directly.
Its main purpose was to overcome the models’ context limitations.
ACCELERATOR.CC
Will a sufficiently long context will be the end of RAG?
Overcoming context limitations
You can think of RAG as a technique to construct context specific to each query, instead of using the same context for all queries.
Context construction for foundation models is equivalent to feature engineering for classical ML models.
ACCELERATOR.CC
Personalizing Context
LLM
Information Retriever
LLM
LLM
LLM
BM25
Medical Literature
Question2Query
Query
Relevance
Classifier
Relevant
Articles
Summarization
Synthesis
Question
Answer + Citations
110
?
1
1
1
embed
embed
ACCELERATOR.CC
ACCELERATOR.CC
Retrieval Algorithms
Term-based Retrieval
Embedding Based
ACCELERATOR.CC
Compare retrievers
| Term-based retrieval | Semantic retrieval |
Querying speed | Much faster than semantic retrieval | Query embedding generation and vector search can be slow |
Performance | Typically strong performance out-of-the-box, but hard to improve Can retrieve wrong documents due to term ambiguity | Can outperform term-based retrieval with fine tuning Allows using more natural queries, as it focuses on semantics instead of terms |
Cost | Much cheaper than semantic retrieval | Embedding, vector storage, and vector search solutions can be expensive |
ACCELERATOR.CC
Retrieval Optimization
ACCELERATOR.CC
ACCELERATOR.CC
Query by
related content
ACCELERATOR.CC
Evaluation
ACCELERATOR.CC
RAG++
ACCELERATOR.CC
Multi-modal RAG
ACCELERATOR.CC
RAGs with tabular data
Order ID | Timestamp | Product ID | Product | Unit price ($) | Units | Total |
1 | … | 2044 | Meow Mix Seasoning | 10.99 | 1 | 10.99 |
2 | … | 3492 | Purr & Shake | 25 | 2 | 50 |
3 | … | 2045 | Fruity Fedora | 18 | 1 | 18 |
… | … | … | … | … | … | … |
SpaceRAG Demo
Code + Weave
112
ACCELERATOR.CC
ACCELERATOR.CC
RAG From Scratch
ACCELERATOR.CC
Level 1
The Basics
ACCELERATOR.CC
Level 2
More Structured Processing
ACCELERATOR.CC
Level 3
Observability
ACCELERATOR.CC
Level 4
Evaluations
ACCELERATOR.CC
Level 5
Understanding Short Comings
ACCELERATOR.CC
Level 6
Level 7
Level 8
Level 9
Finding Segments and Routing: Techniques for identifying and directing data segments efficiently.
Processing Tables: Strategies for interpreting and manipulating tabular data.
Processing Images: Methods for incorporating image data into RAG applications.
Advanced Data Handling
Building Up Timeline Queries: Crafting queries that span across different timeframes for dynamic data analysis.
Adding Additional Metadata: Leveraging metadata to enrich query context and improve response accuracy.
Query Enhancement
Summarization and Summary Indices: Developing concise summaries from extensive datasets to aid quick insights.
Summarization Techniques
Modeling Business Outcomes: Applying RAG techniques to predict and model business outcomes, facilitating strategic decision-making.
Outcome
Modeling
More Levels
ACCELERATOR.CC
Embedding based Retrieval
ACCELERATOR.CC
Chunking
Sentence based chunking
Advanced chunking techniques that take the meaning into account
Add graphic
ACCELERATOR.CC
Reranking
ACCELERATOR.CC
Query Rewriting
ACCELERATOR.CC
Start with Synthetic Data
ACCELERATOR.CC
Continuous RAG Improvement
ACCELERATOR.CC
ACCELERATOR.CC
Start with Synthetic Data
ACCELERATOR.CC
Focus on Leading Metrics
ACCELERATOR.CC
Fast, Unit Test-Like Evaluations
ACCELERATOR.CC
Real-World Data and Clustering
ACCELERATOR.CC
Continuous Improvement Loop