This content is a workshop session focused on building AI agents using Large Language Models (LLMs) and the LangChain framework, demonstrating practical applications and the underlying concepts.
Mind Map
Click to expand
Click to explore the full interactive mind map • Zoom, pan, and navigate
So we're going to start briefly. So
So
while we starting we like to launch
a survey
to understand your background for future references.
So please uh answer uh the survey while
So uh my name is uh Murat. I'm Stanford
scientist and Magnamine co-founder
and I worked on uh data science and AI.
Uh I've been working on data science at Stanford.
Stanford.
I also teach in Santa Clara University
um machine learning AI classes.
So uh we've been uh as a magnuman
academy we've been holding our meetup
groups for last five plus years is past
300 events. If you're not member of any
of our meetup groups please welcome to join
join
and then we have a YouTube channel where
we have our recordings from previous events.
events.
We put our most
meetup or events in YouTube channel except
except
um some of those register workshops. So
you have to be register our workshops to
attend it. But most our events there is
very diverse reach content and we share
all other our social media platforms we
provide different contents in each of them.
them.
So there are a few announcements we're
going to have. Um
first uh we're going to have a six weeks
uh LLM mini boot camp. This is a rare
event that we uh spec we specifically
designed for the industry's demands.
And as you filling the survey, uh we
understand from people that most people
look for job market or most job market
openings they require LLM background
and we are going to build AI agents and
you're going to learn the deep
understanding of LLM with Dr. Geran
which I will introduce him and seami
haj he's a engineer
in C3 AI and he's expert in LLMs and he
build LLMs for different big corporates
and also myself uh I will also teach the
LLM aspect how to build products in LLM
or what kind of products you guys can
build with LLM.
So uh that would be good in a intense
six weeks program in LLMs. If you don't
want to miss your spot and get all early
early bird uh it's finishing in 3 days.
While you're registering you have to
finish and complete the purchase
otherwise you won't have a spot and
after 3 days price goes up. That's a
unique and rare opportunity. We don't
know if we're going to offer that again.
So, but we have a regular our mentorship
data science internship programs 15
weeks where uh we assign mentors to students
students
uh four to five mentors working on so so
many projects. Plus we have a company
affiliations we provide where students
work with companies from industry
and then they get this experience but
most recruit recruiters ask on demand
and if you have any questions you can
let us know and then we're going to give
more information on that later. So I
will introduce Dr. Geran
and uh he is
co-founder Magnumine Academy
and he's been u his faculty in San Jose
State University. Prior to that he was
faculty in Kais University in Korea and
Santa Clara University
and he's also working on AI medicine
projects with Stanford University School
of Medicine
and um he's been uh in data science and
computational field in close to 20
years. He's a great person to learn data
science in general specifically LLMs and
AI agents.
So I will let Dr. Jaran start when he's
All right. Thank you. Thank you for the
introduction Dr. Mrat. So hello
everyone. Welcome to another Magnind
workshop session. This time uh we are
going to work together on
creating a simple uh AI agents step by
step. So, we're going to work on four
different uh small uh projects. Uh and
then uh I'm hoping that you guys are
going to work with me together. Uh we're
going to write the code together. You
don't need anything uh except uh opening
your Google Collab. That's it. So, you
don't need anything else. We are going
to build everything from scratch
together. I'll also give you the API for
um for the LLM that we're going to use
today. So all you have to do is just uh
uh type the code with me together and
then see what's going to happen. So
before we start uh uh I would like to
share this tweet with you. So let me see
if I can find it. Uh first let me share
Yeah, I'll share my screen first. Okay.
So this is uh from one of my favorite
machine learning uh book authors
Sebastian Rajka. So the day before
yesterday I just saw his uh tweet. I
really liked what he was saying. So uh
job roles in 2027 2026 I would say from
2025 to 2027.
So data scientist uh is going to turn
into analytics strategist. Before a data
scientist was expected to do cleaning
data sets, structuring queries. uh now
it's going to be about framing questions
and then interpreting outcomes. So
that's that's mostly what I'm interested
in. But if you guys are falling into any
other category like programmer, so
before writing code by line by line
after designing logic and structuring
systems, I really liked the way he put
uh u the change in the job market into
perspective. So that's the first thing I
would I wanted to share with you. Second
thing before we get started, I I wanted
to share with you is a small side
project I'm working on. So this is uh is
very small AI agent running locally
right now on my computer and then I try
to see what kind of tasks uh for jobs
are going to be replaced augmented by
AI. So I would like to just uh look at
data scientist and then data scientists
are related to so many different uh
jobs. So I wanted to select data
scientist. So this is running locally. I
haven't uh what is that uh I didn't
share this with publicly yet. So right
now the an LLM running locally is
analyzing all the tasks related to this
job and then again depending on how I
define different attributes of u
jobs that are going to be replaced or
augmented AI. So this is not directly
coming from LLM but I also gave a lot of
input expert input into LLM to to to
give me feedback on which tasks are
going to be replaced or augmented. So uh
I I I actually did this for many
different jobs. What I see is in the
next again this is not it is not
perfect. I'm not saying this is all 100%
correct but more or less I'm working
with another field expert on this. more
or less most of the tasks we're going to
see for different jobs are either going
to be augmented I'm not saying totally
replaced that's that's I think too
unrealistic but it's going to be
augmented uh by AI in other words we are
going to be competing with our peers who
know more AI so they're going to be the
ones that are going to be stronger in
the near future okay so that is another
thing I wanted to share with you before
we get started now let's let's get
started with our session uh please uh
open your uh browser and then if you
could just uh this is what we're going
to do today. Okay, this is what we're
going to do today. If you could please
open uh a new notebook in your Google
Collab. Okay, so you I'm going to use
Google Collab. Normally uh I did all
this work on my uh local VS code which
is looking much more organized and
professional and it's much easier for me
to push my code. uh but uh for this
session for the workshop I found uh
working on Google Collab will be easier
for all of us uh because we need to uh
install certain uh libraries and then
it's going to be easier if we all work
on Google Collab. So if you guys are
ready, we can start. If you need more
time, please type your questions,
comments, anything regarding this
session to Q&A. Let me know if you need
more time. But if you are ready, I'm
going to start. So just open a new
Google Collab Jupyter notebook. That's
Uh you don't need to title it now. Uh
yeah, it's a blank screen. Just a blank
uh notebook. That's all. That's all you
have to open. You don't see anything on
on on you don't see my screen. Can you
not see my screen?
Says blank screen. Can you can you
screen maybe he has to click on his own
uh computer? Yeah. Oh, okay. So, but you
Okay. Uh yes, everyone see. Yeah. All
right. Okay. Thank you. Can see. Okay. I
can see the screen. All right. Thank
you. All right. So uh the first thing
I'm going to do is I'm going to install
some uh uh libraries. So this will take
uh maybe uh what is it uh uh couple of
uh maybe 30 35 seconds uh depending on
on the speed. Okay. So here is what
we're going to do. We are going to use
pip install.
Uh okay. So lang chain. So today we are
going to use lang chain Google
genai. Okay. So that is first library we
are going to use and then lang chain
community. That's the second one we are
going to use. All right. And then we
going to use uh
a a vector-based
uh database face CPU from Facebook.
Okay, that's the next one. and sentence transformers.
transformers.
That's what we need for one of the uh
small applications we are going to
develop. So please type this. These are
1 2 3 four libraries that we are going
to use. So I'm going to run this cell.
Please run this cell too. So it's going
to install these cells for this session
to your Google Collab. So next time you
come when you run this, you're going to
you have to do the exact same thing. So
it's only going to be installed for this
session. Okay. So I'm running this. So
it'll take a while. So maybe 30 35 seconds.
So you're going to see a lot of uh uh
uh
lines of
like requirements are set. So you're
going to see all these things. So don't
worry. So it's just uh installing the uh
Yeah. So, my sessions was were already
running. So, it's uninstalling and
installing again. So, in your case, this
See,
scroll up, please. Sure. Sure.
These are the I'm going to I'm going to
after I write every piece of code, I'm
going to copy and then share it with
you. So that Okay, I'm going to share it
So please just use Google collect. Okay.
If there are any uh
mismatchings uh if the uh distribution
found for sentence it's it's not found.
So I I have no idea about that error. So
Asia, so I'm sorry I cannot fix it now.
So I cannot I don't have any any any
suggestions how to fix it now. U but uh
on my end this is what I'm going to use.
Maybe maybe you can just follow the rest
of the session and then try to do it
later uh by by watching the recording.
Okay. So I think we are done. So it is
done. So I'm just going to comment this
out. Uh and then I'm ready to start
typing my code for Yeah, it was a type.
Okay. So I'm I'm going to start typing
my code for uh for for this session now.
Okay. Now the first thing is I'm going
to uh uh import Google generative AI.
Okay. From lang chain Google
Google
geni. We are going to use Google's
Gemini uh LLM today. Okay. So I'm going
to because I already installed lang
chain Google geni. So from Google lang
chain Google geni I'm going to import Google
Google generative
generative
AI. Okay. So that's that's that's what
I'm going to import now. So
I'm done with this line. So now I have
Google generative AI imported. All right.
right.
Okay. So, I'm just taking it slow now,
trying to see if everybody is settled
and then ready following me because now
I'm going to give you the API for this
session. This API will only be valid
during this next maybe 1 hour or or or
75 minutes then it's going to be deleted
and it has a cap. So, please uh just use
it during this session for this session.
Yeah, I will post the uh yeah, that's
that's what I'm going to do. So, I'm
going to post everything I write here so
that you don't have to type it if it is
taking too much time. All right? Or or
if you guys have any if you have any any
mistypos. Yeah, this is recorded. The
recording will be shared. Uh but if you
are already here, stay with me, okay?
Let's do it together. Okay. So, now I'm
going to share the API with you guys. So
for that what I'm going to do is I'm
going to write I'm going to say Google G
Google here Google Google
API key. So this is very important. This
one is very important. So with this API
key we are going to get connected to a
large language model. In this case it's
going to be Gemini uh 2.5 flash. So
Gemini has multiple products. We're
going to use uh we're not going to use
the pro version. It's it's it was a
little bit expensive and then we don't
need that now. I thought of running a
free local uh LLM but for this workshop
I think the first workshop I think it's
better if we use a paid uh u LLM so not
running anything locally because we need
to set it up for for for local
connection. I didn't want to spend time
on it. Okay. So what I'm going to do is
I'm going to say input.
So I'm just asking uh I'm just making
this uh more interactive. Okay,
otherwise I can just API
key. So this API key is going to be
stored as a string. Okay, so I'm going
to run this and then it is expecting
from me my Google API key. I'm gonna get
my Google API key uh here and
and
this one. I think I copied this.
Okay. Now I'm going to share this API
key. Let me first enter it here.
Okay. And then I will share it with you.
So you don't need to use any other API
key. You can just use this one for this
session. Again, it's not going to be
valid after this session.
All right, please let me know if you
guys got the API key.
Can we discuss deployment options in the
file? Oh, so Adam that that's a
different uh story. So maybe we can have
another session for how we can deploy
these models. For now, we are just
building uh a simple uh four different
applications. Right. Okay. I think we
are we are good to go. Now what I'm
going to do is I'm just going to see if
this is working. Okay. So I will say Google
Google generative
generative
sorry I'm not typing here. Google
generative AI. Okay. So that's what I
important. Okay. So Google generative AI
has multiple uh parameters. I'm going to
use two of these parameters. First I'm
going to tell which model I'm using. So
here is it. So there are different there
are different models right. So uh where
Gemini API has no here. So I'm using
Gemini 2.5 flash. I'm using this model.
Okay this model. So that's what I'm
going to use. So I'm going to say this
Okay. 2.5
2.5
flash. Okay, this is the product I'm
using. And this product has a API key. Google
Google
API key
is the key that we just
entered. Google API key. Okay. So this
way I am creating an instance from large
language model. Okay. I'm connecting to
large language model through the API.
And this is an instance of I'm going to
call this LLM. You I'm sorry not here.
I'm going to call it LM. You can call it
anything you like.
Going to be LM. I will copy the code and
share it with you in a minute. Let me
make sure that this is working. Okay.
All right. So
I will run this
and then I have a small typo here.
Okay. So I connected to genative AI. I
got llm. So next thing I'm going to do
is I'm just going to
send my first prompt. Okay. So I'm going
to use for that invoke method. So I'm
going to send my prompt and I will get
the response back from Gemini. Okay. So
I'm going to say say hello
hello
to this workshops participants.
participants.
I say this one.
Okay. And then I'm going to get the
response back
from Okay. So let's see.
So I am sending this prompt to LLM and
then waiting for the response. I got the
response. Let's print this response.
If you just say print response,
I will share the code in a moment. Let
me just run this. If you just say print
response, you will see uh hello
everyone. A warm welcome to all our
workshop workshop participants. We're so
glad to have you here today. Let's make
this a productive and insightful
session. So this is what Gemini is
telling us. Okay. So I'll I stop P here.
Let me see if Yeah. Uh so Rupa really I
it's very difficult for me to u check
what is wrong with installing so maybe
you can just follow the rest of the
works workshop and then try it later.
Okay I'm sorry about that. Okay so let
yeah is that a typo J yeah thank you so
I already typed the corrected the typo.
Okay. Now I'm going to paste the code.
So in case you were not able to write
the code.
this one.
chat. So another thing uh another
parameter for LLM is temperature. I
didn't use temperature here. I use
temperature the default temperature.
Temperature is another parameter that we
use to adjust how much of randomness we
are expecting from the response. So
basically what LLM is doing is it's just
predicting the next word. Right? If the
if the temperature is set to uh what
what is that uh one that means uh every
time you send the same prompt you will
receive the same response. uh by
changing the temperature you are
actually creating adding some randomness
to which word is going to be picked next
as LLM is making its decision on which
word it should pick next. So you are
adding some randomness to that decision
making process. So in that case every
time you send the same same prompt the
Yeah. So uh John uh that's what we we
want to do actually. So I I I see your
question why it did not give a length
response. So we are only we are we have
to be satisfied with whatever response
we are getting from this LLM. Now we are
going to write our code so that we are
going to give him some hints on what
kind of a response we are expecting from
him. So maybe we are going to tell him
that can you make this response warmer
and then longer. So that that's what
we're going to do. So this is just the
first step on seeing if our LLM is
actually active. So we now can we are we
being able to communicate with LM?
That's what we want to see now. Okay.
And then let's uh let me copy this one
too and then share with you guys. All
right. So this is the very first thing.
This is just the we're just checking if
our LM is working. Okay. If you guys are
ready, let's turn this into a function
and that will be our first demo. So it's
a row AI. Okay. I'm going to call it row
E AI. We are going to then work on this
to make it more interactive. So we are
going to actually steer AI to give us
responses in the format that we want him
to respond to us. So let me write our
let me turn this into a function and
it's going to look more professional.
Okay. So I'm going to say define my
first function. It's it's very simple
function. I'm going to call it row AI. Row
Row
AI. Okay. That's it. So there is no
parameter for my function. It's a very
simple function. So in this case I will
say I will ask expect from the user a
question. Okay. So what is that
Okay. So we are just going to ask
anything from Gemini and then again we
are just going to use this lm.
Uh let's use response
will be llm invoke. You can already see
the rest of the code right on the screen
but I'm typing it anyways. Okay. And
then I'm just going to print this. Print.
Print.
Okay. I will use this. So let's go to
the next line.
Gemini is saying this. Let me make
another. And this is the response.
So I'm just going to the next line.
Okay. So that is my function. Now I'm
going to uh
move outside. So and then run my function
raw AI.
AI.
Okay. And let's see what's going to
happen. Again the same thing we are just
asking some question. So I'm just
curious about AI agents. Okay. That's
the first thing I'm curious about. So
now we are getting the response and see
what Gemini is going to tell us about AI
agents. Okay. So this a very big
question actually. So uh yeah as you see
it's giving me uh a good explanation on
actually if you took any introduction to
AI course so you would understand you
would go through these terms pretty
easily right so perception action
environment so these are all defining
what an agent in AI agent should be
doing in an environment so then it's
giving us types of AI agents so model
based goal based agents and examples of
AI agents so this I It's not deep but
it's just giving us a very uh short
introduction to what AI agent is. Okay.
So our goal is not learning about AI
agent by the way. We just wanted to see
that we can make this work writing a
function. Okay. So that will be our row
AI function. As I said now we're going
to work on this and then make it work
better. Now let's do this. Let's uh
instead of asking a single question and
by the way let me check
is invoke the standard chat messaging
syntax with these lms. Yes. Yes. Yes.
Adam. So this is actually uh sending the
prompt and then getting the response. So
that's that's that's what we are using
for this is coming from lench chain.
And could you post here the pip install
code as well? I missed the beginning of
this. Sure. Yeah. in and we are going to
be sharing the recordings uh later. So
this is the pip install code I'm sharing
with you.
Okay. Now let's do this. Let's uh rather
than uh having a single question uh
we're expecting a single question from
outside let's put a number of questions
on a list. Okay. So and then we are
going to uh what is that uh uh again ask
from our Gemini to answer those
questions. So we want to do we want to
make a an observation here. Okay. So
this is this is the list of the
questions. So I'm going to put my first
question. Explain
machine learning.
Okay. So I just want him to explain to
me machine learning. So this is going to
be my first question. Tell me briefly. Briefly.
Briefly.
I think LM will understand even though
my pronunciation is not good. tell me
briefly uh about
Okay. So these are all same questions
that I'm
telling in different formats. Okay. What
is this machine learning thing? Okay. So
I'm asking questions in different
styles. Okay. So that's that's what I'm
doing. Next what I'm going to do is I'm
going to make my uh llm answer these
questions one by one. So let's write a
for loop. Okay for questions in questions.
questions.
Okay. So I I'm going to pick each
question one by one. So uh let's first
uh write a print statement to indicate
this is the question. Okay. So that we
know which question we are getting
answered for. Okay. So we are getting to
the next line and then this is the
question. Okay, first let's see the
question then let's get the response to
this question. Invoke
Invoke
question. Okay, let's not print
everything. Let's print just the first
maybe 200 characters because the the
answer is too long, right? So I don't
want to see the whole thing. That's not
the point here. So let's get the response
response
Okay. All right. So what I'm doing is
very simple. I just put the three
questions about the same thing in a
different style and then I'm just uh
sending these questions one by one to my
to the Gemini and then I'm getting the
response. I'm only printing the first
150 characters of these responses. I I
just want to see if there is if I'm
going to get exactly the same responses
or different responses. Okay, that's
what I want to test. Okay, so this is
the first question. Explain machine
learning. So we are waiting for the
response again. We're going to see the
and uh it's taking time. Yeah. So
imagine you want to teach a computer to
tell the difference between a picture of
a cat and a picture of as you see it
just begin to explain
to me and then the next tell me briefly
about machine learning. So machine
learning is a subset of artificial
intelligence that enables computers to
learn. Uh so what is this machine
learning? Imagine you want to teach a
computer to recognize cats and pictures
in traditional product. So I'm I'm
asking three questions about the same
thing with different styles. I'm getting answers.
answers.
You can see more or less the answers are
uh saying same thing but uh you can see
that uh depending on the question right
so the the answers are slightly
different uh so this is just to test
that you may see inconsistencies
about the responses you receive even
though you ask the same question with uh
uh different styles that's the first
thing and second thing is maybe I want
AI to explain to me uh about machine
learning in a certain style. For
example, first explain it briefly, then
give me an example. Uh uh okay. And then
tell me uh what is the role of machine
learning in the future. Okay. So maybe I
want him to explain any topic. It can be
it can be machine learning, it can be uh
uh quantum mechanics, it can be
blockchain. Okay. Any topic. First tell
me briefly what this topic is about.
then give me an example and tell me what
how this is going to be impactful in the
future. So, so if I want the AI to
explain things to me in a certain way,
so I need to tell this. So, I need to
tell this so that I will see consistency
in the responses. Okay, that's just an
observation. Nothing fancy going on
here. Okay. All right. Now, let's uh add
some structure, okay, to our uh what is
that um coding. So this time we are
going to interact with AI but our
interaction will be a little bit more
structured. Let me see if there are any.
Can you paste this in your question?
Yeah, I'm going to
here.
Okay. So what is the goal of this agent?
Right now there is no goal for this
agent. This agent is
a guru sitting on his chair and then
answering any question uh asked to him.
Okay. It's a very now right now this
this this agent knows claims to know
everything about anything. Okay. So then
later we want to specialize it to a
certain topic. All right. So that's what
we're going to do. All right. Provide
the function code. Yeah. I just provided
it. Yeah. Okay. Let's continue. So now
uh I'm going to uh import some
additional libraries uh from Google
Google gen AI import Google
Google
generative AI. Okay. I'm assuming we are
all new to this field. So I'm trying my
best to go slow. Okay. So and then if
you are behind let me know if you need
me share any of the code let me know.
Okay. Once import prompt
prompt
templates. Okay. So you can understand
from the libraries we are importing. We
are still going to use Google generative
AI but this time we are going to create
a prompt template. Okay. So that is
going to give some structure to the the
way we are asking the questions.
And then the last one from lang chain core
core
okay dot output.
I have some other examples on this third
one but I decided not to do it today. So
what we are doing now this this imported
library this third one is going to put
the response
uh which is the output coming from lench
chain coming from llm to a certain
format okay and then you can define this
format yourself here I'm not defining
the format myself I'm just going to use
the format uh coming with the library
okay all right so let me run this and
I provided the function code but uh I
I'll provide it again.
Oh, you mean this one? Sure.
Now, if you guys are ready,
we are here. We are going to
build another application, a small application.
application.
This time we are going to create a
prompt which has a certain structure.
Okay. So let's build a template for our
uh uh prompt which is going to make LLM
respond to us in a consistent way. Okay.
So I'm going to use prompt template.
Okay. So this prompt template has
certain parameters. First of all, what
is the input variables?
So the input variable is going to be let
me get to the next line so you can see
this. The input variable you can you can
do anything here. So the input variable
is topic. So in this prompt one of the
variables is topic. So the topic can be
again AI agents can be blockchain uh or
or can be weather can be a certain city.
So it can be anything. Okay. So that is
a variable in our template. So let me go
here. Okay. Comma. So this is one of the
first parameters of the template. The
second template. Now I'm going to write
my template. Template.
Okay. So here is the template. explain
now this is the prompt that I will give
to the AI tool but I want I don't want
to write a specific topic here so this
topic is a variable okay explain
whatever this topic is so when we create
the prompt that topic will change we are
going to define that topic for now I
don't know what that topic is I'm just
giving a template so you can fill in
empty spaces in this template based on
what you want to say okay explain
whatever this topic
in simple terms with an example. Okay.
So, I'm not going to stop here. I'm
going to even give further instructions.
So, here are the instructions. Okay. The
format is going to be as following. Keep it
it
under 100 words.
Okay.
And end with a end with a practical
example. This is what we want to see. So
I'm going to give you the topic but and
then here is how you are going to give
me topic is this which is topic.
Okay. This is how I I will see a a
response and then here is explanation.
This is the explanation and I am ending
my template. Okay. So this is my template.
template.
and then let me assign this template to
a variable. Let's use prompt. So I'm I'm
going to use this template for my next.
So prompt
remember prompt is the variable which is
holding the template. Now I'm going to
fill this template by again I have only
one variable here. You may have many
variables. You can add multiple
variables here. I have only one
variable. I just wanted to make it
simple. So now I am going to fill in the
empty spaces. topic is
uh AI agent. Okay. So that is my
template. So this going to be my field prompt.
Okay. Okay. So I just use the template
to create my prompt and then let's see
Okay, it's it looks something like
explain AI agent. So I replaced topic
with AI agent in simple terms with an
example blah blah. Topic is AI agent
explanation will follow.
Okay. Now let's see this is like a mail
merge, right? So there is a template
there are infinite number of variations
and then we are giving AI formatting
instructions. So this is going to ensure
consistency across all responses we
receive from the AI. Now, what I'm going
to do next is
I'm going to build a chain. Okay? I'm
going to call it chain.
All right? So, let me see if you have
any questions.
Uh, can you paste it, please? I'm
Okay. So, I'm pasting this one more
on on the chat. Okay,
All right. So, please let me know when
you have any questions. All right. Now,
I'm going to build a chain. So, now we
are talking about len chain. Okay. So,
I'm building a chain. So, this chain is
going to first take my rounds. So,
imagine that.
Imagine the order of things happening.
Okay. First
give the prompt.
Then connect to LLM and get the response.
response. Response
Response
then format the response
and give it as the out. Okay. So that's
what I want. I want to do three things.
First give the prompt then connect
connect to LLM and get the response and
then I would like to format the response
and give it as the output. That's what I
want to do. So here it is. This is the
prompt. This is the first step. So I'm
going to connect these uh steps uh uh
this way. So prompt line and then lm.
What is lm? lm is what we instantiated
earlier, right? So this one LLM I'm
using Google generative AI Gemini 2.5
flash with this API key. So this LLM is
our guy who is responding to us. Okay,
so we are asking these questions to LM.
Again you can name it anything you like.
My LLM your LLM. Okay, that is the
second step. And the third step is
whatever response is coming it's going
to be parsed output
in a certain format parser.
Okay. So first LLM is going to take the
input. So we are going to fill the
template send it this to Gemini. We're
going to get the response and then the
response is going to be cleaned up and
then we're going to get the output.
That's the order of things that will
happen. So this is our chain. All right.
So let's uh run this.
Nothing is going to happen. So we just
define the chain. Okay. Now what we're
going to do is we are going to give uh
three different topics and then we are
going to get the responses to these
topics. Okay. So let's do that. I'm
going to write a very simple code again.
This this time these are the topics.
I'm just going to give different topics.
Let's say blockchain things that you are
interested in you can give anything what
whatever you are interested in AI agent
okay and then what is that internet model
model
so these are things that I'm interested
in so okay so these are the topics now
let's go through the same uh for loop
that we did earlier for topic in topics
okay again I'm just going to print. I
can see the code here. I'm just typing
it anyways for for us. Okay.
So, I will first print the topic explaining
explaining
Okay. So, this is the topic. Now, this
is what's important, right? So, I'm
going to get the results
by LLM. Sorry, not LLM. I'm not using
LLM anymore because I already have LLM
in this pipeline chain right so I'm
going to use my pipeline chain so I'm
going to use chain
so that is a difference from the
previous case in the previous case we
were invoking we were getting response
directly from lm now I'm going to put my
uh prompt uh through this uh pipeline
Okay, now the chain is going to get an
input from us, right? What is that
input? You look look at the chain. Chain
is receiving the first step in the chain
is prompt. If you look at prompt, prompt
is expecting an input variable from us.
What is that topic? So here here is the
time for us to tell or give the chain
what the topic is. That's what we're
going to do. Okay. So here is what we we
topic. So this is this topic is the
variable this variable. Okay. And this
is the value for that variable that we
are assigning this topic. So this is
maybe maybe let me use a different name
here so that you're not going to be
confused with topic topic
or T in topics
topic is T. Okay. So T is the topic
name. Topic is the variable name. Okay.
Uh I think that's going to be better uh
for us. Uh and then let me take this u
uh what is that uh response first of all
uh u yeah let's just print it. Let's not
make this longer. So I'm just going to
say f response
is the result.
Okay. So let's see what's going to
happen now and then I will also share
the code with you. Let's me first make
sure that uh I have I don't have any
typos and there is typo
explaining oh this should be t2 right.
So t and t are referring to this t which
is coming from this list. So I'm I'm
running for loop uh through this list.
Right? So t is elements of this list.
Okay. Let me run this. Yeah. So it's
working. So now I gave a certain I gave
the instructions right. So first keep it
under 100 or it should be keep it use an
analogy and end with a practical
example. I'm just curious let's see
what's what what is said for blockchain
response blockchain is a shared
unchangeable digital ledger. Imagine a
public diary where each now it's giving
me the analogy right. Imagine a public
diary where each new page block is
cryptographically linked to the last
forming a chain. Once an entry is added
and verified by the network is virtually
impossible to alter. Okay. So this is
the uh what is that the analogy. Now
let's see if it is giving any practical
example. This decentraliz centralization
and transparency make it highly secure
and trusted. A practical example is
bitcoin. Now it's giving us a an
application of blockchain which is
bitcoin. That's perfect. Right? So it
just followed all the instructions and
then it kept with under 100 words and it
we just now we just structured the
response we are receiving from from our
LLM. I think this was a simple but a
good example. So let me copy this and
share with you guys if you are falling
Yeah. Uh so Janine so it's it's it will
be hard for me to to come up with the
version numbers now. Uh
again uh yeah I I had similar issues. So
I I I ran all these things uh on my
other VS codes and then uh I had some
compatibility issues. That's why I chose
to use Google Collab. I thought it would
be this it will be the same for all of
us. It will be much easier for all of
us. Yeah. Uh could could you please
share the prompt? Oh, sure. I'm sharing
Here it is.
Okay. It's a yeah
I'm seeing variance in response structures
Adam what is what do you mean variance
in this yeah so there is there is there
is a yeah there is there is a change in
the bet but this is this is the
structure we are expecting right so it's
exactly following other instructions
that just to see that we can control
this large lm is so nice right so we we
are making it follow a certain structure
yeah kumal You're going to receive an
email from us uh on on on this session
uh where you can see the recordings.
Recordings will be available at YouTube
channel, Magnum's YouTube channel. Okay,
let us continue. Now we going to do uh
uh maybe
uh what is that uh another example.
Okay. So here we learned about uh
creating a chain and that actually uh uh
helped us see a structured response from
the uh AI agent. Now we are going to
take one further step. Okay. Now so so
at first we use the row AI. Second we
structured our query. Third
let's say we want to build an agent
using this LLM. Still LLM is our guy.
Okay. It's waiting there for us uh to
help. So he will always help throughout
the session. He will always help to us,
give help to us. So now what we want to
do is we want to uh work LLM for us for
our company. Okay. Uh but for that we
need to give some information some
knowledge to LLM. So LLM doesn't know
us. He knows uh a lot about in general
about companies but he doesn't know
specifically about our company. Okay. So
it doesn't know about our company but it
knows in general what other companies
are doing. So let's first try to see how
LLM our guy is going to respond to uh to
this question. So I'm going to again uh
not not too what is that uh uh not too
different than what we did earlier. I'm
going to create a couple of questions
for for our LM but these questions are
now specific questions about uh about a
company policy. Okay. So here are some
some questions. Question one, what's
your return policy? What is your return
policy? Okay, it's a very valid
question, right? So, question mark.
Okay, that's the first question. Let's
give the second question. What are your
Okay, that's the second question. And
third, make sure there is a comma here.
And I'm going to give a short break.
Okay, after this one. And then what are
your support hours? You see these are
some valid questions that you can ask
from uh from any company right when you
are uh making any transaction with them. Okay.
Okay.
Now what I'm going to do is and I'm
going to go through these questions again
again
for Q in questions in company questions.
You are already familiar with this
format right? So we did this uh many
times now. So I'm going to say response is
I'm going to invoke
what is that uh my chain remember the
chain that we used
right so this time topic is these questions
questions
okay topic is this questions but uh I
mean u yeah let's see let's see what
what what how how it's going to work
because now I actually I don't want to
use an analogy it's not going to be
Let's just let's rather than using the
chain, let's just use LLM itself. Okay,
LM I'm just going to use LLM itself
because it doesn't make sense to have
any uh analogy for these questions,
right? So, let me use NLM.
Okay, walk. Uh what is that?
Q, right?
Q. All right. And then I will just print
the question. question
question
50 characters
again. Okay. So, let's see if this is
All right, let's see what what we what
we are going to receive.
Oh, we should have used uh
Yeah, it's not it's it's it's not
actually answering our our question. So
first of all, let me make this
Oh, I'm just printing 150th character of
the response. So that's why. Okay, I'll
I'll fix it. I'm going to print the
first 150 characters. So that's why you
see you we need to know how to deal with
um in this case strings, right? So I was
just printing the 150th character. So okay.
All right. Let's see. Yeah. What is your
return policy? Imagine you want to teach
a computer recognized GM in traditional
company questions?
It is still taking the queue from
previous case. Okay, let me fix this.
Let's take a break now. I'm going to fix
this. I'm not going to use Q here. So,
it's it's a good time to take a break.
It's 10:02 during the break time. I'm
going to fix the code. So, let's meet at
10 12. Okay. In 10 minutes, it's 10:02
Okay. Uh we're going to start in 3 minutes. So during this time, let me go
minutes. So during this time, let me go through the questions. First of all, I
through the questions. First of all, I just fixed that was a very simple
just fixed that was a very simple mistake I was making. I just fixed the
mistake I was making. I just fixed the uh the problem here. So, so we get the
uh the problem here. So, so we get the answers. But let's talk about this in 3
answers. But let's talk about this in 3 minutes. Uh getting an error on the
minutes. Uh getting an error on the first row. LM is not defined. So, we
first row. LM is not defined. So, we defined LLM at the very beginning
defined LLM at the very beginning literally. So, here LLM this one. So,
literally. So, here LLM this one. So, you need the Google API key for that.
you need the Google API key for that. So, this is the API key. I'm going to
So, this is the API key. I'm going to share the API key one more time.
This is the API key. you can use for this session. It's not going to be there
this session. It's not going to be there in maybe 30 minutes. And this is LLM.
This is how we define LLM. And uh so yeah, notebooks. I I can share this
yeah, notebooks. I I can share this notebook. It's not a problem. Uh let me
notebook. It's not a problem. Uh let me see what how we can do. So I can I can
see what how we can do. So I can I can put this one to my uh to my uh what is
put this one to my uh to my uh what is that?
that? uh GitHub account. So I think that's
uh GitHub account. So I think that's going to be the best. Okay. So I can
going to be the best. Okay. So I can upload this to the to my GitHub account
upload this to the to my GitHub account and then make it public so you can have
and then make it public so you can have access to this. But again we are going
access to this. But again we are going to have the recording anyways. So you
to have the recording anyways. So you can follow the recording as well. Let me
can follow the recording as well. Let me see if we'll be recording. Yeah. Could
see if we'll be recording. Yeah. Could you explain briefly what link chain is
you explain briefly what link chain is and what its relationship with LLM is?
and what its relationship with LLM is? Thanks. So link chain is uh as a
Thanks. So link chain is uh as a framework here. So what what it is
framework here. So what what it is allowing us is creating structured
allowing us is creating structured prompts. So again it's it's a lot more
prompts. So again it's it's a lot more than that but uh for now that's that's
than that but uh for now that's that's the use the use of lench chain for us.
the use the use of lench chain for us. We are creating structured prompts so
We are creating structured prompts so that we can communicate with our large
that we can communicate with our large language model. So it is a a way for us
language model. So it is a a way for us to communicate with LLM in a structured
to communicate with LLM in a structured manner. Okay, let's put it that way.
manner. Okay, let's put it that way. It's it's a lot more than this by the
It's it's a lot more than this by the way.
way. uh how would you pass out parameters
uh how would you pass out parameters from one step in the chain to the next?
from one step in the chain to the next? For example, LM has more than one
For example, LM has more than one variables in the response. Uh can I'm
variables in the response. Uh can I'm trying to understand. So how would you
trying to understand. So how would you pass output parameters from one step? Oh
pass output parameters from one step? Oh yeah, you can you can assign your output
yeah, you can you can assign your output to one of the variables to another
to one of the variables to another prompt and then create a chain like you
prompt and then create a chain like you get the response from the previous
get the response from the previous question but then the response to the
question but then the response to the first question will be an input to the
first question will be an input to the next prompt. So you can create a chain
next prompt. So you can create a chain of prompts and each prompt is using the
of prompts and each prompt is using the response to the previous prompt. Yeah.
response to the previous prompt. Yeah. But again uh this is the first time we
But again uh this is the first time we are uh I'm assuming that all most of us
are uh I'm assuming that all most of us are uh learning about this topic for the
are uh learning about this topic for the first time. So we are just uh navigating
first time. So we are just uh navigating uh entrance okay uh entrance door to to
uh entrance okay uh entrance door to to AI agents. Maybe uh in other workshops
AI agents. Maybe uh in other workshops we can go deeper and then create more
we can go deeper and then create more sophisticated ones. But this these are
sophisticated ones. But this these are very simple uh agents. We just want to
very simple uh agents. We just want to see the difference between just
see the difference between just communicating with chat GBT versus
communicating with chat GBT versus communicating with GPT with in a
communicating with GPT with in a structured manner.
Okay. Yeah. I think we are what extra does
Yeah. I think we are what extra does prompt give over simply invoking LM?
prompt give over simply invoking LM? What extra does prompt give over simply
What extra does prompt give over simply invoking?
invoking? I mean uh the prompt is set of the
I mean uh the prompt is set of the instructions right in addition to
instructions right in addition to instructions uh we can use the same
instructions uh we can use the same template for many different topics. So
template for many different topics. So for each question I don't I'm not I
for each question I don't I'm not I don't want to write a prompt. What I
don't want to write a prompt. What I want to do is I want to use in this case
want to do is I want to use in this case I'm just explaining regarding this case
I'm just explaining regarding this case I want to use a template which is going
I want to use a template which is going to only replace in this case only topic
to only replace in this case only topic so that I can send the prompt to to the
so that I can send the prompt to to the LM
LM could you put the link to the collab
could you put the link to the collab here please? JJ uh for that I need to
here please? JJ uh for that I need to share this one. Sure I can do that.
share this one. Sure I can do that. I need to find the Okay, so let's do
I need to find the Okay, so let's do this. Just I'm going to stop sharing for
this. Just I'm going to stop sharing for a minute and then uh in 30 seconds we
a minute and then uh in 30 seconds we are starting again. So let me find the
are starting again. So let me find the file in my Google Drive. Okay, just one
file in my Google Drive. Okay, just one second please
workshop called
called June 28,
June 28, 2025.
Okay, [Music]
[Music] just one second, please.
Okay, I got it. So, this is the link to this
So, this is the link to this file. I'll keep this file in my Google
file. I'll keep this file in my Google Drive so you guys can have access to
Drive so you guys can have access to this file. Okay. All right. Let me share
this file. Okay. All right. Let me share my screen now.
All right, let's continue guys. Let's continue. Uh there is uh there is more
continue. Uh there is uh there is more to do now. All right, now what we're
to do now. All right, now what we're going to do is first of all let's see
going to do is first of all let's see what happened here. Okay, so I asked
what happened here. Okay, so I asked three questions. What is your return
three questions. What is your return policy? What are your shipping costs?
policy? What are your shipping costs? What are So LM the guy that is
What are So LM the guy that is responding to us as you see gave us very
responding to us as you see gave us very gener general answers, right? So as an
gener general answers, right? So as an AI, I don't sell physical product or
AI, I don't sell physical product or services. I don't have a return policy.
services. I don't have a return policy. I'm here to provide. So there is no
I'm here to provide. So there is no return put because this guy is not
return put because this guy is not selling stuff as an AI I don't sell or
selling stuff as an AI I don't sell or ship physical. So I don't have any
ship physical. So I don't have any shipping cost. So yeah we are asking
shipping cost. So yeah we are asking some questions but these questions uh
some questions but these questions uh LLM cannot answer them because I mean uh
LLM cannot answer them because I mean uh even what are the what are the support
even what are the what are the support hours? I'm available 24 hours 7 days a
hours? I'm available 24 hours 7 days a week but that is only the LLM itself.
week but that is only the LLM itself. Okay. So but we want to ask these
Okay. So but we want to ask these questions we want to be able to answer
questions we want to be able to answer these questions for our own company.
these questions for our own company. Okay. So that's the next thing. What we
Okay. So that's the next thing. What we want to do is we want to provide some
want to do is we want to provide some input to our LLM so that LLM can use
input to our LLM so that LLM can use that input when responding to these
that input when responding to these questions. So that's the next thing
questions. So that's the next thing we're going to do now. So that is called
we're going to do now. So that is called rack solution retrieval augmented
rack solution retrieval augmented generation. So we are giving AI access
generation. So we are giving AI access to specific knowledge and then uh uh
to specific knowledge and then uh uh it's like giving giving AI a handbook
it's like giving giving AI a handbook about our company. So AI is going to
about our company. So AI is going to check that handbook before answering the
check that handbook before answering the questions.
questions. All right. So that's what we want to do.
All right. So that's what we want to do. So first of all that handbook again
So first of all that handbook again we're going to keep it very simple. This
we're going to keep it very simple. This can be very very sophisticated. We're
can be very very sophisticated. We're going to keep things very simple. This
going to keep things very simple. This here is our handbook. Okay. So we are
here is our handbook. Okay. So we are going to create documents.
going to create documents. These documents are this extra knowledge
These documents are this extra knowledge we are providing to LLM. So this is
we are providing to LLM. So this is about our company. Okay. So I'm just
about our company. Okay. So I'm just going to write this. We offer 30-day
going to write this. We offer 30-day returns
returns with receipts. Okay, that's our policy.
with receipts. Okay, that's our policy. Okay, second,
Okay, second, free shipping
free shipping on orders over $50. Okay, again, that's
on orders over $50. Okay, again, that's our second policy.
our second policy. Third, support available
9:00 a.m. to 5:00 p.m. Friday, Monday to Friday, Monday
Friday, Monday to Friday. So, I'll talk about this in a
to Friday. So, I'll talk about this in a moment. And then we
moment. And then we accept all major
accept all major credit cards. Okay, not paper. All
credit cards. Okay, not paper. All right. So these are our company
right. So these are our company policies. Now let's think how we can use
policies. Now let's think how we can use these documents. I can build an
these documents. I can build an application.
application. In this application uh if a customer
In this application uh if a customer arrives at my application at my website
arrives at my application at my website and then wants to ask a question the
and then wants to ask a question the application will receive that question.
application will receive that question. So it's almost like input right? So we
So it's almost like input right? So we are asking the customer input give me
are asking the customer input give me your question
your question of course we're going to say please give
of course we're going to say please give me your question your question
me your question your question and then what we can do is given this
and then what we can do is given this question
question we can check the words in the question
we can check the words in the question let's say if in the words it's about
let's say if in the words it's about returns
returns okay I can simply if for example if
okay I can simply if for example if input is a question
take this question and then split it into words and then check each word in
into words and then check each word in that question and then if you catch any
that question and then if you catch any words that are also in one of these
words that are also in one of these documents for example the question is
documents for example the question is what is your return policy right so one
what is your return policy right so one of the words return is matching with
of the words return is matching with this returns that means the question is
this returns that means the question is most likely about this document I can
most likely about this document I can simply report the first document so what
simply report the first document so what is your return policy the answer will we
is your return policy the answer will we offer further returns with receipts.
offer further returns with receipts. So to some extent that would solve the
So to some extent that would solve the problem to some extent. Okay. Again I
problem to some extent. Okay. Again I take the question I break the question
take the question I break the question into words. I go through the words in
into words. I go through the words in the question and then I count how many
the question and then I count how many of those words are actually I do the
of those words are actually I do the same thing about these documents. I also
same thing about these documents. I also break these documents down into words
break these documents down into words and then I compare what is the overlap
and then I compare what is the overlap between the question and these documents
between the question and these documents and the document that gives the most
and the document that gives the most overlap I'm going to pick that document
overlap I'm going to pick that document and then uh the posted as my response.
and then uh the posted as my response. Okay, I can use an if else statement for
Okay, I can use an if else statement for that. It's going to be a rulebased
that. It's going to be a rulebased system and to some extent that might
system and to some extent that might work. But let me ask you this.
work. But let me ask you this. Rather than doing this, how about I tell
Rather than doing this, how about I tell you that take the question
you that take the question and then find the closest document to
and then find the closest document to that question. Again, we are the logic
that question. Again, we are the logic is still the same, get the question like
is still the same, get the question like what is your return policy, but this
what is your return policy, but this time rather than going through each word
time rather than going through each word one by one. So if there was a way for me
one by one. So if there was a way for me to compare this question with these
to compare this question with these documents
documents not not word by word but uh if I could
not not word by word but uh if I could represent these documents and the
represent these documents and the questions in terms of numbers
questions in terms of numbers and then let's say one of the four let's
and then let's say one of the four let's say the first documents. So I create
say the first documents. So I create let's say uh numbers representing these
let's say uh numbers representing these documents. Now my documents will look
documents. Now my documents will look something like this. Okay I'm just I'm
something like this. Okay I'm just I'm just making up. Okay. 4 5 1 6.
just making up. Okay. 4 5 1 6. Four is representing the first document.
Four is representing the first document. Five is representing the second
Five is representing the second document. One is representing the third.
document. One is representing the third. Six is representing the fourth document.
Six is representing the fourth document. And the let's say question whatever the
And the let's say question whatever the question is. So what is your return
question is. So what is your return policy? Question is also represented as
policy? Question is also represented as a number. Let's say and then that number
a number. Let's say and then that number is I'm just making it up. I am just
is I'm just making it up. I am just making up. Okay. It is 3.9.
making up. Okay. It is 3.9. Okay. again how the number is coming
Okay. again how the number is coming from how why suddenly we are using
from how why suddenly we are using number for a question that we'll see in
number for a question that we'll see in a moment but what I'm doing is I take
a moment but what I'm doing is I take the question what is your return policy
the question what is your return policy and that is mapped to a some number that
and that is mapped to a some number that is 3.9 now I'm going to compare I'm
is 3.9 now I'm going to compare I'm going to measure the distance between
going to measure the distance between this number and all other numbers so
this number and all other numbers so this time the distance is very easy
this time the distance is very easy right so what is the distance between
right so what is the distance between 3.9 and four it's 0.1 what is the
3.9 and four it's 0.1 what is the distance between 3.9 and five it's 1.1.
distance between 3.9 and five it's 1.1. So I'm just taking the difference
So I'm just taking the difference between these numbers. So the closest
between these numbers. So the closest the smallest distance is four. That
the smallest distance is four. That means four is corresponding to this. We
means four is corresponding to this. We offer third terms with receipts. Okay,
offer third terms with receipts. Okay, that's the first uh novelty I'm bringing
that's the first uh novelty I'm bringing rather than counting the words. What I'm
rather than counting the words. What I'm doing is I am mapping all the documents
doing is I am mapping all the documents and the questions all the strings into
and the questions all the strings into numbers. Here I used only one number
numbers. Here I used only one number single numbers a scaler but I can use
single numbers a scaler but I can use bunch of numbers actually I can use
bunch of numbers actually I can use let's say 150 numbers for any document
let's say 150 numbers for any document and if you ask me how that's a different
and if you ask me how that's a different story okay but let's assume that it did
story okay but let's assume that it did that is doable that's the first novelty
that is doable that's the first novelty I introduced to this this very simple uh
I introduced to this this very simple uh what is that uh application now the
what is that uh application now the second one rather than just saying we
second one rather than just saying we offer third rate turn with receipts yeah
offer third rate turn with receipts yeah we know that the question is what is
we know that the question is what is your return policy? The answer is we
your return policy? The answer is we offer 30 returns with receipts. I also
offer 30 returns with receipts. I also want now my chatbot let's call it
want now my chatbot let's call it chatbot respond more humanely like uh
chatbot respond more humanely like uh thank you for asking this question. Uh
thank you for asking this question. Uh so we understand that you want to return
so we understand that you want to return your product and uh uh we just want to
your product and uh uh we just want to let you know that our we offer a
let you know that our we offer a thirdary return with receipts. Please
thirdary return with receipts. Please make sure that you bring your receipt
make sure that you bring your receipt with you when you want to return your
with you when you want to return your product. So what we are doing is we are
product. So what we are doing is we are actually answering the question but what
actually answering the question but what when we answer we are answering using
when we answer we are answering using this policy but in a in a more more what
this policy but in a in a more more what is that humanly way so that the other
is that humanly way so that the other person is going to be pleased to hear
person is going to be pleased to hear that response. So that is the second
that response. So that is the second novelty we want to bring. Okay. The
novelty we want to bring. Okay. The first novelty is the way we are
first novelty is the way we are searching through the documents finding
searching through the documents finding the best document which we can use in
the best document which we can use in our in our response to this question.
our in our response to this question. Actually that document will be that
Actually that document will be that document and the question together will
document and the question together will be a prompt we are sending to the LLM
be a prompt we are sending to the LLM and then LLM is going to response using
and then LLM is going to response using those two inputs. What is that the
those two inputs. What is that the document that is most related to the
document that is most related to the question and question itself and then
question and question itself and then LLM is going to use these two to create
LLM is going to use these two to create a better response rather than simply
a better response rather than simply saying we offer further returns with
saying we offer further returns with receipts. it's going to be more uh again
receipts. it's going to be more uh again we can even check control that how the
we can even check control that how the response is going to be how long it's
response is going to be how long it's going to be how it should maybe start
going to be how it should maybe start with a greeting to the customer anyways
with a greeting to the customer anyways so that's what we want to do now okay
so that's what we want to do now okay that's the next thing we want to do all
that's the next thing we want to do all right so let's get started then
right so let's get started then the first thing is let's talk about
the first thing is let's talk about these numbers we're going to call them
these numbers we're going to call them embeddings I'm going to write the word
embeddings I'm going to write the word embedding again this is a large topic if
embedding again this is a large topic if you has learned large language models.
you has learned large language models. Uh so this is a very important topic
Uh so this is a very important topic embedded. Uh so how we create
embedded. Uh so how we create embeddings? Embedding is again coming up
embeddings? Embedding is again coming up bunch of numbers which is representing a
bunch of numbers which is representing a document. Okay. And then we want to make
document. Okay. And then we want to make sure that these numbers are for any
sure that these numbers are for any document at equal length. Let's say I'm
document at equal length. Let's say I'm going to use 134 numbers or 300 numbers
going to use 134 numbers or 300 numbers for any document. How we come up with
for any document. How we come up with numbers as I said that's a different
numbers as I said that's a different story. Okay. for coming up with
story. Okay. for coming up with embeddings I'm going to use hugging face
embeddings I'm going to use hugging face are these what we call vectors yeah
are these what we call vectors yeah embedding vectors Adam is that's what we
embedding vectors Adam is that's what we call yeah I I don't want to use two so I
call yeah I I don't want to use two so I want to keep it as uh what is it again
want to keep it as uh what is it again we are I'm assuming that we are totally
we are I'm assuming that we are totally new to this domain all right so I'm
new to this domain all right so I'm going to use hugging face embeddings
going to use hugging face embeddings there are many different libraries we
there are many different libraries we can use or tools we can use to create
can use or tools we can use to create embeddings for this one I'm going to use
embeddings for this one I'm going to use hugging phase embeddings. First of all,
hugging phase embeddings. First of all, I'm not going to I'm not going to run
I'm not going to I'm not going to run this one. Okay, so let's um yeah, let me
this one. Okay, so let's um yeah, let me get to the next one. I'm going to use
get to the next one. I'm going to use embeddings. Embedings.
embeddings. Embedings. I will use hugging
I will use hugging face
face embeddings. Did I? But before I use
embeddings. Did I? But before I use hugging face embeddings,
hugging face embeddings, I think I need to import it from
I think I need to import it from lang chain embeddings
lang chain embeddings import
import hugging
hugging face
face embeddings again embeddings will create
embeddings again embeddings will create these numbers for the documents that's
these numbers for the documents that's all it's going to do okay that's what we
all it's going to do okay that's what we expect and then later I'm going to use
expect and then later I'm going to use this uh database this database is going
this uh database this database is going to hold these embeddings this database
to hold these embeddings this database is going to so for example when I
is going to so for example when I receive the question. How am I going to
receive the question. How am I going to go and dig and find the closest response
go and dig and find the closest response to that question? So, I need to keep
to that question? So, I need to keep these documents. After I find the
these documents. After I find the embeddings for these documents, I need
embeddings for these documents, I need to store them in a in a in a database so
to store them in a in a in a database so that it's going to be fast. So, I expect
that it's going to be fast. So, I expect a database that is going to be very
a database that is going to be very efficient in terms of finding finding
efficient in terms of finding finding the closest embedding really fast. Okay?
the closest embedding really fast. Okay? Because I don't want people wait when
Because I don't want people wait when talking with a chatbot. you ask a
talking with a chatbot. you ask a question, you you don't want to wait for
question, you you don't want to wait for 10 seconds to get the answer, right? You
10 seconds to get the answer, right? You want to get the answer right away. So, I
want to get the answer right away. So, I need something which works really fast
need something which works really fast so that uh when I receive a question, I
so that uh when I receive a question, I find the embedding for that question and
find the embedding for that question and I find the closest record from all the
I find the closest record from all the documents in my database. So, for that
documents in my database. So, for that I'm going to use a database, but not for
I'm going to use a database, but not for now. Okay, not for now. Okay,
now. Okay, not for now. Okay, embeddings. Let me use this word
embeddings. Let me use this word correctly. Embeddings. Hugging face.
correctly. Embeddings. Hugging face. It's a small A.
It's a small A. embeddings and uh I'm going to use a
embeddings and uh I'm going to use a specific model. Again, these model names
specific model. Again, these model names can change by time. Okay, this is all
can change by time. Okay, this is all mini L ln L6
mini L ln L6 D2. Okay.
D2. Okay. All right. So, let me run this and
All right. So, let me run this and hoping that it's going to work. So, we
hoping that it's going to work. So, we we're just going to wait for loading it.
we're just going to wait for loading it. Okay. And then during this time, let me
Okay. And then during this time, let me see if you guys have any questions at
see if you guys have any questions at the end. Can you explain how to get our
the end. Can you explain how to get our own API if you if you are expired? Yes,
own API if you if you are expired? Yes, John, it's very easy. I got this Gemini
John, it's very easy. I got this Gemini API. Go to your Google, go to just type
API. Go to your Google, go to just type Gemini API. Uh it's it's like 10
Gemini API. Uh it's it's like 10 seconds. So, you just going to use your
seconds. So, you just going to use your Google account to get API. Actually, you
Google account to get API. Actually, you can get API for free. Gemini gives you
can get API for free. Gemini gives you free API. Use that for your exercise.
free API. Use that for your exercise. Just keep in mind that it has a it has a
Just keep in mind that it has a it has a limit on I think per minute. Uh there
limit on I think per minute. Uh there are there is the limit on number of
are there is the limit on number of prompts you can send. Uh I didn't want
prompts you can send. Uh I didn't want to use the free one for this workshop
to use the free one for this workshop because uh I don't want to you know stop
because uh I don't want to you know stop in the middle right now. The API you are
in the middle right now. The API you are using I I'll be paying for it but it's
using I I'll be paying for it but it's it's not going to be there in in 30
it's not going to be there in in 30 minutes. But you can use Gemini API free
minutes. But you can use Gemini API free API uh for learning purposes and it's
API uh for learning purposes and it's not going to cost too much if you even
not going to cost too much if you even pay. I think it's going to cost maybe
pay. I think it's going to cost maybe $1, $2 uh for for your entire week of
$1, $2 uh for for your entire week of learning process. Okay,
let me see. Paste documents signing into with a different device. Okay.
with a different device. Okay. Paste documents to sell documents. I
Paste documents to sell documents. I didn't get this. Oh, this one. Sure,
didn't get this. Oh, this one. Sure, sure, sure. I will post it.
sure, sure. I will post it. Edwards, I got I understood your
Edwards, I got I understood your question. Okay.
question. Okay. Should we use the updated model due to
Should we use the updated model due to deprecation warning? Uh yeah, you can
deprecation warning? Uh yeah, you can but I I'm not worried about it now. So
but I I'm not worried about it now. So you can always go back and then update
you can always go back and then update your code. Uh that is polishing your
your code. Uh that is polishing your code for now. I'm okay with this one.
code for now. I'm okay with this one. It's it's working. I checked this one
It's it's working. I checked this one before the I checked each one of these
before the I checked each one of these things before the workshop. It's
things before the workshop. It's working. Okay. So we got the embedding.
working. Okay. So we got the embedding. Okay. We got the uh hugging face
Okay. We got the uh hugging face embeddings. I uh I have it here. So now
embeddings. I uh I have it here. So now now let's see what embedding means
now let's see what embedding means actually. Okay. So what I'm going to do
actually. Okay. So what I'm going to do is I'm just going to do a very simple
is I'm just going to do a very simple example. So I'm going to give some
example. So I'm going to give some sample text. Sample text.
sample text. Sample text. I'm sorry. Sample text.
I'm sorry. Sample text. These are the sample text. Return
These are the sample text. Return policy.
policy. Okay. Now we are getting into
Okay. Now we are getting into application, right? Refund policy.
application, right? Refund policy. something concrete and believe me it's
something concrete and believe me it's not going to take too much time for you
not going to take too much time for you to learn and
to learn and implement this locally. Now deploying it
implement this locally. Now deploying it as an application for business you need
as an application for business you need to you need to spend some more time on
to you need to spend some more time on that. Okay. So this is sample text. So
that. Okay. So this is sample text. So what I'm going to do now is now I
what I'm going to do now is now I already have embeddings right. So I'm
already have embeddings right. So I'm going to use embeddings. Okay. So this
going to use embeddings. Okay. So this instance again you can you can give any
instance again you can you can give any name here my embeddings your embeddings.
name here my embeddings your embeddings. I'm going to use embeddings. embedings
I'm going to use embeddings. embedings do embed documents
sample text. Okay. So, and then I'm going to assign this to let me sample
going to assign this to let me sample embeds. Okay. Let's see. Let me run
embeds. Okay. Let's see. Let me run this. And then uh sample text.
this. And then uh sample text. Okay. All right. It's it's very fast. I
Okay. All right. It's it's very fast. I got the embeddings. Now I'm just going
got the embeddings. Now I'm just going to show you uh the text length and
to show you uh the text length and embedding length. Okay. So let's write a
embedding length. Okay. So let's write a list comprehension for this one. For
list comprehension for this one. For text and sample text
text and sample text okay for text and sample text I'm just
okay for text and sample text I'm just going to have length of text. Okay. So
going to have length of text. Okay. So this is I'm just counting number of
this is I'm just counting number of characters. So this one is what is 5 6
characters. So this one is what is 5 6 11 right? I can see that. Okay, let me
11 right? I can see that. Okay, let me print this.
print this. This is the length of the text. So,
This is the length of the text. So, return policy is 13. Refund policy is
return policy is 13. Refund policy is 13. Leather forecast is 16. Okay. Now,
13. Leather forecast is 16. Okay. Now, I'm going to do the same thing for
I'm going to do the same thing for sample. Let me copy this.
sample. Let me copy this. Paste it here. So for I'm going to use
Paste it here. So for I'm going to use EMD embedding
EMD embedding in sample embeddings. And by the way,
in sample embeddings. And by the way, there is there's a typo here.
there is there's a typo here. Embeddings.
Embeddings. Okay.
Okay. Print the length of each embedding.
Print the length of each embedding. You got it right. So that's what I was
You got it right. So that's what I was trying to say. So the text no matter how
trying to say. So the text no matter how long. So now I'm going to return policy.
long. So now I'm going to return policy. You see the the length of the text is 13
You see the the length of the text is 13 13 16 but I'm using a standardized
13 16 but I'm using a standardized uh size of numbers representing these
uh size of numbers representing these text. So the first text is represented
text. So the first text is represented by 384 numbers. It's a vector of
by 384 numbers. It's a vector of numbers. The second one refund policy is
numbers. The second one refund policy is represented by 384. The third one is
represented by 384. The third one is represented by 384. Each of these are
represented by 384. Each of these are represented by a vector which is which
represented by a vector which is which has 384 numbers elements in it. So I can
has 384 numbers elements in it. So I can return policy for
return policy for purchased goods
purchased goods from our store. You see I made it even
from our store. You see I made it even longer. So let's see
longer. So let's see now I have 48 characters in the first
now I have 48 characters in the first text but still embeddings will remain
text but still embeddings will remain the so embedding changed. embedding for
the so embedding changed. embedding for the first text already changed but its
the first text already changed but its length is standardized it is so that's
length is standardized it is so that's the beauty no matter how long the
the beauty no matter how long the document is no matter how long the
document is no matter how long the document is I will always represent
document is I will always represent every document with the same length of
every document with the same length of vector in this case 384 so these vectors
vector in this case 384 so these vectors are not random numbers that's why it is
are not random numbers that's why it is beyond the scope of this workshop the
beyond the scope of this workshop the way we come up with these numbers is
way we come up with these numbers is also special so that for example one
also special so that for example one embedding ing if it is representing
embedding ing if it is representing let's say king.
let's say king. Okay. Another embedding is let's say
Okay. Another embedding is let's say representing queen. Okay. So queen not
representing queen. Okay. So queen not queen.
queen. Let's say these are two words king and
Let's say these are two words king and queen. I have embedding one for king.
queen. I have embedding one for king. Embedding one or king. Let's say I have
Embedding one or king. Let's say I have embedding two or queen. Let's say I also
embedding two or queen. Let's say I also have embedding three for men.
have embedding three for men. men and embedding for for woman. Okay.
men and embedding for for woman. Okay. So here is the nice thing about these
So here is the nice thing about these embeddings. The way they are generated
embeddings. The way they are generated is not random. Again this is uh an
is not random. Again this is uh an example which we need to check but more
example which we need to check but more or less this is what's going to happen.
or less this is what's going to happen. So what I can do is what I can do is
So what I can do is what I can do is I can take E3 men and then subtract
I can take E3 men and then subtract woman from men.
woman from men. Okay. E4. So this is giving me the
Okay. E4. So this is giving me the difference between men and woman. Okay.
difference between men and woman. Okay. And then when I add this to queen E2 you
And then when I add this to queen E2 you see queen and king woman and men I'm
see queen and king woman and men I'm taking difference between men and woman
taking difference between men and woman adding that to queen. So this is giving
adding that to queen. So this is giving going to give me a number which is very
going to give me a number which is very close to E1. You got it right? So what's
close to E1. You got it right? So what's happening here is these embeddings in
happening here is these embeddings in the space they are vectors
the space they are vectors are computed such that they are also
are computed such that they are also representing
representing the distance between the meanings of the
the distance between the meanings of the words and it's not just words it's
words and it's not just words it's meanings of bunch of words meanings of
meanings of bunch of words meanings of documents okay the the content of
documents okay the the content of documents so that's how I'm going to use
documents so that's how I'm going to use embeddings when I receive a question I'm
embeddings when I receive a question I'm going to find the closest answer to that
going to find the closest answer to that closest document to that question by
closest document to that question by comparing their embeddings. Okay, let me
comparing their embeddings. Okay, let me stop uh about embeddings. Okay, let me
stop uh about embeddings. Okay, let me continue with with the with the code.
continue with with the with the code. Okay,
Okay, [Music]
[Music] uh yeah and then I really so sorry. So
uh yeah and then I really so sorry. So yeah, you might receive these uh
yeah, you might receive these uh exceptions. Uh I I don't know what what
exceptions. Uh I I don't know what what is the cause of the error now. So uh
is the cause of the error now. So uh just follow the please follow the
just follow the please follow the workshop and then maybe you can try
workshop and then maybe you can try later on the yeah you can yeah I shared
later on the yeah you can yeah I shared the collab with you guys so you can you
the collab with you guys so you can you can check it okay let's finish this we
can check it okay let's finish this we don't have too much time how to know
don't have too much time how to know where to embed and give it number so
where to embed and give it number so that's John that's that's that's beyond
that's John that's that's that's beyond the scope of scope of this workshop okay
the scope of scope of this workshop okay how we can get these embeddings you can
how we can get these embeddings you can go back and then study a little bit on u
go back and then study a little bit on u how we create embeddings for for words.
how we create embeddings for for words. It's it's one of the first initial
It's it's one of the first initial topics when you learn NLP or large
topics when you learn NLP or large language models, right?
language models, right? Okay.
Okay. Now, let's let's really write the
Now, let's let's really write the application now. Okay. All right.
So this time I'm going to use as I said I I need to use a database lench chain
I I need to use a database lench chain vector stores
per stores I'm going to stop in 15 minutes okay
I'm going to stop in 15 minutes okay so base is uh what is that uh
so base is uh what is that uh a a database which is going to hold our
a a database which is going to hold our documents another uh
documents another uh um library we're going to use from lang
um library we're going to use from lang chain
chain lang chain
lang chain as schema actually for documents. So we
as schema actually for documents. So we are going to create documents in a
are going to create documents in a certain way and then we're going to use
certain way and then we're going to use this documents uh in our database. Okay.
this documents uh in our database. Okay. So let's
So let's this all right
this all right now remember our documents documents
now remember our documents documents remember the documents we created we
remember the documents we created we offer third rate return with receives so
offer third rate return with receives so we are still there okay we are still
we are still there okay we are still there so now I'm going to turn these
there so now I'm going to turn these documents to a specific format so for
documents to a specific format so for I'm going to use list comprehension for
I'm going to use list comprehension for documents in documents
okay So I'm going to take each document and turn it into a document format.
and turn it into a document format. Okay. So documents
page content. Basically this is creating this document is just a string. It is
this document is just a string. It is going to put that string into a document
going to put that string into a document template. Okay. So there is a metadata
template. Okay. So there is a metadata defining how a document is going to look
defining how a document is going to look like. Okay. we are we are actually
like. Okay. we are we are actually creating a document filling a document
creating a document filling a document template where we're going to use it to
template where we're going to use it to push it into our uh our database. So our
push it into our uh our database. So our database is expecting documents in a
database is expecting documents in a certain format. That's what we are doing
certain format. That's what we are doing here
here documents.
documents. So I'm getting each and every document
So I'm getting each and every document from my document list and turning it
from my document list and turning it into a document format and then I'm
into a document format and then I'm going to assign this list of documents
going to assign this list of documents to this variable. Let me print documents
to this variable. Let me print documents on the screen. See how they look like
on the screen. See how they look like you see? So I just changed I didn't
you see? So I just changed I didn't change too much, right? So I just took
change too much, right? So I just took this string but now I have a specific
this string but now I have a specific format. So document metadata is empty.
format. So document metadata is empty. Again this is a very basic uh what we
Again this is a very basic uh what we are doing is very basic and this is the
are doing is very basic and this is the content of the document. So you can you
content of the document. So you can you can also define the metadata for the
can also define the metadata for the document. So we are not there yet. All
document. So we are not there yet. All right. So now now this is a format which
right. So now now this is a format which our database is going to accept. Okay.
our database is going to accept. Okay. Now I'm going to take my database
Now I'm going to take my database and then it's going to take from these
and then it's going to take from these documents.
documents. Okay.
Okay. All right. And then documents,
All right. And then documents, comma. But before these documents, I
comma. But before these documents, I need to create the what is that the I
need to create the what is that the I need to also give the embeddings. This
need to also give the embeddings. This one what is embeddings? You see
one what is embeddings? You see embeddings is the name of the
embeddings is the name of the this embeddings object. You remember
this embeddings object. You remember this hugging face embeddings. So this is
this hugging face embeddings. So this is this is think of it as a box. From one
this is think of it as a box. From one side you put your documents from the
side you put your documents from the other side you get the embedding for
other side you get the embedding for that document. So this embedding is that
that document. So this embedding is that box. So what we are doing is to our
box. So what we are doing is to our database we are giving the documents and
database we are giving the documents and the box.
the box. Okay. By the way I should be consistent
Okay. By the way I should be consistent with the name embeddings. Embeddings.
with the name embeddings. Embeddings. Yeah. Correct. Okay. So the the the
Yeah. Correct. Okay. So the the the database is going to take our documents
database is going to take our documents in a certain format. It's going to take
in a certain format. It's going to take the embeddings box which is going to
the embeddings box which is going to create embeddings for the documents.
create embeddings for the documents. It's going to push the documents through
It's going to push the documents through that box. It will get the embeddings and
that box. It will get the embeddings and then there it's going to store those
then there it's going to store those embeddings for those documents nicely.
embeddings for those documents nicely. Okay, that let's put it that way. So
Okay, that let's put it that way. So that later on we can have access to
that later on we can have access to these embeddings easily and that let's
these embeddings easily and that let's call this vector store.
Okay. Now let me run this. Okay. Now if uh you want to see uh how this is
uh you want to see uh how this is working first of all vector store let's
working first of all vector store let's see what what we're going to see it's
see what what we're going to see it's not going to give us anything it's just
not going to give us anything it's just saying that vector store is is an object
saying that vector store is is an object something that is stored at this address
something that is stored at this address okay so we're not seeing the content of
okay so we're not seeing the content of that database all right so but that that
that database all right so but that that database is created and it is somewhere
database is created and it is somewhere stored in the memory now let's test
stored in the memory now let's test this. Let's test this. For example, I'm
this. Let's test this. For example, I'm going to run a query. Test query.
going to run a query. Test query. Okay. And refund
Okay. And refund policy.
policy. Remember, one of the documents is one of
Remember, one of the documents is one of the documents is uh what is that? We
the documents is uh what is that? We offer 30-day returns with receipts.
offer 30-day returns with receipts. So, this is the question refund policy.
So, this is the question refund policy. What is your refund policy? Now, here is
What is your refund policy? Now, here is how it's going to work. I'm going to
how it's going to work. I'm going to take my
take my database. Remember our database already
database. Remember our database already has this box embeddings. Okay. So, I'm
has this box embeddings. Okay. So, I'm going to take and then I'm going to ask
going to take and then I'm going to ask my database, can you search
my database, can you search for similar
search? Can you f search in your database? Can you search in your records
database? Can you search in your records for similar things to this test query
for similar things to this test query refund policy? Okay, let me put this
refund policy? Okay, let me put this inside test
inside test query. So what this vector store is
query. So what this vector store is going to do is it's going to take in
going to do is it's going to take in this refund policy query. It's going to
this refund policy query. It's going to push that query through this embeddings
push that query through this embeddings box and it will receive the embeddings
box and it will receive the embeddings for this query refund policy. It will
for this query refund policy. It will find the embeddings value embeddings
find the embeddings value embeddings vector for refund policy and then it's
vector for refund policy and then it's going to compare that embedding with all
going to compare that embedding with all the embeddings in the record. Okay. So,
the embeddings in the record. Okay. So, how many embeddings we have? 1 2 3 4.
how many embeddings we have? 1 2 3 4. There are four embeddings in the
There are four embeddings in the database. It's going to find the
database. It's going to find the embedding for refund policy. It'll
embedding for refund policy. It'll compare. It'll find the most similar
compare. It'll find the most similar here. We're going to say, "Give me the
here. We're going to say, "Give me the most similar one document." If I say two
most similar one document." If I say two document, it's going to give me the most
document, it's going to give me the most similar two documents in order. I'm
similar two documents in order. I'm going to say the give me the most
going to say the give me the most similar document to this embedding.
similar document to this embedding. Let's see what it's going to return.
Let's see what it's going to return. Okay. So, let me run this.
Okay. So, let me run this. You see? So it already returned the ID
You see? So it already returned the ID of that document,
of that document, its metadata and its page content. Okay.
its metadata and its page content. Okay. So let's make this let's let's make this
So let's make this let's let's make this more uh put in a more nice nicer format.
more uh put in a more nice nicer format. So I'm going to say this is my relevant.
So I'm going to say this is my relevant. You got the you got you got what's
You got the you got you got what's happening here, right? Relevant relevant
happening here, right? Relevant relevant documents. Okay. So you you got the rest
documents. Okay. So you you got the rest of I asked refund policy. It easily
of I asked refund policy. It easily found the most relevant document to this
found the most relevant document to this question. I didn't search for words.
question. I didn't search for words. Remember that was our if as rulebased
Remember that was our if as rulebased system. We would break down the
system. We would break down the queries and the documents into words and
queries and the documents into words and then find the word frequency map
then find the word frequency map matchings. We didn't do any of that. We
matchings. We didn't do any of that. We turned everything into a a set length of
turned everything into a a set length of vector 384 long vector and then we just
vector 384 long vector and then we just compared those vectors and then found
compared those vectors and then found the closest vector to refund policy
the closest vector to refund policy vector. That's what we did. So let's
vector. That's what we did. So let's make this a little bit nicer. So I'm
make this a little bit nicer. So I'm going to print
going to print uh uh print.
[Music] Yeah, you guys must be tired now. So I'm
Yeah, you guys must be tired now. So I'm I will get the first element and then
I will get the first element and then from that I'm going to get page
from that I'm going to get page contents. So this is a list. As you see
contents. So this is a list. As you see this is a list. This is a list. So there
this is a list. This is a list. So there is only one element here because I asked
is only one element here because I asked only the closest one document. I'm
only the closest one document. I'm taking the first document in that list
taking the first document in that list and the first documents page content.
and the first documents page content. Okay. Page content.
Okay. Page content. Okay.
What happens? page content relevant documents
relevant documents zero
zero and then
and then page content
page content relevant.
Oh, I need to put F in here. Sorry. Yeah. So, we offer 30-day returns with
Yeah. So, we offer 30-day returns with receipts. Perfect. So we got the most
receipts. Perfect. So we got the most relevant document uh to our now let us
relevant document uh to our now let us create our what is that u agent AI
create our what is that u agent AI agent. So this time so what we going to
agent. So this time so what we going to do is now we understood that we can
do is now we understood that we can have a list of documents that is only
have a list of documents that is only known to us for our own organization.
known to us for our own organization. LLM doesn't know those documents. LLM
LLM doesn't know those documents. LLM has a generic idea about the world.
has a generic idea about the world. Okay, but we want to
Okay, but we want to create prompts
create prompts for large language model that is going
for large language model that is going to be about our own company uh
to be about our own company uh documents. Okay. And then we want to
documents. Okay. And then we want to when we receive a question, we want to
when we receive a question, we want to find the most relevant document from our
find the most relevant document from our database. And then we're going to put
database. And then we're going to put this question and document together, put
this question and document together, put into a prompt, send it to LLM and ask
into a prompt, send it to LLM and ask LLM to give a nice answer using these
LLM to give a nice answer using these two documents. That's what we're going
two documents. That's what we're going to do now. And then I'll finish with
to do now. And then I'll finish with that. I have one more uh application,
that. I have one more uh application, but I think we are out of time. So, and
but I think we are out of time. So, and then I see that you guys also are
then I see that you guys also are getting tired. Relevance of K plus what
getting tired. Relevance of K plus what is K= 1 referring to? So, if I make this
is K= 1 referring to? So, if I make this K= 2, I'm finding from this you have I
K= 2, I'm finding from this you have I have four documents. when k equals 1 I'm
have four documents. when k equals 1 I'm finding the out of these four documents
finding the out of these four documents I'm finding one document which is the
I'm finding one document which is the most which is the closest in terms of
most which is the closest in terms of relevance to refund policy string if I
relevance to refund policy string if I make this two then I'm going to have uh
make this two then I'm going to have uh so let me
Actually, let me let me print here. Relevant
Relevant documents.
documents. Let's not change this one. Okay, let run
Let's not change this one. Okay, let run this. Let run this relevant document.
this. Let run this relevant document. Now you see I have two documents because
Now you see I have two documents because I changed this. So these are the two
I changed this. So these are the two documents that are in terms of relevance
documents that are in terms of relevance closest to this qu question query.
closest to this qu question query. refund policy. Okay, that's what it
refund policy. Okay, that's what it means. Highest similarity, shortest
means. Highest similarity, shortest vector path. Yes, the shortest. We are
vector path. Yes, the shortest. We are just measuring the distance between two
just measuring the distance between two vectors actually here. It's got to be
vectors actually here. It's got to be cosine similarity. Adam, uh more
cosine similarity. Adam, uh more technically it's a it's a cosine
technically it's a it's a cosine similarity. We are looking at the angle
similarity. We are looking at the angle between two vectors. So if two vectors
between two vectors. So if two vectors are closer to each other, cosine of that
are closer to each other, cosine of that angle will be the smallest.
angle will be the smallest. You're welcome.
You're welcome. Not tired. Okay. Why? So wow. All right.
Not tired. Okay. Why? So wow. All right. So let's let's finish this guys. Let's
So let's let's finish this guys. Let's finish this one. Now let's uh create our
finish this one. Now let's uh create our uh new application. All right. Okay.
uh new application. All right. Okay. Let's see. So let's write this as a as a
Let's see. So let's write this as a as a function together. Uh so this is the R A
function together. Uh so this is the R A rag. So Dr. Jam, maybe before you start,
rag. So Dr. Jam, maybe before you start, I make the last announcement. Oh, sure.
I make the last announcement. Oh, sure. Please go ahead. Okay. Sorry. Just give
Please go ahead. Okay. Sorry. Just give me time. So I hope you guys enjoying I
me time. So I hope you guys enjoying I see that participants level is almost
see that participants level is almost 98% from starting it means that people
98% from starting it means that people really enjoy we are over 100 people
really enjoy we are over 100 people here. So uh if you want to continue and
here. So uh if you want to continue and excel in LLMs which most jobs are really
excel in LLMs which most jobs are really looking that skill set LLMs and AI
looking that skill set LLMs and AI agents through that six weeks program we
agents through that six weeks program we mentioned in the beginning we have
mentioned in the beginning we have actually a early bird discount till end
actually a early bird discount till end of the month in couple days two days and
of the month in couple days two days and it is $500 original price $800.
it is $500 original price $800. recommend not to mess it. Not on early
recommend not to mess it. Not on early bird discount, we have a limited space.
bird discount, we have a limited space. We may close the uh uh we may close the
We may close the uh uh we may close the registrations in after maybe two or
registrations in after maybe two or three days. Uh just encourage to
three days. Uh just encourage to register if you want to get more in
register if you want to get more in depth and you will be also joining
depth and you will be also joining Magniman alumni where we also offer
Magniman alumni where we also offer special uh classes to just alumni only.
special uh classes to just alumni only. So thank you Dr. Jang. So you continue.
So thank you Dr. Jang. So you continue. Thank you. I just want to add my my
Thank you. I just want to add my my colleague uh Sei is an MIT graduate.
colleague uh Sei is an MIT graduate. He's really good what at what he's
He's really good what at what he's doing. He's actually working in the
doing. He's actually working in the Silicon Valley. Uh he he's he's an
Silicon Valley. Uh he he's he's an expert on this. So he will be giving
expert on this. So he will be giving half of that workshop and then I'll give
half of that workshop and then I'll give the other half. So just for information.
the other half. So just for information. Okay. So let's continue. Let's now write
Okay. So let's continue. Let's now write the function which is going to be our
the function which is going to be our application. I'm going to call this ask.
application. I'm going to call this ask. I'm sorry here.
I'm sorry here. ask rag. So this time I'm going to
ask rag. So this time I'm going to create an application which is going to
create an application which is going to receive a question okay from outside and
receive a question okay from outside and then uh exactly we are going to look for
then uh exactly we are going to look for the most relevant document to that
the most relevant document to that question and then we're going to send
question and then we're going to send question and that most relevant document
question and that most relevant document to our LLM and then we are going to get
to our LLM and then we are going to get the response to that. So let's see how
the response to that. So let's see how it's going to work. Let's see how it's
it's going to work. Let's see how it's going to work. Okay, first uh so we are
going to work. Okay, first uh so we are going to find the relevant documents. So
going to find the relevant documents. So relevance
relevance document.
document. So we already document I'm sorry
So we already document I'm sorry document we already have our vector
document we already have our vector space here. Vector store. I'm going to
space here. Vector store. I'm going to use the same vector store. Otherwise we
use the same vector store. Otherwise we should have put this inside the
should have put this inside the function. I'm not doing that. So and
function. I'm not doing that. So and then I am searching for similarity
then I am searching for similarity search. Okay. And then uh I will say I'm
search. Okay. And then uh I will say I'm looking for similarity search for this
looking for similarity search for this question. Let's set K to two this time.
question. Let's set K to two this time. Okay. So earlier it was one. Now I'm
Okay. So earlier it was one. Now I'm looking for the most relevant two
looking for the most relevant two documents to this question. Okay. So let
documents to this question. Okay. So let now
now next what I'm going to do is sorry next
next what I'm going to do is sorry next if you like you can print those
if you like you can print those documents on screen if you like just to
documents on screen if you like just to if you want to see how they look like
if you want to see how they look like but let's not do it. We already did that
but let's not do it. We already did that part. Uh printing the content of the
part. Uh printing the content of the documents. We already did that. Now I'm
documents. We already did that. Now I'm going to put these documents, join them
going to put these documents, join them together and then create one context
together and then create one context from that. Okay. So for that I'm going
from that. Okay. So for that I'm going to first create a uh use what is that uh
to first create a uh use what is that uh uh list comprehension for documents in
uh list comprehension for documents in relevant document.
relevant document. Okay, I'm going to put these documents
Okay, I'm going to put these documents together. So for that uh I will get the
together. So for that uh I will get the first I will get the page content of
first I will get the page content of each document. I'm sorry page content.
each document. I'm sorry page content. You know what this page content does
You know what this page content does right here. Page content it's just from
right here. Page content it's just from this document. So this is the document.
this document. So this is the document. Okay let's say this is the document the
Okay let's say this is the document the most relevant document. I'm only taking
most relevant document. I'm only taking the page content part of that document.
the page content part of that document. This 30-day we offer we offer 30-day
This 30-day we offer we offer 30-day return with receipt. I just take that
return with receipt. I just take that part. Let's say I have two documents. I
part. Let's say I have two documents. I take that part of these two documents
take that part of these two documents and create a list of that. Okay. So
and create a list of that. Okay. So actually let me write let me run this
actually let me write let me run this here
here for you this one. So let me first print
for you this one. So let me first print this. I just want you guys see what I'm
this. I just want you guys see what I'm doing inside the function.
doing inside the function. This one
This one that's exactly what the look look this
that's exactly what the look look this is the this is the two documents. The
is the this is the two documents. The first list is the two documents. Second
first list is the two documents. Second is only the list of the document content
is only the list of the document content of those two documents. this one. This
of those two documents. this one. This one, the second, that's what we did
one, the second, that's what we did here. Now, next what I'm going to do is
here. Now, next what I'm going to do is I'm going to join them. So, let's let's
I'm going to join them. So, let's let's see how it's going to work. So, I will
see how it's going to work. So, I will join them uh uh
join them uh uh like I I I'll put first document content
like I I I'll put first document content and I'll put the second one right below
and I'll put the second one right below that one. For that, you know, you know
that one. For that, you know, you know the join uh function, right? So what I'm
the join uh function, right? So what I'm going to do is first I will write a
going to do is first I will write a string that string is slashn / slashn is
string that string is slashn / slashn is going to go to the next line. Right? So
going to go to the next line. Right? So I will join these two documents using
I will join these two documents using slashn. That's what I'm doing. That
slashn. That's what I'm doing. That means in between these two documents I
means in between these two documents I will put slashn. So let let's show what
will put slashn. So let let's show what what
what I do. I need this one. Okay here you see
I do. I need this one. Okay here you see this I put in between two documents I
this I put in between two documents I put this slashn. Basically first I'm
put this slashn. Basically first I'm just telling
just telling that this this is the first document
that this this is the first document content and this is the second document
content and this is the second document content. I'm just creating the context
content. I'm just creating the context for that. So let's do this
slashn dot join. Perfect.
dot join. Perfect. We don't know to do this. We don't need
We don't know to do this. We don't need to do this but it's going to be easier
to do this but it's going to be easier if we join all the documents and then
if we join all the documents and then call it a context. Okay. Now let's
call it a context. Okay. Now let's create our prompt. We are experts of
create our prompt. We are experts of creating prompt, right? We already did
creating prompt, right? We already did that earlier. I'm going to we're going
that earlier. I'm going to we're going to follow the same steps. So this is my
to follow the same steps. So this is my prompt template. We know how to create a
prompt template. We know how to create a template. Now
in between this I'm going to write my template. Okay. So based on this company
template. Okay. So based on this company information
information okay so I'm now this is my instructions
okay so I'm now this is my instructions to LLM take this context
to LLM take this context now this context is coming from here
now this context is coming from here right that is the input to our prompt
right that is the input to our prompt and then take this question
okay take this question and then this is my instruction ction. Please, please
my instruction ction. Please, please provide
provide a helpful
a helpful answer
answer based on the company information
based on the company information provided.
provided. Okay. And then answer. You see this is
Okay. And then answer. You see this is my template. Perfect. Next.
Now this template is going to receive context from here question as the
context from here question as the function parameter. Okay. All right. All
function parameter. Okay. All right. All right. Now I'm going to get the
right. Now I'm going to get the response. Response
response. Response sorry
sorry response is llm.invoke.
response is llm.invoke. Here if you like you can create a chain
Here if you like you can create a chain too. Remember we created a chain. Now
too. Remember we created a chain. Now let's keep things simple for now. Let's
let's keep things simple for now. Let's see what is the response. Okay. And then
see what is the response. Okay. And then I'll get the front rag.
I'll get the front rag. Nothing stops us create from creating a
Nothing stops us create from creating a chain here. I just don't do it here for
chain here. I just don't do it here for now. And then return
now. And then return response. That's it. So I just created a
response. That's it. So I just created a very simple rag application. Okay. So
very simple rag application. Okay. So let's test it. Question.
let's test it. Question. This is what the person is going to ask.
This is what the person is going to ask. What is
What is your
your return policy?
return policy? Okay, now let's get the response answer.
Okay, now let's get the response answer. I will ask my
I will ask my AI agent. Hey, give me the answer for
AI agent. Hey, give me the answer for this question. Now, let's print this
this question. Now, let's print this answer.
answer. Okay, let's see if this is going to
Okay, let's see if this is going to work, guys. If it works, we are fine.
work, guys. If it works, we are fine. Okay, let's see. And most of the time it
Okay, let's see. And most of the time it doesn't work the first try. Oh, it it
doesn't work the first try. Oh, it it did. You see it says we offer 30 returns
did. You see it says we offer 30 returns with a receipt. So it is we offer 30
with a receipt. So it is we offer 30 returns with receipts. It just added a
returns with receipts. It just added a receipt. So that's it was a very uh so
receipt. So that's it was a very uh so we can add please provide helpful answer
we can add please provide helpful answer provided uh please.
like that. And then first
first greet the customer.
greet the customer. Say a few nice words. Okay.
Hello there. We're happy to help you with your question. Our return policy is
with your question. Our return policy is quite straightforward. We offer 30
quite straightforward. We offer 30 returns for items when accompanied by
returns for items when accompanied by receipt. We also accept all major credit
receipt. We also accept all major credit for a convenience. Perfect. Right.
for a convenience. Perfect. Right. Perfect. So uh just imagine that these
Perfect. So uh just imagine that these uh these documents are not just simple
uh these documents are not just simple list of sentences. You can have actual
list of sentences. You can have actual documents really long documents, right?
documents really long documents, right? And each of these documents are going to
And each of these documents are going to be squeezed into a fixed length of
be squeezed into a fixed length of vectors and then they will be stored in
vectors and then they will be stored in a database which is going to allow you
a database which is going to allow you to search for them very quickly. And
to search for them very quickly. And then you can turn any question into a
then you can turn any question into a vector and you can find the most similar
vector and you can find the most similar vectors from your vector space and then
vectors from your vector space and then you can send those documents with the
you can send those documents with the question to your LLM and then LLM is
question to your LLM and then LLM is going to get back to you based on your
going to get back to you based on your instructions and and we also learned how
instructions and and we also learned how to create a prompt uh a template for a
to create a prompt uh a template for a prompt. I think this was very useful. So
prompt. I think this was very useful. So I had one more application that I was
I had one more application that I was planning to share with you today. But I
planning to share with you today. But I think I think we did we did good today.
think I think we did we did good today. Uh maybe next time. All right. Thank you
Uh maybe next time. All right. Thank you so much for listening. Uh our time is up
so much for listening. Uh our time is up and u hope to see you guys in another
and u hope to see you guys in another workshop. All right. So I shared the
workshop. All right. So I shared the document with you. I will close API
document with you. I will close API right away. So that means you need to
right away. So that means you need to come up with your own API to make the
come up with your own API to make the code work. Otherwise you're going to
code work. Otherwise you're going to receive that the API key is is no longer
receive that the API key is is no longer valid. you're going to receive that that
valid. you're going to receive that that kind of a response. Okay, thank you and
kind of a response. Okay, thank you and take care. Uh see you next time.
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.