GENAI1
GENAI1
I
ORAC LE
University
'r.•:• .. ..
'"-. .. ~
fl-•-
•-AJ-'V-.io,c.a.,..-·----,; • Retrieval Augmented Generation (RAG)
is a method for generating text using
additional information fetched from an
external data source.
.. ~
information
or database
Retriever
Function: Sources
from a large
relevant
corpus
Ranker
Function: Evaluates and prioritizes
the information retrieved by the
retriever
+ Generator
Function: Generates human-like text based
on the retrieved and ranked information,
along with the user's original query it receives
Workinc: Uses retrieval techniques Working: Uses various algorithms to Working: Uses generative models to cratt
evaluate the quality of the retrieved ~ human-like text that is contextually relevant,
Purpose: Provides the generation content coher,nt, and informative
system with contextually relevant,
accurate, and up-to-date Purpose: Ensures that the Purpose: Ensures that the final response is
information that might not be generation system receives the most factually accurate. relevant, and also
present in the model's pre-trained pertinent and high-quality input coherent, fluent, and styled typically like
knowledge human language
RAG Techniques
--
C,
•I
For each input query (like a chapter topic), the model retrieves a set of
I
I
relevant documents or information.
I
I
I
I
I
•
I
It then considers all these documents together to generate a single, cohesive
RAG Sequence response (the entire chapter) that reflects the combined information.
•'
•
I
I
For each part of the response (like each sentence or even each word),
the model retrieves relevant documents.
I
I
I
I
I
•
I
The response is constructed incrementally, with each part reflecting
RAG Token the information from the documents retrieved for that specific part.
RAG Pipeline
-
RAG Application
-
· what are my
-What~ tM policy?" corporate benefits?"
+
Chat History
1 r
T
Private content ""'
1
HIGHLY
Similarity Search ~~ ,;
ACCCRATE
RESPONSE
Relational Database
- ·- .
RAG Evaluation
-
Groundedness
RESPONSE Is the response supported
by the context?
CONTEXT
Vector Databases
-
OCI Generative Al
Himanshu Raj
SENIOR INSTRUCTOR Al/ML
ORACLE UNIVERSITY
LLM Versus LLM + RAG
- f ~tMI
0
II
LLMs withou t RAG rely on
interna l knowledge learned
• ···-•••in ino 0 rino tunin9 4Jf.~ 4
QMry
C ,
a
~,,l
I
I R4t•pon••
I during pre-tra ining on a large Gigantic dataset Base LLM Flnetune d LLM User
1QJ ~
is a Vector Database.
0
Query
• Jte•pon••
Pro-trai nino
1'•apen••
..
Gigantic dataset '-
web, wiki, books, etc.
Query•
relevant docs
l User
Vector DB
Vector
-
Vector
':) A vector is a sequence of numbers,
DATA I
I
I ca11ed dimensions, used to capture
I
~
I
I
I
I
the important "features" of the data.
I
I
•
I
I
• •
I
I
I
I
high-dimensional vectors.
I
I
I
:/ ~II]
I
I
•
I
Vector
- •
I
There are three groups of words
! here based on similarity:
!
I
animals, fruit, places.
I
I
elephant
e
I
I
•
A.B = ,n
Lt=1
Ai Bi
40
20
Cosine Distance
-20
A.B
l - llAII llBII -40
0
-40 -30 -20 -10 0 10 20 lO
t-SNl!FHturitl
oracle.com - To exit full screen, press ~
Similar Vectors
Data vectors
.-.-------~---------..- 4------~--- Ou t ., , t( ~
--------------------·--
-----~-·--------·
------
........
___ ..__..,_..,.. ___ _,...-.-----
....._----·---·-·-----
___________ -.-----
---
_____.........-_
==-...:.=:-::~........
~------·- ~
:r.=-~·-T.::..--=:.--
------.--------
_
._..
---------._,....,.._.,_,.
...,,_.,.._.,. __
........_,_ _____ ~-----
...,..................... --..-...-..-
...,._ _____
::~:;-~•
_,.._
... ____
-:. _3::
..,_,------·-·----
_ .............. ....-
_..__
- --------·-•-
:a!'---=-.----===-"!:
·-
c:=-~----=-=-~-=
.................... ....... Oc,,• So..rco
------·
---··-··--·--
---·-··---
-·----·-- -=--=-~....
............................--.__., :.::t=..--. - .
--.-----~
:--=.;;.~_:;::.· -
·------·- .. __
--~...............- --------
---_____
.. ____
~ , . . . . . . . . . . . . . . . . . &-Mia_
:-.c:-.:.::.=::::-:-..=-.:
........... 0 K-Nearest Neighbors algorithm can be used to perform
...- ~------.~ ..., g spoilty/ annoy ,_....
<>0.0 0 - ..
n ,.._ • 0 - -=:.:-=------
_""""
le _...;._______,____
._
i
I
I
a vector or semantic search to obtain nearest vectors
I
I in embedding space to a query vector.
I
I
'
·--p,A- I)
I
I
I
ANN algorithms are designed to find near-optimal
neighbors much faster than exact KNN searches.
·-
I
I
•
!
·-
·-
ANN metho~s such as HNSW, FAISS, Annoy are often
preferred for large-scale similarity search tasks in
embedding spaces due to their efficiency.
Vector Database Workflow
-
Vectors ----.-
• Indexing Vector
Database
- -~--1 Querying .. Post
Processing
Vec tor Databases
-
ORA CLE
A~Vector Search
• Chroma w Weaviate
Vector Databases
-
Accuracy
(!J Pinecone
ORACLE Latency
Al Vector Search
B et te r bu si ne ss outcom
es
- -
LLM
-- - ~-
+ Ve ct or Database
ORACL E
University
Himanshu Raj
SENIOR INSTRUCTOR Al/ML
ORACLE UNIVERSITY
Keyword Search G oogle
> Keywords are words used to match with
~--__.,.
'l - •1
0. , . . _ .. _ _ . . .
a. _ _ .. .._..
X G!
0. -
0. - - l- · -
the terms people are searching for, l)N e
0. -
0. _·_-
......
-
ORA CLE
University
Semantic Search
-
OCI Genera tive Al
Himanshu Raj
SENIOR INSTRUCTOR Al/ML
ORACLE UNIVERSITY
Semantic Search
-
Search by meaning
Google
> Retrieval is done by understanding
0. Wh1I It Se~
intent and context, rather than
matching keywords. ¥met It ~nUCI • I.. man{l)ill,/
o_ lhe brand! ol lt'flNICa and logic c,onc.emed ...at lftNlllnt. ni.rt . . a 111,mber
of lnnc:hM and ....,.IC:Ne ol ..-...nllc:e. ~ b,1111 eemanb, whkil
1111dlet the loglc.al ~ of fflMNIIO, audl u NIIM, ,.._,.,_, lmplcallan, •
Dog
•I
I
I
I
I
I
Embeddings represent the meaning of
text as a list of numbers.
I
6 • I
I
I
I
• Capture the essence of the data in a lower-
5 dimensional space while maintaining the
semantic relationships and meaning.
-~·~ =-
4 '
Car •
3 • Words
[-17.216797, -14.016798]
2
Rose
•
Fruit
• •
[0.015594482, -
rose 0.0038833618, -0.0635376,
1 -0.07...
6
Oracle offers a free [0.02619934, -0.028915405.
0 1 2 3 4 5
0 pricing tier for most -0.015777588, -0.07...
Al services.
Embeddings in two dimensions b...-..-
Dense Retrieval
-
7
6 ~
•
(Doc6J
5
[Doc9l
~
•
•
• Relies on embeddings of both queries
and documents to identify and rank
• re1evant documents for a given query
4
3
[QodJ [Dcd]
• • Enables the retrieva1 system to
understand and match based on the
contextua1 simi1arlties between queries
• ---------- Query
~
•
2 and documents
1
~
•
-~
•
0
0 1 2 3 4 5 6
*Relevant Docs
Rerank
-
Query text Initia l Searc h Resu lts Relev ance Scor e New Rank ing
~2
Rerank
>