Complete Langchain Course For Generative AI In 3 Hours — Transcript
Full transcript
- 0:00hello all my name is krishak and welcome
- 0:02to my YouTube channel so guys here is
- 0:04one amazing one short video on Lang
- 0:06chain in order to learn generative AI so
- 0:09if you are interested in creating
- 0:10amazing llm application or gen AI power
- 0:13uh application then this specific video
- 0:16is definitely for you if you don't know
- 0:18about Lang chain it is a complete
- 0:19framework that will actually help you to
- 0:21create Q&A chatbots rag application and
- 0:24many more the most interesting thing
- 0:26will be that I will be covering all the
- 0:28paid llm models along with that open llm
- 0:30models even though that they are hosted
- 0:32in hunging face so we will be getting to
- 0:34know each and everything about it and
- 0:36how we can specifically use in Lang
- 0:37chain so I hope you enjoy this
- 0:39particular video and please make sure
- 0:41that you watch this video till the end
- 0:43so thank you let's go ahead and enjoy
- 0:45the series uh before I go ahead guys uh
- 0:48since uh you know there's some there
- 0:50should be some motivation for me also so
- 0:52I will keep the light Target to th000
- 0:55please make sure that you hit like share
- 0:57with all your friends and we'll also
- 0:59keep a target of comments okay 200
- 1:01comments I know you will be able to do
- 1:03it so let's keep that specific Target
- 1:05and let's understand what all things we
- 1:07are going to learn uh about Lang chain
- 1:10and then we'll also understand the
- 1:12second topic that we are going to
- 1:13understand in this specific video is
- 1:15about the Lang chain ecosystem and how
- 1:17it is related to each other now uh right
- 1:20now in the langin documentation if you
- 1:22probably see the recent updates that are
- 1:25there mainly uh most of the modules
- 1:28revolve around this particular topics in
- 1:30Lang chain okay so over here you'll be
- 1:32able to see lsmith uh here you'll be
- 1:34able to see Langer if I talk about
- 1:37lsmith recently I had also made a video
- 1:39on this uh just a simple video but I
- 1:41will try to create more videos on that
- 1:43when we go in this specific Series so
- 1:45lsmith is if I probably give you some
- 1:47examples it is it'll help you to monitor
- 1:50your application it'll help you to debug
- 1:53your application so in short whatever
- 1:56mlops activities is specifically
- 1:58required with respect to mon in
- 2:00deploying sorry debugging testing you
- 2:02know so third point I will say testing
- 2:04you can specifically use this amazing
- 2:06module in Lang langin that is called as
- 2:08lsmith the best thing will be that all
- 2:11the reports all the analytics you'll be
- 2:13able to see very much easily in this
- 2:16ecosystem itself in the langin ecosystem
- 2:18so there is a dashboard in langin which
- 2:19you'll be able to see it okay now how we
- 2:22going to use in this use this entire
- 2:24technique in some projects we'll be
- 2:26seeing completely end to end and we'll
- 2:28also be able to understand this so if I
- 2:31talk about lsmith it is mostly of U if I
- 2:34say llm Ops okay so this part that is
- 2:38right now required uh in many many
- 2:40companies so that part we'll also be
- 2:42able to cover it that is the reason why
- 2:44I like langen because it is providing
- 2:45you the entire ecosystem irrespective of
- 2:48any llm model okay any llm model now
- 2:51coming to the second thing over here you
- 2:52have Langer let's say that you have
- 2:54created your llm application you
- 2:57obviously want your entire llm
- 2:59application in the the form of apis
- 3:01right without writing much code yes you
- 3:03can write the code from scratch with the
- 3:05help of flask or some other some other
- 3:07libraries but here Lang uses something
- 3:10called as fast API okay and because of
- 3:13this fast API you know creation of this
- 3:16particular apis becomes very much easy
- 3:19so we'll be also able to understand it
- 3:21before the deployment if I have actually
- 3:23created my own llm app how I can
- 3:26actually create all the services in the
- 3:28form of apis that we'll try to see with
- 3:30respect to the Langer now coming to the
- 3:33next thing there are some amazing
- 3:35Concepts and important Concepts in Lang
- 3:36chain from data inje to data
- 3:38transformation and all in that major
- 3:41major topics are with respect to chains
- 3:43we'll try to understand about chains and
- 3:45probably in the next video once I
- 3:46probably start the Practical
- 3:47implementation the first thing that I'm
- 3:49actually going to cover is with respect
- 3:50to chains and I'm also going to discuss
- 3:54something called as agents and retrieval
- 3:56right not only that U you'll be able to
- 3:58see there is a concept of LC okay now in
- 4:01this LC we will be discussing and this
- 4:04full form is Lang chain expression
- 4:06language right so there are lot of
- 4:08Concepts that are specifically used in
- 4:10LC we'll also see that how it is
- 4:12basically important while you are
- 4:14building what are techniques it actually
- 4:16has when you're creating your own
- 4:18generative AI power application right
- 4:20along with that uh there are three main
- 4:22topics also which I will be able to
- 4:24cover it while I will be discussing all
- 4:26these things that is about model iio
- 4:28retriever agent tooling and all uh these
- 4:30are Concepts that you should really know
- 4:32uh the main aim of this entire series is
- 4:35not to make you understanding
- 4:36theoretical concept but uh it's more to
- 4:39understand how you can create amazing
- 4:41generative AI applications irrespective
- 4:43of any llm model now see guys one of the
- 4:46question that I get from many people hey
- 4:47Kish uh I'm using this specific llm
- 4:50model I don't have openi access I don't
- 4:52have API access tell me what should I do
- 4:54you know uh let's say many people say
- 4:57that hey Krish I don't have credit card
- 4:58for open AI
- 5:00right can you show me some examples with
- 5:02respect to open source models like
- 5:05Google gini or some other mrr what about
- 5:08open source models right see llm over
- 5:10here as I said Lang chin is an amazing
- 5:12framework to build the entire
- 5:13application and creating the best llm is
- 5:17already a rat race so if I probably say
- 5:19this is a rat race by Tech Giants right
- 5:22so Google will be competing meta will be
- 5:24competing um uh you know anthropic will
- 5:27be competing um openi will be comp
- 5:29rating so you don't even have to worry
- 5:31about this right whatever models will be
- 5:33probably coming up in the future don't
- 5:35worry about this the main thing is that
- 5:37how you can use this llm app in a
- 5:39generic way to build any kind of
- 5:41application so here whatever model it
- 5:43may come you just need to stay up to
- 5:45date right which model has the best
- 5:47accuracy and all that will basically
- 5:49happen over here right later on all the
- 5:51integration part will be completely
- 5:53generic okay now let's go ahead and
- 5:56understand the entire Lang chain
- 5:58ecosystem like what are are the very
- 6:00important things so this is a diagram
- 6:01that I have already taken from the Lang
- 6:03chin so as I already discussed with
- 6:05respect to lsmith the first model that
- 6:07you see over here we basically say it as
- 6:09observ observability right and with the
- 6:12help of lsmith you will be able to do
- 6:14debugging playground evaluation
- 6:17annotation and monitoring when I say
- 6:19annotation it's all about creating your
- 6:21own custom data set which will require
- 6:24uh with respect to finetuning or
- 6:25creating your gen AI powered application
- 6:28the next thing is with respect to
- 6:29deployment and recently uh right now
- 6:31Lang Ser has actually come it'll be in
- 6:34the form of API so here it is written
- 6:36right chains as rest API whatever
- 6:38Services you are specifically providing
- 6:40Lang chain soon will also come up with
- 6:42only one click deployment mechanism once
- 6:44you probably create this entire apis
- 6:46with the help of langub the next thing
- 6:48is that you just need to deploy it okay
- 6:51then um and already I have created a
- 6:54couple of videos on Langs Smith and Lang
- 6:56langsa but don't worry uh in this entire
- 6:59series I'm going to again start from
- 7:00fresh combine new topics and create a
- 7:03project Okay the third thing that you
- 7:05really need to understand is about
- 7:07templates okay so there are different
- 7:09different templates reference the
- 7:11application uh with respect to Lang
- 7:14chain you need to understand these three
- 7:16important things chains agent and
- 7:18retrieval strategies so we'll try to
- 7:20understand that how these things work
- 7:21and understand guys you will be able to
- 7:23get the code with respect to Python and
- 7:24JavaScript but my main aim will be with
- 7:27respect to python because in some of the
- 7:28article it was already said that AGI
- 7:30application is going to get created in
- 7:32Python okay then you also have some
- 7:34integration components so we are
- 7:37understanding about the ecosystem
- 7:39because all these things we are going to
- 7:40discuss in this specific playlist itself
- 7:42so here you have model iio here you have
- 7:44retrieval here you have agenting tool so
- 7:47retrieval you also will be having
- 7:49features to read your data set from
- 7:51different different uh data sources how
- 7:54you can actually create vector edings
- 7:55and all and all are there right in model
- 7:57iio you have various techniques with
- 7:59respect to model chain prompt example
- 8:02selector and output parcel and finally
- 8:05you'll be also seeing that we'll be
- 8:06focusing on this amazing thing which is
- 8:08called as protocol which is basically
- 8:10coming under Lang chain core and here we
- 8:12are going to discuss about Lang chain
- 8:14expression language right so there are
- 8:17some important Concepts like
- 8:18paralyzation fallback tracing batching
- 8:20streaming a sync and composition so all
- 8:23these things we are basically going to
- 8:24cover and then we will be focusing on
- 8:27end to end projects how you can use all
- 8:31these Concepts together right understand
- 8:34one thing guys when we create L when we
- 8:36use Lang ser and start creating rest
- 8:38apis we'll also be writing our we'll
- 8:42also be writing our uh client side code
- 8:45so that we'll be able to access those
- 8:47kind of apis right so all these things
- 8:50in the form of ecosystem will get
- 8:52completely covered trust me again why
- 8:55I'm saying this is this is important
- 8:57because tomorrow whatever llm models may
- 9:00come right how advanced it may be Lang
- 9:03chain will be a generic framework which
- 9:05will actually help you to build any kind
- 9:07of llm application in this video I will
- 9:09be showing you how you can create
- 9:11chatbot applications with the help of
- 9:13both paid apis llm along with that we'll
- 9:16also see how you can integrate with open
- 9:18source llms now you should definitely
- 9:20know both the specific ways how you can
- 9:23actually do it one way to basically
- 9:26integrate any open source llm is through
- 9:28hugging face but as as you know that I'm
- 9:30focusing more on the Lang chain
- 9:32ecosystem and with respect to hugging
- 9:34face I've already uploaded a lot of
- 9:35videos in my YouTube channel and how you
- 9:37can actually call these kind of Open
- 9:39Source llms but since we are working
- 9:41with the langen ecosystem we will try to
- 9:43use all the components that are
- 9:45available in langen as you all know guys
- 9:47uh this is a fresh playlist and
- 9:49obviously my plan is that this month I
- 9:52will be focusing entirely on langin many
- 9:55more videos will be coming up many more
- 9:56amazing videos along with end to endend
- 9:59applic
- 10:00fine tuning many more things is going to
- 10:02come up so please make sure that we'll
- 10:04keep a like Target for every video and
- 10:06for this video the like Target is 1,000
- 10:08and at least 200 comments and please
- 10:10make sure that you watch this video till
- 10:12the end because it is going to be
- 10:14completely practical oriented okay and
- 10:17uh if you really want to support please
- 10:19make sure that you subscribe the channel
- 10:21and take up membership plan from my
- 10:22YouTube channel so that it will help me
- 10:25and with the help of those benefits I
- 10:27will be able to create more videos as
- 10:28such so let me quickly go ahead and
- 10:30share my screen so here is my screen
- 10:32over here and you'll be able to see in
- 10:35the GitHub that you'll be finding in the
- 10:37description of this particular video
- 10:38you'll be having folders like this so
- 10:40today is the third tutorial not third
- 10:43second tutorial uh in the first and
- 10:45second we just understood that what all
- 10:46things we are going to learn but in this
- 10:49is the real practical implementation
- 10:51that is probably there so as usual the
- 10:53first thing that we are going to do is
- 10:54that create our V andv environment how
- 10:57to create it cond create minus pvnv
- 11:00python is equal to 3.10 you can probably
- 11:02take 3.10 version and I have already
- 11:04shown you how to create virtual
- 11:06environments in many number of videos
- 11:08then you'll be using EnV file so this
- 11:10will basically be my environment
- 11:12variable um in this environment variable
- 11:14I will be putting three important
- 11:16information one is Lang chain API key uh
- 11:20the second one is open a API key and
- 11:22Lang chain project you might be thinking
- 11:24this open API key I've kept it as open
- 11:27no it is not I've changed some of the
- 11:29numbers over here so don't try it out
- 11:31it'll be of no use okay and then the
- 11:34third environment variable that I'm
- 11:36actually going to create is my Lang chin
- 11:38project name that is tutorial one I have
- 11:40written it over here the reason why I
- 11:43have written this because whenever I try
- 11:45to go ahead and see in my lsmith right I
- 11:48will be able to see observe the entire
- 11:50I'll be able to monitor each and every
- 11:52calls from the dashboard itself how we
- 11:54will be using this everything I will be
- 11:56discussing about it okay so all these
- 11:58things will spe specifically get
- 11:59required and uh all this will be used in
- 12:02our environment variable so these are
- 12:04the three parameters I have already
- 12:05created myv file so let's go ahead and
- 12:08start the coding okay and you have to
- 12:10make sure that you code along with me
- 12:12because this is the future AI
- 12:15engineering things are basically coming
- 12:16up I'll just show you initially with the
- 12:18foundation model later on this
- 12:20complexity will keep on increasing so
- 12:22let's go ahead and start our first code
- 12:25now what is our main aim what we are
- 12:28trying to do in our first project let me
- 12:30just discuss about because these are all
- 12:32the things that we going to discuss in
- 12:33the future but first thing that we will
- 12:36try to create is our normal chat GPT
- 12:38application okay I'll not say chat GPT
- 12:41but a normal chatbot okay and this
- 12:43chatbot will be important it will be
- 12:46helping you to probably create chatbot
- 12:48with the help of both paid and open open
- 12:51open source llm model so this will be
- 12:53the chatbot that we will be creating one
- 12:56way is that we will be using some paid l
- 12:59l m now paid llms one example I can show
- 13:02it with the help of open AI API okay
- 13:05open AI API the second one that I will
- 13:09try to probably show it uh or you can
- 13:11also use cloudy API so that is from a
- 13:15company called as anthropic okay that
- 13:18you can do and one more I will try to
- 13:19use it with the help of Open Source
- 13:22llm see calling apis is a very easy task
- 13:27okay but the major thing is that since
- 13:30we have so many modules we are going to
- 13:32use Lang chain as suggested right and in
- 13:35Lang chain we definitely have so many
- 13:37modules how we can use this modules for
- 13:40different different calls and along with
- 13:43this whenever we are developing any
- 13:45chatbot application what all
- 13:47dependencies we have specifically right
- 13:51dependencies now if you probably see
- 13:53this diagram here you'll be able to see
- 13:55there will be model prompt output parcel
- 13:58so in our video in this video I'm going
- 14:01to see some of the features with respect
- 14:02to lsmith I'm going to see some of the
- 14:05features with respect to chains and
- 14:06agents and I'm also going to use some of
- 14:09the feature present in model and output
- 14:11parcel so all this combination we going
- 14:13to specifically use and that is the
- 14:15reason how this is how I'm going to
- 14:17create the all the projects that we are
- 14:18doing entire videos that are probably
- 14:21going to come up will be much more
- 14:23practical oriented okay so now let's
- 14:25start our first chatbot application so
- 14:28here I will go ahead and write from Lang
- 14:31chin okay from
- 14:34linore open a since I'm going to use
- 14:36open a
- 14:38import chat open AI okay
- 14:43chat open a so this is the first one
- 14:47that we're going to basically do from
- 14:48Lang chain see this three things will
- 14:52definitely be required then one is chat
- 14:54openi or whatever open you whatever chat
- 14:57model that you're going to use how to
- 14:59call Open Source I will also be
- 15:00discussing about that first of all we'll
- 15:02start with opening API itself okay so
- 15:04from Lang chinor
- 15:06core. prompts I'm going to
- 15:10import chat prompt template okay chat
- 15:14prompt template so this is the next
- 15:15thing that we are probably going to use
- 15:17chat prompt template okay at any point
- 15:21of time whenever you create a chat bot
- 15:24right this chat prom template will be
- 15:26super important right here is what
- 15:27you'll you'll basically give the initial
- 15:30prompt template that is actually
- 15:31required Okay the third library that I'm
- 15:34actually going to import is from Lang
- 15:35chain uncore core dot output uncore
- 15:41parsers okay
- 15:43input H
- 15:46Str
- 15:48output parcel okay now this three are
- 15:53very important this string Str Str
- 15:55output processor is the default output
- 15:57processor whenever your llm model gives
- 15:59any kind of response you can also create
- 16:02a custom output parer that also I will
- 16:04be showing you in the upcoming videos
- 16:06okay this custom output parcel you can
- 16:09do anything with respect to the output
- 16:10that probably comes you want to do a
- 16:12split you want to make it as a capital
- 16:13letter anything right you can write your
- 16:15own custom code with respect to this but
- 16:17by default right now I'm going to use
- 16:19just St Str output parsel now along with
- 16:22this the next thing that I'm actually
- 16:23going to do is that I'm going to use
- 16:25streamlet as St okay stream streamlet as
- 16:29St then I'm going to also import OS and
- 16:33since I'm also going to use from
- 16:35EnV import load. EnV so that we'll be
- 16:41able to import all our libraries okay so
- 16:44let's see whether everything is working
- 16:46fine or
- 16:49not okay U from EnV so here I'm going to
- 16:53basically write
- 16:56python loore
- 16:59sorry python app.py I'm just running it
- 17:02so that everything works fine and all
- 17:04our libraries will also get ined
- 17:06cannot python app.py okay I have to
- 17:09probably go to my chatbot folder CD
- 17:12chatbot so now I'll clear my screen
- 17:15python
- 17:19appp oh
- 17:24sorry from streamlet as St okay import
- 17:28stream as H I have to write so that is
- 17:31the reason it was coming all this errors
- 17:33now let's see if everything is working
- 17:36fine Lang chain core so here you can
- 17:39probably see that there is a spelling
- 17:41mistake okay but I'm just going to keep
- 17:43all the errors like this so that you'll
- 17:46be able to see it python app.py if
- 17:49everything works fine uh output parser
- 17:52okay P Capital
- 17:55um so I think my suggestion box is not
- 17:59working well and that is the reason now
- 18:01everything is working fine uh here you
- 18:04can see that I'm not getting any error
- 18:05so let's start our coding and let's
- 18:07continue it okay so we have imported all
- 18:09these things right now now as I
- 18:11suggested guys since we are going to use
- 18:13three environment variables one is the
- 18:15open API key Lang chain API key and
- 18:17along with that I will also make sure
- 18:20that the tracing to capture all the
- 18:22monitoring results I will keep this
- 18:24three environment variable one is
- 18:25opening API key lch tracing verion to
- 18:29and langin API key so langin API key
- 18:32will actually help us to know that where
- 18:35the entire monitoring results needs to
- 18:37be stored right so that dashboard you'll
- 18:39be able to see all the monitoring
- 18:41results will be over here and tracing we
- 18:43have kept it as true so it is
- 18:45automatically going to do the tressing
- 18:46with respect to any code that I write
- 18:48and this is not just with respect to
- 18:50paid apis with open source llm also
- 18:52you'll be able to do it now this is the
- 18:54second step that I've actually done now
- 18:55let's go ahead and Define my promt
- 18:57template simple so here I'm going to
- 19:00write my prompt
- 19:02template okay promt template so here I'm
- 19:06going to Define prompt is equal to chat
- 19:09prompt template dot okay from uncore
- 19:14messages
- 19:16okay and here I'm going to Define my
- 19:18promt template in the form of list the
- 19:20first thing that with respect to my
- 19:23promp template that I'm going to give is
- 19:24nothing but system and system here I say
- 19:28that you you
- 19:29are
- 19:31a helpful
- 19:35assistant
- 19:36please
- 19:38respond to the queries okay please
- 19:43respond to the questions or queries
- 19:45please response to the user queries okay
- 19:49whatever queries that I'm going to
- 19:50specifically ask a simple prompt that
- 19:53you can probably see over here the next
- 19:55statement uh after this is what
- 20:01so this will be my next see if I'm
- 20:04giving a system prompt I also have to
- 20:05give a user prompt right user prompt
- 20:07will be whatever question I ask so this
- 20:10will be user and here I will define
- 20:12something like
- 20:13question colon question I can also give
- 20:17context if I want but right now I'll
- 20:19just give it as a question a simple
- 20:20chatbot application so that you'll be
- 20:23able to start your practice of creating
- 20:25all the chat bots so now I will go ahead
- 20:28and my streamlet framework okay see the
- 20:32learning process will be in such a way
- 20:34that I will try to create more projects
- 20:36and use functionalities that are there
- 20:38right and in this way you'll be able to
- 20:40work it in an amazing way okay so here
- 20:42I'm going to basically write st. title
- 20:44Lang chain demo with the opening API
- 20:47std. textor input search the text topic
- 20:50you want okay now let us go ahead and
- 20:53call my open AI llms okay open AI llm so
- 20:57here I'm going to be basically write llm
- 20:59and whenever we use openi API so it will
- 21:02be nothing but chat open Ai and here I'm
- 21:04going to give my model name the model
- 21:06name will be nothing but GPT GPT 3.5
- 21:11turbo so I'm going to use turbo because
- 21:13the cost is less for this i' I put $5 in
- 21:16my openingi account okay just to teach
- 21:18you so please make sure that you support
- 21:21so that I will be able to explore all
- 21:23these tools and create videos for all of
- 21:25you okay and finally my output parser
- 21:28see always remember Lang chain provides
- 21:31you features that you can attach in the
- 21:34form of chain right so here three main
- 21:36things we have created one is the chat
- 21:38prom template next one is the llm and
- 21:40next one is the output parcel obviously
- 21:43this is the first thing that we require
- 21:45after this we integrate with our llm and
- 21:47then finally we get our output so string
- 21:49output parser is responsible in getting
- 21:51the output itself finally chain is equal
- 21:54to we will just combine all these things
- 21:56so here I'm going to write prompt L LM
- 21:59and then finally my output parsel right
- 22:02I will show you going forward how we can
- 22:05customize this entire output parsel and
- 22:06all and finally if I write if input text
- 22:11if input undor text colon now whenever I
- 22:16write any input and probably press enter
- 22:19Then I should be able to get this output
- 22:21so std. WR and here I'm going to just
- 22:23write chain. invoke and finally I get
- 22:29I give my input as question and that
- 22:32input is assigned to my input text input
- 22:36text right so this is what we are going
- 22:38to basically do right st. write now this
- 22:42is what we are doing a simple chatbot
- 22:44application but along with this we have
- 22:47implemented this this this feature is
- 22:49specifically for Langs Smith Langs
- 22:52Smith
- 22:54Lang Smith tracking okay this will be
- 22:58amazing for to use okay and this is the
- 23:02recent updates that are there so
- 23:04whatever code I'm writing will be
- 23:05applicable going forward in various
- 23:08things that are probably going to come
- 23:09up okay now let's go ahead and run this
- 23:12so in order to run it you'll just need
- 23:16to write nothing but streamlet
- 23:20Run app.py Okay oops there is an error
- 23:26app.py and here I'll to allow access
- 23:29okay so right now you'll be able to see
- 23:31over here Lang chain series test llm but
- 23:34my my my project name was Project one
- 23:37okay so now if I go ahead and hit hey hi
- 23:40okay and just press enter you'll be able
- 23:43to see that we'll be getting this
- 23:45information over here and here you can
- 23:47see my project something let me reload
- 23:51it tutorial one right so this is the
- 23:53first request that is already been H and
- 23:56here you'll be able to see your enable
- 23:58sequest chat prom template right all the
- 24:00chat prom template output message your
- 24:03helpful assistance pleas response to the
- 24:04user queries right along with this you
- 24:07will be seeing chat open AI API and with
- 24:10respect to this what was the cost
- 24:11everything you are able to track so
- 24:14027 is the cost that actually took with
- 24:18respect to this and finally my string
- 24:19output parser how can you assist today
- 24:22with respect to this output parsel it is
- 24:23just going to give me the response
- 24:25clearly now when I develop my own custom
- 24:28output parel I'll be able to track
- 24:29everything so here what you are able to
- 24:31do you are able to monitor each and
- 24:33everything that is there right all the
- 24:35request that is probably coming up okay
- 24:37so provide me a python
- 24:40code a python code to swap two
- 24:45numbers okay so once I execute this and
- 24:48here you'll be able to see that I'm able
- 24:50to get the output and answer everything
- 24:52is over here and for this you'll be able
- 24:54to see the cost will be little bit High
- 24:56okay if you don't agree with me or let's
- 25:00see with respect to tutorial one the
- 25:01second request that I've actually got
- 25:034.80 seconds yes it took a little bit
- 25:06more time and here the cost was
- 25:090211 so it is based on the token size
- 25:12right for every token it is bearing some
- 25:14kind of cost perfect uh this was the
- 25:16first part of this particular tutorial
- 25:18now let's go to the second part uh the
- 25:20second part is more about making you
- 25:23understand that how you can call um open
- 25:26source llms in your local itself and how
- 25:29you can actually use it so for this
- 25:30first of all I will go ahead and
- 25:32download olama okay AMA is an amazing
- 25:35thing because you'll be able to run all
- 25:38the large language models locally uh the
- 25:41best thing about AMA is that it
- 25:42automatically does the compression and
- 25:44probably in your local you'll be able to
- 25:46run it let's say if you have 16 GB Ram
- 25:48you will just have to wait for some
- 25:50amount of time to get the response but
- 25:52Lama 2 and code Lama you can
- 25:54specifically use it over here all the
- 25:55open source llm model and it supports a
- 25:57lot of Open Source LM models and yes uh
- 26:00in Lang chain ecosystem the integration
- 26:02has also been provided over here so what
- 26:05I'm actually going to do over here is
- 26:06that I'll show you first of all just go
- 26:08ahead and download it this is available
- 26:10both in Mac Mac Linux and windows
- 26:12wherever you want just download it after
- 26:14you downloaded it what you really need
- 26:16to do is just go ahead and install it it
- 26:18is a simple exe file for Windows MSI
- 26:20file for Mac OS and then Linux is a
- 26:22different version so you just need to
- 26:24double click it and start installing it
- 26:26once you install it here uh somewhere in
- 26:28the bottom this AMA will be start
- 26:30running okay now once AMA installation
- 26:33is done now what I will do over here I
- 26:36will create another file inside my
- 26:39chatbot okay and create another file
- 26:44local
- 26:46llama okay local Lama py now local Lama
- 26:51py what we are going to basically do
- 26:53over here is that uh with respect to the
- 26:55local llama I will first first of all go
- 26:59ahead and import some of the library see
- 27:01code will be almost same right there
- 27:03also I'll be using chat open API chat
- 27:05prom template string output parser so
- 27:07I'll copy the same thing over here I'll
- 27:08paste it over here now along with this
- 27:10what I'm going to do I have to import
- 27:12olama right because that is the reason
- 27:14why we will be able to download all the
- 27:16specific models okay so Lang chain
- 27:18community. llm see over here whenever we
- 27:22need to do the third party integration
- 27:23so that will be available inside langin
- 27:25Community okay so AMA is third party
- 27:28cont configurations uh let's say you're
- 27:31using some Vector embeddings that is
- 27:32also third party so everything will be
- 27:34available over here okay now this is
- 27:36done langore community. LM import AMA
- 27:39and then we have this output parser
- 27:40string output parser core. prompts that
- 27:43is nothing but chart prom template and
- 27:45everything is there okay now let's go
- 27:47ahead and write import streamlet as St
- 27:51so I'm going to going to use the
- 27:53streamlet over here along with this
- 27:56import OS
- 27:58and not only that we will also go ahead
- 28:01and import from
- 28:04EnV
- 28:06import load
- 28:08uncore
- 28:09dot loore
- 28:13dob
- 28:14okay now we'll initialize it load
- 28:18underscore
- 28:20Dov okay once we initialize all this
- 28:22random all this uh environment variables
- 28:26as usual I will be importing this three
- 28:28things now see in my previous code when
- 28:31I was using open aipi promt template we
- 28:33have written it over here right same
- 28:34promt template we'll also write it over
- 28:36here because it we just need to repeat
- 28:38it because the main thing is that you
- 28:40really need to understand how with the
- 28:42help of AMA I can call any open source
- 28:43models okay so here it is and then
- 28:46finally you'll be able to see where is
- 28:49my uh code to call my open AI llms that
- 28:52we going to see over here so this is
- 28:55done now stream late framework also I
- 28:56will try to call it over here here okay
- 28:59it's more about copy paste the same
- 29:01thing that we have actually implemented
- 29:03and then you will also be seeing this is
- 29:06the code that we going to implement it
- 29:08okay but here we are calling chat open
- 29:11AI okay I specifically don't want chat
- 29:13open AI instead I will be calling AMA
- 29:16okay so AMA whatever Library we have
- 29:19imported so AMA okay and then here we
- 29:23are specifically going to call a Lama 2
- 29:26okay now before call any models now
- 29:29which all model are specifically
- 29:30supported if you go ahead and see in the
- 29:32GitHub right of AMA you'll be seeing the
- 29:34list of everything every every every
- 29:37libraries that it supports like Lama 2
- 29:38mral dolphin F 52 neural chat code Lama
- 29:42all are mostly open source GMA GMA is
- 29:44also there but before calling this what
- 29:46you really need to do is that just go to
- 29:48your command prompt let's say that I
- 29:49want to use GMA GMA model okay so what I
- 29:52have to do or I have to use llama model
- 29:54right so in order to do this I have to
- 29:57just write AMA run whatever model name
- 29:59because initially it needs to download
- 30:01it right uh this will get downloaded
- 30:03from some open source some GitHub it can
- 30:06be GitHub it can be hugging face
- 30:07somewhere right some location there will
- 30:09be there we have to download that entire
- 30:11model so let's say that I want to go
- 30:12ahead and write o run gamma so this what
- 30:15will happen it will pull the entire
- 30:17gamma model right wherever it is so here
- 30:19you can see pulling will basically
- 30:21happen now this is right now 5.2 GB
- 30:23right for the first instance you really
- 30:25need to do it now since I I I am writing
- 30:28the code with respect to Lama 2 I've
- 30:29already downloaded that model so that is
- 30:31the reason I'm showing you another
- 30:32example over here run gamma now once
- 30:35this entire downloading happens then
- 30:37only I'll be able to use the gamma model
- 30:39in my local with the help of AMA so I
- 30:42hope you have got an idea about
- 30:44it now what I'm actually going to do so
- 30:47here I've called AMA model Lama 2 okay
- 30:49then again output parser is this and I'm
- 30:51combining prompt llm on output parser
- 30:54and everything will be almost same and
- 30:55that is the most amazing thing about
- 30:57Lang
- 30:58the code will be only generic now only
- 31:00you need to replace open AI or paid or
- 31:02open source it is up to you again I'm
- 31:04saying you guys the system that I'm
- 31:06currently working in has a 64GB Ram uh
- 31:09it has Nvidia Titan RTX which was gifted
- 31:12by Nvidia itself so with respect to this
- 31:15uh amazing system I will be able to run
- 31:17very very much quickly that is what I
- 31:19feel so let's go ahead and run it so
- 31:22here what I'm actually going to do I'm
- 31:23going to write
- 31:25python uh so it is stream streamlet so
- 31:28streamlet
- 31:30run local Lama py so once I execute it
- 31:36here you'll be able to see now now
- 31:39instead of open a API I should had okay
- 31:41no module name Lang chain Community
- 31:43let's see where is Lang chain Community
- 31:45okay I have to also make sure that in my
- 31:48requirement. txt I go ahead and use this
- 31:53langin community and I need to import
- 31:56this Library since and need to do that
- 31:58and that is the reason I'm getting an
- 32:00error so if I go ahead and write pip
- 32:02install minus r requirement.
- 32:06txt
- 32:08oops
- 32:09CD dot dot okay now if I go ahead and
- 32:12write pip install minus r requirement.
- 32:16txt so here you'll be able to see my
- 32:19requirement. will get installed this Lin
- 32:21Community will get installed once I'm
- 32:23done with this then I can probably go
- 32:25ahead and run my code okay so this will
- 32:27take some amount of time so if you
- 32:29liking this video please make sure that
- 32:30you hit like uh there are many things
- 32:32that are probably going to come up and
- 32:34it'll be quite amazing when you learn
- 32:35all this things okay so uh once this is
- 32:38done then what will happen is that we
- 32:40can and you can use any model up to you
- 32:42okay and I don't want this open key also
- 32:46only this two information I specifically
- 32:48want I'll be able to track all these
- 32:50things okay and later on I'll also show
- 32:53you how you can create this in the form
- 32:54of apis again it'll some time it'll take
- 32:57this
- 32:58but uh let me know uh how do you think
- 33:00all these tutorials are blank chain I
- 33:03see a lot of purpose for this particular
- 33:06Library it's is quite amazing that
- 33:07people are doing um the company is doing
- 33:10amazingly well in this open source in
- 33:11world and it is developing multiple
- 33:13things over there so now I will go ahead
- 33:15and write CD chatbot I will go inside my
- 33:18chatbot and then I will run this python
- 33:21local Lama py once I execute this now I
- 33:25don't think it should be an error
- 33:28okay it should be streamlit come on
- 33:31streamlit run local llama oops local
- 33:35Lama py not python run streamate run now
- 33:39here you have again I'll be getting open
- 33:42AI text over here let me change this
- 33:44also so that I can make it
- 33:47perfect with Lama
- 33:512 okay so I've executed it saved it I
- 33:54will rerun it I'll say hey high so once
- 33:58I execute it you'll be seeing that it'll
- 34:00take some amount of time in my system
- 34:02even though I have a 64 GB Ram but I'll
- 34:04get the output over here so assistant
- 34:06says hello how can I help you today now
- 34:08if I probably go ahead with respect to
- 34:10this dashboard uh let's see where it is
- 34:14so now tutorial one you'll be able to
- 34:16see that this will increase okay there
- 34:18will be one more over here right so I've
- 34:21reloaded this
- 34:23page okay and you'll be able to see it
- 34:26okay you'll be able to see the new olama
- 34:28request see hey hi 4.89 second token 39
- 34:32but there is no charges because it is an
- 34:35open source model right so here you'll
- 34:37be able to see if I extend this there
- 34:40you'll be able to see chat PR template
- 34:41ama ama is over here now this AMA is
- 34:44specifically calling llama 2 over there
- 34:46and whatever open source libraries that
- 34:48you specifically want just to call this
- 34:50it is very much simple you have to just
- 34:52go into the GitHub and download any
- 34:54model first of all just by writing o
- 34:56Lama run that particular model name and
- 34:59once it is downloaded it is good that
- 35:00you can probably go ahead with and use
- 35:02it okay now I will say uh provide me a
- 35:06python
- 35:08code python code to swap two numbers
- 35:13okay if you want more coding well
- 35:16chatbot you can directly use code Lama
- 35:18if you want okay so here you can see all
- 35:20the examples are there and this was
- 35:22quite fast right so this is good you
- 35:24know so if you have the right kind of
- 35:26things so here you can see 4 seconds it
- 35:29has probably taken okay AMA is over here
- 35:32all the information is probably over
- 35:34here prompt and completion and all right
- 35:37hello guys so we are going to continue
- 35:39the langin series already in our
- 35:41previous video we have already seen how
- 35:43to create chat Bots with the help of
- 35:45both openai API and open source llm
- 35:47models like Lama 2 we have also seen
- 35:50what is the use of AMA how you can run
- 35:52all these open source model locally in
- 35:55your system and uh along with this this
- 35:57we also created multiple end to-end
- 35:59projects using both of them now what we
- 36:02are going to do in this specific video
- 36:04one more step which is very much
- 36:05important for our production G
- 36:07deployment that is creating apis you
- 36:10know for all this kind of llm uh models
- 36:13we will be able to create apis and uh
- 36:16through this you will also be able to do
- 36:18the deployment in a very efficient
- 36:19manner now how we are going to create
- 36:22this specific apis there is a very
- 36:23important component uh which is called
- 36:26as Lang serve in Lang chain we're going
- 36:28to use that along with this we are going
- 36:30to use fast API um and not only that
- 36:33we'll also create a sag Swagger UI which
- 36:36is already provided by Lang chin uh the
- 36:39Lang serve library that we are
- 36:40specifically going to use now it is
- 36:42important guys you know this specific
- 36:44step because tomorrow if you are also
- 36:47developing any application you obviously
- 36:49want to do the deployment for that
- 36:51particular application so creating uh
- 36:54the entire API for this application will
- 36:56be the first task that will be required
- 36:58so uh yes let's continue let's go ahead
- 37:01and uh discuss this entire thing first
- 37:03of all how we are going to go ahead
- 37:05first of all I'm going to show you the
- 37:07theoretical intuition how we going to
- 37:08develop it and then we will start the
- 37:10coding part so let me quickly go ahead
- 37:13and share my screen what we are actually
- 37:15going to do over here over here I se you
- 37:17have seen that I've written apis for
- 37:19deployment okay so if I consider this
- 37:22diagram this is the most simplistic
- 37:24diagram that I could draw okay now let's
- 37:27consider see um the at the end of the
- 37:30day in companies right uh there will be
- 37:32different different uh applications this
- 37:34applications are obviously created by
- 37:36software Engineers right it can be a
- 37:38mobile app it can be a desktop app web
- 37:40app and all now for this particular app
- 37:43if I want to integrate uh any foundation
- 37:46model or any fine-tuned foundation model
- 37:49like llms and all um so what I really
- 37:52need to do is that I need to integrate
- 37:53this with the form of apis at the end of
- 37:56the day see what we are going to do over
- 37:57here this side is my llm models itself
- 38:00right it can be a fine-tuned llm models
- 38:02it can be a foundation model I want to
- 38:04use those functionality along with my
- 38:06web app or mobile app so what we are
- 38:08doing is over here is that we will
- 38:10create this specific apis now this apis
- 38:13will be having routes okay routes and
- 38:17this routes will be responsible whether
- 38:19we have to probably interact with open
- 38:21AI or whether we have to interact with
- 38:23other llm model like Cloud 3 cloudy 3 or
- 38:26llama 2 open source model model so any
- 38:28number of llm models whether it is open
- 38:30source or uh whether it is uh paid API
- 38:34models specifically for llm we can
- 38:36definitely use it now this is what we
- 38:38are going to do in this video we will
- 38:41create this separately we will create
- 38:43this separately and at the end of the
- 38:45day I'll also give you an option through
- 38:47routes how you can integrate with
- 38:49multiple llm models right so I hope you
- 38:52have got an idea with respect to this
- 38:54and any number of llm models it may
- 38:55probably come you can probably integrate
- 38:57it at the end of the day whichever model
- 38:59is suitable for you you can use for
- 39:01different different functionality and
- 39:03the reason why I'm making this video
- 39:05understand one thing guys because in
- 39:06llms also you have different performance
- 39:09metrics some model is very good at some
- 39:12performance metrics over there like MML
- 39:14other other metrics are definitely there
- 39:16so this is an option where we can use
- 39:17multiple llm models now what we are
- 39:20going to do quickly I will go ahead and
- 39:22open my code document so in in my
- 39:25previous video already you have seen I
- 39:27had actually developed till here right I
- 39:29have basically if you see over here we
- 39:32have created this first folder that is
- 39:34chatbot and inside the chatbot we had
- 39:36created app.py then local Lama py right
- 39:40we with this did this entire thing and
- 39:42as I said every tutorial I'll keep on
- 39:45creating folders and developing our own
- 39:47project over here now let's go ahead and
- 39:49create my second folder and this time
- 39:51this will be apis okay so I'll just go
- 39:54ahead and write something like API okay
- 39:57now with respect to this API as I said
- 40:00whatever we do with this local Lama or
- 40:03app.py right over here I've used open a
- 40:05API key here I used open source models
- 40:08so we'll try to integrate both of them
- 40:10in the form of routes okay so that we'll
- 40:12be able to create an API so let me
- 40:14quickly go ahead and write over here
- 40:16app. Pui so one will be my app. Pui
- 40:19which will be responsible in creating
- 40:20all the apis the second one will
- 40:22specifically be my client.py now
- 40:25client.py in this specific diagram is
- 40:28just imagine like this one web app or
- 40:30mobile app because we are going to
- 40:31integrate this apis with this mobile app
- 40:33or web app okay so quickly let's do this
- 40:36uh first of all I will go ahead and
- 40:38start writing the code in
- 40:40app.py before I go ahead uh we have to
- 40:43make sure that we need to update all the
- 40:45requirement. txt almost all the
- 40:47libraries have installed it but I'm
- 40:49going to install more three libraries
- 40:51one is langu fast API and uvon okay
- 40:54since I'm going to create my entire
- 40:55Swagger documentation of API using fast
- 40:58API right so all these three libraries
- 41:00I'll be using it so first of all I will
- 41:02go ahead and install all these
- 41:05libraries that we'll do once we run the
- 41:07code right now let's go ahead and write
- 41:08my app.py code okay now as usual first
- 41:13of all uh let me just open my terminal
- 41:17okay and let me do one thing with
- 41:20respect to the terminal I will go ahead
- 41:22and write pip
- 41:25install pip install
- 41:27minus our requirement.
- 41:31txt okay first of all I need to just
- 41:34write CD dot dot okay then I'll clear
- 41:38the screen and then go ahead and write
- 41:40paper install minus r requirement. txd
- 41:44now here you'll be able to see that my
- 41:45entire installation will start taking
- 41:47place and here uh the other three
- 41:50packages that I have actually written
- 41:51right Lang serve and all that will get
- 41:53particular installed okay now till then
- 41:56installation is B basically going on let
- 41:58me go ahead and write my code so I will
- 41:59write from Fast
- 42:02API
- 42:05import fast API okay so this is the
- 42:09first
- 42:11uh first library that I'm going to
- 42:13import along with this I have to also
- 42:15make sure that I create or I import my
- 42:18uh chat prom template so from Lang chain
- 42:23since we are going to create that entire
- 42:24apis in this okay prompt
- 42:28import chat prom template
- 42:35right so this is done then
- 42:39from line chain
- 42:43dot chatore models
- 42:47import chat open aai so this is the next
- 42:50one since I need to make sure that I
- 42:53need to create a chat chat application
- 42:55so that is the reason why I'm using this
- 42:56chat models okay uh this is the next
- 42:59library that I'll be going ahead and
- 43:01importing along with this I'll also use
- 43:03langu which will be responsible in
- 43:05creating my entire apis right so from
- 43:08Lang serve import add routes okay so
- 43:11through this I will be able to add all
- 43:14the routes over there right whatever
- 43:16routes suppose one route will be that I
- 43:18need to interact with my opening API one
- 43:21one route will be to interact with the
- 43:23Lama 2 and all So based on that I will
- 43:25go ahead and import this next thing is
- 43:29import
- 43:31uon okay uon will be required over
- 43:35here
- 43:39oops okay next is import OS see I can
- 43:44probably enable my GitHub co-pilot and I
- 43:47can probably write the code but I don't
- 43:49think so that will be a better way uh I
- 43:51usually use this AI tool which is called
- 43:53as blackbox uh so that it will help me
- 43:55to write my code faster
- 43:57and uh you know it also explains about
- 43:59the code so I'll probably create another
- 44:01video about it okay so how to basically
- 44:03use this then one more thing that I
- 44:05really want to import over here is my
- 44:07olama so from langin community.
- 44:11llms LMS
- 44:14import o Lama okay so this is done all
- 44:19the libraries that is specifically
- 44:21required by my code uh I have actually
- 44:23written that okay and these are all the
- 44:26things that I will require to create my
- 44:27open a API now this is done now what I'm
- 44:30actually going to do over here is that
- 44:31I'm just going to write os. environment
- 44:34and first of all I will initialize my
- 44:36open AI API key so I will write open
- 44:38aore API _ key okay and this
- 44:43specifically I will load it from os.
- 44:48getenv and then I will go ahead and
- 44:51write open aior API
- 44:55uncore key okay so this is the first
- 44:58thing that we really need to do before I
- 45:00do this I will just go back to my o
- 45:03app.py and I will just initialize
- 45:07this okay load. EnV let me quickly copy
- 45:11this entire thing and paste it over
- 45:15here and I will initialize
- 45:18this load
- 45:22[Music]
- 45:23uncore
- 45:25Okay so this will actually help me to
- 45:28initialize all my environment variable
- 45:31perfect uh I've also loaded my open API
- 45:34key now let's start this fast API now in
- 45:36order to create the fast API uh I have
- 45:39to create an app here I've given title
- 45:41langin server version 1.0 and the third
- 45:45information I basically want is the
- 45:47description now after this I can use
- 45:49this app and I can keep on adding my
- 45:52routes okay so what I will do uh addore
- 45:56routes and this routes is basically to
- 45:59add all the routes over there right for
- 46:01so the first time when we are adding
- 46:03this particular routes you have to make
- 46:04sure that I give all the information
- 46:06like whether I'm going up with my app
- 46:09let's say I go with this chat open a API
- 46:14chat open
- 46:15AI open AI okay and the third
- 46:19information that I will probably give is
- 46:21my path so this is my one of my one of
- 46:25my uh route you can just consider this
- 46:28open AI route and this is my model that
- 46:30I will specifically be using so this is
- 46:32just one way how you can actually add
- 46:34route okay but let me just add some more
- 46:37things because see at the end of the day
- 46:39when we created our first application we
- 46:41used to combine prompt llm and output
- 46:44parser in this specific way so what
- 46:46we'll do over here is that when we are
- 46:47creating routes we also need to make
- 46:49sure that we add all the routes in such
- 46:51a way that I also integrate my prompt
- 46:54template with it okay so here I'm going
- 46:56to say model is equal to chat open
- 47:01AI chat open Ai and I'm going to
- 47:03initialize this particular
- 47:05model and then let me go ahead and
- 47:07create my other model also see o Lama I
- 47:09will just use my llama 2 Okay so this
- 47:12model also I need to basically create it
- 47:14or call it okay because I I want to use
- 47:15multiple models so here I'm going to
- 47:17write
- 47:19llm and here
- 47:21AMA and this will basically be my model
- 47:24is equal to
- 47:28llama 2 okay so I'm going to use the
- 47:31Llama 2 model so this is my one model
- 47:33over here this is my another model over
- 47:35here okay now let me go quickly go ahead
- 47:38and create my prompt one so my prompt
- 47:40one will be my chat prompt template
- 47:43chart promp
- 47:45template dot frore
- 47:49template okay and here I'm going to
- 47:51basically give one chat prompt okay
- 47:54let's say one of my interaction one I
- 47:57want to use open a API uh for open a API
- 48:01let's say I want to create an essay so
- 48:03I'll say write me an
- 48:05essay write me an
- 48:08essay about a specific topic that topic
- 48:11I will be giving it okay about some
- 48:14topic okay some topic
- 48:17okay
- 48:19around with 200 words or with 100 words
- 48:23okay so this is my first prom template
- 48:26okay I'm saying this will be my prom
- 48:28template write me an essay about
- 48:30whatever topic I give with 100 words
- 48:32okay something like this so this let's
- 48:34go ahead and write this this is my first
- 48:36promt template then I will create my
- 48:39second prompt template okay this is
- 48:41important just just hear me out okay and
- 48:43this promt template will be responsible
- 48:46in interacting with my open source model
- 48:48so let me say write me a poem I'll say
- 48:50write me a poem about this specific
- 48:52topic with 100 words so in short this
- 48:55first prom template will will be
- 48:57interacting with this model that is
- 48:58chart open API prompt 2 will be
- 49:00interacting with llm model okay whatever
- 49:03llm model I written over here that is
- 49:04Lama 2 now let me go ahead and add this
- 49:07routes so here I'll say add routes okay
- 49:11and again as usual I will write app now
- 49:14here you see I will be combining prompt
- 49:17or model right model will be chat open
- 49:20API and you know this prompt one is
- 49:22specifically for my chat open API right
- 49:26then I will also give the route path so
- 49:28my path will be something like this okay
- 49:32and this will be my API right so here
- 49:34say let's say I'll write slay that
- 49:37basically means this path is responsible
- 49:39in interacting with the open API and
- 49:42this is denoted by slash essay so that
- 49:45API URL that you'll be getting will be
- 49:48ending with slay okay the other route
- 49:51and I can keep on adding any number of
- 49:52routes as you want so another route will
- 49:54be like with promp two okay and here I'm
- 49:58going to basically use my llm and let me
- 50:00just go ahead and write this as/ poem
- 50:03okay/ poem so this is my another route
- 50:06this is my another route okay and
- 50:08finally I've created two apis in short
- 50:11and now here I will write if underscore
- 50:12uncore name underscore uncore is double
- 50:15equal to underscore uncore maincore
- 50:18uncore
- 50:19right now what we are going to do over
- 50:22here this is the starting of the
- 50:24application I will say uvon
- 50:27run and here I'm going to use my app
- 50:31comma host will specifically be my Local
- 50:33Host see here I'm giving you the Local
- 50:36Host uh this application you can run it
- 50:39in any server that you want right so
- 50:41that is the saying that is the reason
- 50:42why I'm saying this is the first step
- 50:44towards building that production grade
- 50:46application okay and the port number
- 50:48will be 8,000 perfect so this is done I
- 50:51think uh it looks really really amazing
- 50:53we have written the complete code over
- 50:54here and this is is my entire app.py
- 50:58with all the API so that basically means
- 51:00if I see the diagram over here this API
- 51:03part I actually created routes along
- 51:05with prompt template I've created and
- 51:07I've used two apis one is open aai and
- 51:10one is Lama tool two routes I've
- 51:11specifically used now my time is to
- 51:14basically create this web app and mobile
- 51:15app okay and I here I will just try to
- 51:17create a simple web app the reason why
- 51:20I'm creating this simple web app because
- 51:21it will be able to interact with this
- 51:23okay now what I will do let's go ahead
- 51:26and run this and see whether everything
- 51:28is running fine or not okay so here what
- 51:31I will do I will go to my CD which
- 51:34folder this is this is basically my API
- 51:36folder okay so CD
- 51:39API oops
- 51:41Port let me just write
- 51:45it Port okay done CD I'll save this CD
- 51:52API okay and then here I'm going to
- 51:55write python app.py okay now once I
- 51:58execute this from Lang chain uh Lang
- 52:01chain. prompts just let me see the
- 52:03documentation whether it is correct or
- 52:05not it should be prompts okay so a small
- 52:09issue over here it should be prompts now
- 52:12let me just go ahead and execute it now
- 52:14I think it should work
- 52:17fine uh so here you can see import error
- 52:23uh SSE Starlet Okay so so this is one of
- 52:27the dependency that is probably coming
- 52:29up uh I will quickly go ahead and update
- 52:31my requirement. txt okay and let me do
- 52:36one thing just let me write pip install
- 52:39this particular application
- 52:41okay so I will go and write pip
- 52:45install control V oops pip
- 52:50install and SSC Starlet okay so once
- 52:53this installation will probably happen I
- 52:55think now we'll not get an error now if
- 52:57I write python app.py it should run I
- 53:01guess so it is now running okay uh so
- 53:04let's go ahead and open this Local Host
- 53:07uh now here you can see I'm getting
- 53:09details not found but if you really want
- 53:11to see that entire API that is basically
- 53:13created you can just write slash docs
- 53:17now here you can see your entire langin
- 53:19server see I've created open aai input
- 53:22schema everything is given essay essay
- 53:24is also there poem is also there and all
- 53:26right so all the apis is almost created
- 53:29see here you can see what is the input
- 53:31what is the output output schema what is
- 53:33is basically required everything is
- 53:35probably given over here and this is
- 53:36basically called as a Swagger UI
- 53:38documentation okay the entire Swagger UI
- 53:40documentation is done now
- 53:43perfect your apis part is basically
- 53:46created now how do we interact with this
- 53:48apis that is the most important part so
- 53:50for that what we are going to basically
- 53:52do I'm going to uh let let let let let
- 53:57let this terminal be hidden over here
- 53:59I'm going to create my client.py okay
- 54:02now with respect to the client.py what
- 54:04we are going to do and let me do one
- 54:06thing till then I will go ahead and
- 54:09disable this extension okay because I
- 54:12don't want this extension to disturb
- 54:16things okay
- 54:18disable
- 54:23perfect I will show you this extension
- 54:25it is a very powerful extension okay now
- 54:28this client. py is my app it can be my
- 54:31app okay so first of all what I'll do I
- 54:33will go ahead and import
- 54:35request
- 54:37okay after importing request I'm going
- 54:39to write import streamlet
- 54:43as stream late as St okay so two
- 54:47libraries I'm going to import request
- 54:50and streamlet understand I'm creating a
- 54:52web app I can create a front end that
- 54:54will interact with the API okay so here
- 54:57first of all I will write two definition
- 54:59or two important function one
- 55:01is
- 55:03uh
- 55:06getor open aore response and here I'm
- 55:11going to basically go ahead and write my
- 55:13input underscore
- 55:15text okay here I will call I will
- 55:20probably call use this request object
- 55:22and create my response now in order to
- 55:25create the response in order to call the
- 55:26API how do I do it so here I'm going to
- 55:29write request dot
- 55:31post and how to basically call it so
- 55:34first of all I need to give the URL
- 55:37understand we are already running this
- 55:39URL right this entire Local Host if you
- 55:41probably see over here everything is
- 55:42running over here right if you if you
- 55:45see this okay if you probably see this
- 55:48and try to try to see this entire URL
- 55:52okay you can directly see that in order
- 55:55to call this API
- 55:56I will be using a URL that is already
- 55:59provided by this particular Swagger UI
- 56:01that is nothing but let's say I want to
- 56:03call the essay URL okay now in order to
- 56:07call the essay URL which is using the
- 56:09open a API here you can see HTTP Local
- 56:12Host 8000 / invoke so this is my entire
- 56:15API URL which will be responsible in
- 56:17calling this and here we also know that
- 56:20we need to give one input so what I will
- 56:22do I will go ahead and write over here
- 56:24as Json is equal to and in the form of
- 56:27Json I will give one of my input so
- 56:30input colon okay and here I will write
- 56:35topic why topic because see here what we
- 56:37are given over here if you see over here
- 56:39topic is there right now this topic will
- 56:42be nothing but whatever input text I am
- 56:45giving to this particular function that
- 56:47same input text will be visible over
- 56:49here okay so this is what we have
- 56:52actually done over here right so input
- 56:55topic colon input so text so this is
- 56:57what is the input I will give and it
- 57:00will hit this particular URL along with
- 57:02this particular input post okay and then
- 57:05finally I get my response now what I
- 57:07will do I will go ahead and take this
- 57:10response convert into a Jon and it has a
- 57:13key dictionary value pairs which where
- 57:16my output content will be present inside
- 57:18this variable called as output and one
- 57:21more thing that I require is basically
- 57:23content okay so inside this key my
- 57:25entire response will be available the
- 57:28next thing that I'm actually going to do
- 57:29is similar with the help of AMA response
- 57:32and here we are going to use Lama 2 so
- 57:35get AMA response input text again
- 57:37request. poost now instead of using
- 57:39this/ / invoke we are going to use SL
- 57:43po/ invoke why/ po/ invoke because SL
- 57:46poem will be responsible in interacting
- 57:48with Lama 2 okay and then I get my Json
- 57:51again I uh I get my response here I'm
- 57:53writing response. Json of output okay
- 57:56okay so these are my two functions that
- 57:58I've actually created to get the
- 58:00response now what let me do one thing
- 58:02now let me go ahead and create my
- 58:03streamlet framework very simple now now
- 58:06from here everything will be simple okay
- 58:08so st. title this this is there I've
- 58:11created two textbox one is input text
- 58:14and one is input text one first text box
- 58:17I'm saying write an essay on whatever
- 58:18topic the second text box I'm writing
- 58:20write a poem of any other topic okay so
- 58:23first one we'll be interacting with the
- 58:25openi application this the second one
- 58:26will be interacting with Lama 2 okay and
- 58:29finally I'm going to call this
- 58:32particular two function that I have
- 58:34created if input. text if I write any
- 58:37text in the first time then it should
- 58:38basically interact with the openi
- 58:41response whatever response I'm getting
- 58:42it will display it over here if input
- 58:44text one I'll just call the AMA response
- 58:48which is interacting with the Llama 2 on
- 58:50this particular URL okay and then I will
- 58:52get the over here the output so this is
- 58:55my entire application which is
- 58:57interacting with the API which is
- 58:59already running over here right now with
- 59:01respect to this client.py what I'm
- 59:03actually going to do I'm going to create
- 59:05another command prompt and let me run
- 59:06this okay so here I will say uh cond
- 59:13deactivate and I will say
- 59:16cond activate
- 59:18VNV okay and let me just go ahead and
- 59:21run this now see python client.py okay
- 59:27okay sorry it should be
- 59:28streamlit
- 59:30streamlit
- 59:32run client.py okay so this is my client
- 59:36side okay file does not exist okay oh I
- 59:39will say CD and I will go to my folder
- 59:42that is API now let me go ahead and
- 59:44write streamlet run client.py now see
- 59:46this this is my Swagger UI the API is
- 59:50running over here and this is my front
- 59:52end application which is basically in
- 59:54now it will interact with with this apis
- 59:57okay now if I write the first one the
- 59:59first the first anything in the first
- 1:00:01text box this is going to interact with
- 1:00:03the open API so I'll say write an essay
- 1:00:05on machine
- 1:00:07learning okay so here you can see name
- 1:00:11get open AI response is not defined why
- 1:00:14this is the error let's
- 1:00:16see open AI
- 1:00:19response oops just a second this
- 1:00:22function name is does not match
- 1:00:26and this also o Lama response does not
- 1:00:29match or what okay now I think it should
- 1:00:31work let's reload it
- 1:00:35okay now you can see automatically
- 1:00:37machine learning is a powerful
- 1:00:38technology that enables computer this
- 1:00:40this this so the first text box is
- 1:00:42interacting with the open aipi write a
- 1:00:45po poem on machine learning let's say if
- 1:00:47I give the same thing if I execute it
- 1:00:50now this is going to interact with the
- 1:00:51Llama 2 so machine learning is a field
- 1:00:52of arti that allows computers to make
- 1:00:54decision or still running sorry
- 1:00:56uh this was the first response that I
- 1:00:58got from them
- 1:01:00uh okay it's running I guess let me
- 1:01:03reload
- 1:01:04it write a poem on machine learning okay
- 1:01:09and I can also write my own custom
- 1:01:11prompt if I want everybody I was
- 1:01:13thinking that we could make a bit of
- 1:01:15interesting by adding some extra
- 1:01:16challenges so and so so what do you say
- 1:01:19something something is given okay uh and
- 1:01:21if I probably see over here with respect
- 1:01:23to the prompt input text one this is
- 1:01:25also going over here uh this is my input
- 1:01:28text okay perfect so everything works
- 1:01:30fine and here you'll be able to see
- 1:01:31write a poem about uh this particular
- 1:01:34topic with
- 1:01:37um for a five years child okay so now
- 1:01:41let's see I'll just try to change the
- 1:01:44prompt and see whether it is working
- 1:01:45fine or not so this has got reloaded it
- 1:01:48uh let's see whether this is reloaded or
- 1:01:50not now if I go ahead and reload this
- 1:01:54write a poem on on
- 1:01:57unicorn okay I'm just writing something
- 1:02:01unicorn I think it should be able to
- 1:02:02give the
- 1:02:03poem shimmering coat in various colors
- 1:02:06here are 100 words that describe a
- 1:02:08unicorn okay something something
- 1:02:10information is basically and this is
- 1:02:12basically interacting with the entire
- 1:02:13Lama 2 hello guys we are going to
- 1:02:16continue the Lang chain series and in
- 1:02:18this specific videos and in the series
- 1:02:20of upcoming videos we are going to
- 1:02:22discuss about rag pipeline now rag uh
- 1:02:26the full form is retrieval augmented
- 1:02:28generation one of the very important use
- 1:02:30cases you may probably solving when you
- 1:02:33specifically use llm models and most of
- 1:02:36the use cases right now in companies are
- 1:02:38demanding this kind of skill sets you
- 1:02:40know where you can actually develop rag
- 1:02:42let's say you have a set of documents
- 1:02:44and you should be able to query that
- 1:02:46specific documents and get the result
- 1:02:48quickly if you have different kind of
- 1:02:51files let it be a readme file a text
- 1:02:53file a different data source file you
- 1:02:55should be able to read it convert that
- 1:02:56into a vectors and able to retrieve any
- 1:02:58queries specifically from those kind of
- 1:03:01data sources so uh as I said uh we will
- 1:03:04be implementing this completely from
- 1:03:06scratch from basic to Advanced in this
- 1:03:09specific videos we'll understand the
- 1:03:10entire architecture and then we will do
- 1:03:12a lot of practical intuitions okay so uh
- 1:03:16in any rag pipeline these are the major
- 1:03:19components that will probably exist so
- 1:03:21the first component is specifically
- 1:03:23called as load data source now whenever
- 1:03:26we say load data source initially we may
- 1:03:29have see rag is all about quering from a
- 1:03:31defin different different data source
- 1:03:33all together right so we may be having
- 1:03:36files that may be having PDF it can be a
- 1:03:38MD file readme file it can be a Excel
- 1:03:41file it can be a txt file it can be a
- 1:03:44database file it can be different
- 1:03:45different files all together right and
- 1:03:47in the first so first step that we see
- 1:03:50over here it is basically called as load
- 1:03:52Source data this step is also called as
- 1:03:55data injection okay data injection now
- 1:03:59in Lang chain the most amazing thing is
- 1:04:01that it definitely have a lot of
- 1:04:04different kind of data injection tools
- 1:04:06which will be able to load the data in
- 1:04:08various manner so in our current video
- 1:04:11we are going to implement each and every
- 1:04:13of this component from data injection
- 1:04:14till the query Vector store okay then
- 1:04:18after ingesting the data you can
- 1:04:20probably do load you can transform and
- 1:04:23you can embid okay we will discuss about
- 1:04:25this what exactly is load transform and
- 1:04:27embid specifically when we do loading
- 1:04:30that is nothing but we are reading from
- 1:04:31a specific data source then we perform
- 1:04:34some type of feature engineering over
- 1:04:37here if we want like in transform stage
- 1:04:40here the data the complete data will be
- 1:04:43broken into smaller chunks okay now why
- 1:04:47do we divide this data into smaller
- 1:04:48chunks it is very much important to
- 1:04:51understand because whatever llm models
- 1:04:54we specifically use right is definitely
- 1:04:57has some kind of context size right so
- 1:05:00based on this context size it is always
- 1:05:02a good good way to basically convert
- 1:05:07this entire data which can be of many
- 1:05:10number of PDFs it can be U many number
- 1:05:13of pages in this specific PDF we will
- 1:05:15try to divide this particular thing into
- 1:05:17chunks of data so this is also what
- 1:05:19we'll going to see in the practical way
- 1:05:21then finally we go ahead with embeddings
- 1:05:24embeddings basically means how we can
- 1:05:26convert all these chunks into vectors
- 1:05:30okay how we can actually use vectors in
- 1:05:33order to probably convert this chunks
- 1:05:35right and finally all these vectors will
- 1:05:38be further stored in some kind of vector
- 1:05:41stored database okay so it can be a
- 1:05:44database over here and the main reason
- 1:05:46of this specific database is that we
- 1:05:48will be able to query this particular
- 1:05:51database in an efficient manner right
- 1:05:53with respect to any query that we have
- 1:05:55have right so whatever vectors are
- 1:05:57basically stored if I have a query if I
- 1:06:00hit the query on this particular
- 1:06:01database I should be able to get the
- 1:06:03result based on the context of the query
- 1:06:06so this is the entire rag pipeline that
- 1:06:08we specifically use in the upcoming
- 1:06:11series of videos we are going to use
- 1:06:13different different Vector databases in
- 1:06:15different different clouds also okay so
- 1:06:17right now we will try to implement all
- 1:06:19these things that you can actually see
- 1:06:20in front of you and we will follow this
- 1:06:23entire architecture so let me quickly
- 1:06:25open my vs code and once I probably
- 1:06:28start my VSS code I will be um I will
- 1:06:31continue with respect to the same uh
- 1:06:34thing that I have actually used right
- 1:06:36all the projects that I've actually
- 1:06:37created as I said that all the things
- 1:06:39will be given in the description of this
- 1:06:41particular video with respect to the
- 1:06:42GitHub link okay now I've have created a
- 1:06:45folder which is called as rag inside
- 1:06:47this I will create one ipynb file okay
- 1:06:50initially we'll go with ipnb file and
- 1:06:52then later on we'll try to create an end
- 1:06:54to end project okay so here I will say
- 1:06:57uh simple rag.
- 1:07:00iynb since we are doing it completely
- 1:07:02from Basics it is always good that we
- 1:07:05try to do it completely from basic
- 1:07:06itself right so U this is the thing so
- 1:07:10first of all I will go ahead and see
- 1:07:12whether in my terminal whether I have
- 1:07:14that I kernel installed or not okay so I
- 1:07:18will go ahead and write pip
- 1:07:20install iy kernel IPI kernel is
- 1:07:23specifically used to install all the
- 1:07:25jupyter notebook kernels itself right so
- 1:07:28once I probably install this you'll be
- 1:07:29able to see that this installation will
- 1:07:31take place and I think it is already
- 1:07:33satisfied so it is good enough we can
- 1:07:35probably go ahead and start the coding
- 1:07:37over here then I will go ahead and
- 1:07:39select my kernel and it is nothing but
- 1:07:423.1 1.0 right this is what is the
- 1:07:45environment that I have created now if I
- 1:07:47go ahead and execute something so it is
- 1:07:49giving me some kind of error okay so
- 1:07:51perfect now what I'm actually going to
- 1:07:53do uh I can see that there is some kind
- 1:07:56of message over here I will just try to
- 1:07:58uh disable this I've already uninstalled
- 1:08:00uh this extension so that it will not
- 1:08:02give us any disturbance so let me do one
- 1:08:05thing let me just open over here for you
- 1:08:09and here I will open this particular
- 1:08:11folder and then I will go ahead and
- 1:08:14close this okay close window okay and
- 1:08:17now let me quickly open the vs code
- 1:08:20again and here is my entire project we
- 1:08:24will just try to execute it once again
- 1:08:26okay perfect so that so that I don't
- 1:08:30have any disturbance with respect to
- 1:08:31that okay now perfect now this is done
- 1:08:34now let's go ahead and start our coding
- 1:08:36initially I will try to show you
- 1:08:39multiple data injection steps okay so
- 1:08:41data injection basically means let's say
- 1:08:43I want to read from a text file I want
- 1:08:45to read from a PDF file I want to read
- 1:08:48from a web web page how can I actually
- 1:08:50do it okay so all those things we'll
- 1:08:52start to discuss so first of all I will
- 1:08:54go ahead and import from Lang chain unor
- 1:08:58Community do document loaders now
- 1:09:01document loaders has all the techniques
- 1:09:04specifically if you want to load uh
- 1:09:06let's say a PDF you want to load a Excel
- 1:09:08file you want to load a txt file so over
- 1:09:11here all the libraries will be present
- 1:09:13so from linore community. doent loaders
- 1:09:17until then I will just close this
- 1:09:18terminal because I will not require over
- 1:09:20here then the first one that I'm
- 1:09:22actually going to discuss about text
- 1:09:24loaded itself now over here what I'm
- 1:09:26actually going to do I'm going to create
- 1:09:27a loader is equal to text
- 1:09:31loader and after creating this text
- 1:09:33loader here I'm going to give a text
- 1:09:36file okay speech. txt so we'll just go
- 1:09:39ahead and see whether we have the
- 1:09:40speech. txt file or not no I don't have
- 1:09:43it so let me go ahead and create one
- 1:09:45speech. txt file okay and uh with
- 1:09:49respect to this particular file what I
- 1:09:51am actually going to do I'm going to put
- 1:09:52some content so I have already have that
- 1:09:55content let me just quickly copy and
- 1:09:57paste it this is one of the most famous
- 1:10:00speech um that is available in some
- 1:10:03history it has been taken over here so I
- 1:10:05just Googled it and I bought this
- 1:10:06particular speech over here and saved it
- 1:10:08in speech. txt okay uh then what I will
- 1:10:12do I will go over here and read the
- 1:10:14speech. txt okay now just by using this
- 1:10:17text loader what will happen is that
- 1:10:19you'll be able to read the speech. txt
- 1:10:21then I will use
- 1:10:23loader do load load and here I'm going
- 1:10:27to specifically convert this entire
- 1:10:30thing into text
- 1:10:32documents okay once I write loader. load
- 1:10:36that basically means it is going to just
- 1:10:38convert this into a text documents and
- 1:10:40this finally you'll be able to see my
- 1:10:42test
- 1:10:44documents and I will go ahead and
- 1:10:46execute it so here you'll be able to see
- 1:10:48that once it is reading the specific
- 1:10:51speech it has the entire text document
- 1:10:54now it is becoming so easy
- 1:10:55just to read the txt file okay now the
- 1:10:58next thing that I'm going to
- 1:10:59specifically do is that uh since I'm
- 1:11:01also going to use open keys or um I'm
- 1:11:05also going to use Ama embeddings or AMA
- 1:11:07model so what I can do is that I will
- 1:11:09just go ahead and import OS um the next
- 1:11:13thing that I will go ahead and do is lo
- 1:11:16load. EnV okay so load. EnV so for this
- 1:11:22I'm also going to import from. EnV
- 1:11:26uh import
- 1:11:29load. EnV okay now why I'm doing this so
- 1:11:32that I will be able to call all my
- 1:11:34environment variables and in one of the
- 1:11:36environment variables I also have my
- 1:11:38open API key so now I will go ahead and
- 1:11:40write OS dot environment and here I'm
- 1:11:44going to use my
- 1:11:46opencore a sorry open aior
- 1:11:51API uncore key
- 1:11:55and here I'm just going to use os.
- 1:12:01getv and here again I'm going to use my
- 1:12:03open API key so this is basically going
- 1:12:05to call the open API key from the
- 1:12:08environment variable now a very
- 1:12:09important step Al together over here
- 1:12:12guys now is the main term that we will
- 1:12:14be starting to uh see some more data
- 1:12:18injection techniques so one more data
- 1:12:20injection technique is directly reading
- 1:12:22from the web based web based
- 1:12:25uh loader you can basically say okay and
- 1:12:28for this again I will be importing
- 1:12:30understand any document loader will be
- 1:12:33available in this specific Library
- 1:12:34itself and instead of writing text
- 1:12:36loader we will be using webbased loader
- 1:12:40okay now along with this I will also
- 1:12:42import bs4 that is beautiful soup 4 so
- 1:12:45for that also what I will do I will just
- 1:12:47import over here in my requirement. txt
- 1:12:50bs4 so that whenever I execute this it
- 1:12:53should be able to run okay now in order
- 1:12:57to do something like this load chunk and
- 1:13:01index the content of the page HTML page
- 1:13:07right or any web page so here I will
- 1:13:09create a loader and this will be equal
- 1:13:12to web based loader and here I'm going
- 1:13:15to give two important parameters one is
- 1:13:17the web path so webcore
- 1:13:21paths okay is equal to and here I will
- 1:13:24give the UR Ur l so let me just take one
- 1:13:26URL from the GitHub IO page that is also
- 1:13:29available in the documentation of langin
- 1:13:32so this is what is the page over here um
- 1:13:35what I will do is that quickly I will
- 1:13:37open a browser and show it to you how
- 1:13:39this page looks like okay so if I
- 1:13:42execute this over here you'll be able to
- 1:13:45see that just a second okay perfect so
- 1:13:49here you you are able to see that uh
- 1:13:52just a second this see is this the same
- 1:13:54page yes it is the same page and I will
- 1:13:58be opening this okay perfect so this is
- 1:14:01the page that you will be able to see
- 1:14:03over here and I want to probably read
- 1:14:05this entire page and uh use it as a rag
- 1:14:09system itself right so in order to read
- 1:14:11this entire page I can just take this
- 1:14:13URL and use this web loader Library so
- 1:14:17here if you see I'm using this web based
- 1:14:19loader library and I'm giving the first
- 1:14:22parameter that is the web path okay the
- 1:14:25second parameter that we can
- 1:14:26specifically give is our arguments right
- 1:14:29so here I will wrate BS doore KW a r GS
- 1:14:34okay so this is the second parameter I'm
- 1:14:36just seeing the documentation and we
- 1:14:38will give the next argument in the form
- 1:14:39of dictionaries the first is parscore
- 1:14:43only okay and then here I'm basically
- 1:14:47going to use my bs4 that is a beautiful
- 1:14:49Soup For Soup trainer okay soup
- 1:14:55strainer soup strainer okay yeah soup
- 1:14:59strainer so this is the first uh
- 1:15:02parameter that I will be specifically
- 1:15:03giving and understand why this is
- 1:15:06required because here the soup strainer
- 1:15:08and since we are using beautiful soup
- 1:15:11over here we really need to give the
- 1:15:13classes that it read it needs to read
- 1:15:16from that particular page okay and here
- 1:15:19what all classes are there let's go
- 1:15:21ahead and see this okay so if I probably
- 1:15:23see over here and if I do just inspect
- 1:15:26element okay so here you can see post
- 1:15:29title is there then you have something
- 1:15:32like post content where all the content
- 1:15:34is basically available so let us take
- 1:15:36this one as my first one okay so I will
- 1:15:39just go ahead and execute this and here
- 1:15:42you'll be able to see that uh this will
- 1:15:45basically be my post title and here you
- 1:15:48have the postore content and third one
- 1:15:53that I also want to take is postore
- 1:15:56header because header will also have
- 1:15:57some information over here right so this
- 1:16:00is done you'll be able to see that it
- 1:16:02looks absolutely fine and here with
- 1:16:04respect to this we have also created
- 1:16:06this entire loader um and here I will
- 1:16:09use a Comm up so that this is basically
- 1:16:11my argument over here right so once we
- 1:16:14do this uh then let's see whether it'll
- 1:16:17execute or not uh bs4 is not found as I
- 1:16:20said that bs4 is not there so let me do
- 1:16:23one thing quickly let me open my command
- 1:16:26prompt and do the PIP install
- 1:16:27requirement. txt okay so here I will go
- 1:16:31ahead and write pip install minus r
- 1:16:34requirement. txt and execute it over
- 1:16:36here you'll be able to see now bs4 will
- 1:16:39also get installed and once it is
- 1:16:40getting installed it is completed it is
- 1:16:43good to go now if we go ahead and
- 1:16:45execute it I think it should work
- 1:16:46perfect now loader is there now what we
- 1:16:49are going to do over here is that again
- 1:16:51write loader. load and finally I will be
- 1:16:53able to get in the form of text
- 1:16:56documents textor documents okay
- 1:17:00documents and here is my text document
- 1:17:03so perhaps you meant uh this one let's
- 1:17:07see um so guys there was one one error
- 1:17:11we need to give this URL in the form of
- 1:17:13duple so let this get closed and then I
- 1:17:16will write comma over here now I think
- 1:17:18it should be working let's see yes
- 1:17:20perfectly it is working right now and if
- 1:17:23you go ahead and see your text documents
- 1:17:25again you will be able to get all the
- 1:17:27information from that particular web
- 1:17:29page in the form of URL okay or in the
- 1:17:31form of documents so this is perfect uh
- 1:17:33you able to get every information over
- 1:17:36here and uh with respect to this you
- 1:17:38will be able to see that yeah you have
- 1:17:40all the information and you can also see
- 1:17:42the page content and everything looks
- 1:17:44fine so these are some of the ways how
- 1:17:46you can specifically make sure that uh
- 1:17:50you probably get all the content from a
- 1:17:52page itself one more thing uh this is
- 1:17:54not not underscore this is Dash so now I
- 1:17:57think you'll be able to see more content
- 1:17:58okay so let me just open this so here
- 1:18:01you'll be able to see all the content
- 1:18:03itself so uh this is one more way one
- 1:18:06more way is directly to read from the
- 1:18:07PDF itself so what I will do is that I
- 1:18:09will quickly create a PDF okay so let me
- 1:18:13do one thing and I will upload a PDF
- 1:18:16over here okay so here I've created this
- 1:18:18attention. PDF this is nothing but
- 1:18:20attention is all you need uh now uh
- 1:18:23using document loader you can also
- 1:18:24directly read completely from the PDF
- 1:18:26itself okay and how to do that see still
- 1:18:29we are in the data injection phase and
- 1:18:31how do we do this we'll also see that so
- 1:18:33from uh the same library that we'll be
- 1:18:35using again we have to focus on document
- 1:18:38loader and here I will copy and paste it
- 1:18:41okay um and this is basically my
- 1:18:45PDF reader one more Library dependency
- 1:18:48will be there okay so we will try to
- 1:18:50install that also so here I'm going to
- 1:18:52write Pi PDF all loader okay and again I
- 1:18:57will be using loader is equal to Pi PDF
- 1:19:00loader Pi PDF loader and I have to give
- 1:19:03my PDF name right so PDF name over here
- 1:19:06specifically is nothing but attention.
- 1:19:08PDF so it is in the same F same folder
- 1:19:11itself so here I will write attention.
- 1:19:14PDF okay now I think I should be getting
- 1:19:17an error if I don't get an error I will
- 1:19:19definitely install yeah I'll install it
- 1:19:21now see pip install P PDF so here I will
- 1:19:24make make sure that I will write
- 1:19:25requirement. txt and I will write Pi PDF
- 1:19:29okay so all these things you really need
- 1:19:30to take care of because they will
- 1:19:32definitely be dependencies because and
- 1:19:35understand rag is one very important
- 1:19:37thing that really needs to get created
- 1:19:38in the form of application so that is
- 1:19:40the reason I'm creating this completely
- 1:19:42from scratch so pip install minus r
- 1:19:44requirement. txt so this is also done I
- 1:19:47think and Pi PDF is also installed
- 1:19:49perfect then the next step again I will
- 1:19:52go ahead and execute this and but here
- 1:19:54also the same step will be required
- 1:19:55loader. loadad and this will basically
- 1:19:58be my documents and I will execute this
- 1:20:01and once I probably execute this this is
- 1:20:03my docs okay perfect so here you'll be
- 1:20:06able to see my entire PDF has been read
- 1:20:08and it is in front of you now the next
- 1:20:10step now see this load data source part
- 1:20:12is basically done we know how to load it
- 1:20:14okay now we will move towards this
- 1:20:17transform okay then we will go ahead
- 1:20:19towards embid okay so the first part of
- 1:20:21load I've actually done with respect to
- 1:20:23PDF web based with respect to text file
- 1:20:27if you go ahead and check out the langin
- 1:20:28documentation this there are still more
- 1:20:31amazing ways to do for Excel file for
- 1:20:33readme file different directories even
- 1:20:36for directors let's say that you have
- 1:20:38lot of files in the directory itself
- 1:20:40many files and you can also load that so
- 1:20:42we'll try to see in upcoming videos more
- 1:20:44about different different examples but
- 1:20:46here just to give an idea about load
- 1:20:48data source and load is actually done
- 1:20:51now let's go ahead and do this transform
- 1:20:53now transform is very much important
- 1:20:54important Now understand guys this is
- 1:20:56your entire PDF documents right now you
- 1:20:58need to convert this PDF documents into
- 1:21:01chunks now how do you do that and again
- 1:21:03they are multiple ways and this ways
- 1:21:06entirely Falls inside the category of
- 1:21:09text splitter inside Lang chain so here
- 1:21:12we are going to write from Lang
- 1:21:13chain from Lang chain dot text
- 1:21:19splitter
- 1:21:21import recursive
- 1:21:25recursive character text splitter we'll
- 1:21:26try to split it with the with the help
- 1:21:28of uh text itself so here I'm going to
- 1:21:31create my text splitter is equal to
- 1:21:34recursive character text splitter and
- 1:21:37here I'm going to specifically use my
- 1:21:39chunk uncore size is equal to 1,000 uh I
- 1:21:42want this specific size to be the chunk
- 1:21:45and let's say the overlap chunk chunk
- 1:21:49overlap okay chunk
- 1:21:53overlap so here I will go ahead and
- 1:21:55write chunk underscore overlap is equal
- 1:21:58to 200 I'll keep this as 200 okay so
- 1:22:01once I do this now this text splitter
- 1:22:02will be uh
- 1:22:04responsible textor splitter dot split
- 1:22:08documents will be responsible in
- 1:22:10splitting all the specific documents
- 1:22:12that I give over here okay so this docs
- 1:22:14will be there and this will be my
- 1:22:17documents final documents that I will be
- 1:22:19able to see okay let's display this
- 1:22:22documents the top five documents still
- 1:22:24here okay
- 1:22:27uh and let's see this so here you'll be
- 1:22:29able to see provided proper attrition is
- 1:22:31Google by Grant permission best model
- 1:22:33this this this this everything is there
- 1:22:36attention. PDF right so all the
- 1:22:38information is basically there um and
- 1:22:41with respect to this if you really want
- 1:22:43to see the more things more uh different
- 1:22:45different uh all the documents in short
- 1:22:48so you can also go ahead and see the
- 1:22:50entire documents over here okay done so
- 1:22:53these are all my documents over here
- 1:22:55Transformers everything is available
- 1:22:56over here now see this is my entire
- 1:22:59documents it has been divided into
- 1:23:01proper smaller chunks now we can take
- 1:23:03this chunks and we can convert that into
- 1:23:06vectors okay and that is what is giving
- 1:23:08you an idea over here right like how we
- 1:23:10have transformed We have basically taken
- 1:23:12this entire PDF document and we have
- 1:23:14divided that into chunks now it's a time
- 1:23:17that we understand how to probably
- 1:23:20convert this into vectors and for this
- 1:23:22we will also be using some different
- 1:23:24different Vector em uh Vector embedding
- 1:23:26techniques right one of the vector
- 1:23:28embedding techniques that I will be
- 1:23:29showing you is with respect to open AI
- 1:23:32so here now we will go ahead and
- 1:23:35probably write about vector embeddings
- 1:23:38and Vector store right Vector embeddings
- 1:23:41is a technique wherein we convert a text
- 1:23:44into vectors okay so how do we do that
- 1:23:46again with the help of open AI so here
- 1:23:48I'm going to write from Lang chain
- 1:23:49uncope Community Dot
- 1:23:53embeddings
- 1:23:55import open
- 1:23:56AI open AI embeddings you can also use
- 1:23:59AMA embeddings it is up to you since if
- 1:24:01you don't have open API you can use AMA
- 1:24:03embeddings directly but the performance
- 1:24:06of open AI embeddings is better far more
- 1:24:08better than AMA embeddings okay so here
- 1:24:10what I'm actually going to do next thing
- 1:24:12is that uh first of all uh we need to
- 1:24:16understand how to probably create
- 1:24:17vectors again to create vectors we can
- 1:24:19use open AI embeddings but after
- 1:24:22creating the vectors we also need to
- 1:24:24store in the vector store that is what
- 1:24:26it is right this Vector store is like
- 1:24:28kind of a database embeddings can be
- 1:24:31embeddings is a technique where we
- 1:24:32convert text into vectors but later
- 1:24:34those text needs to be stored in some
- 1:24:36kind of vector store right so for this
- 1:24:38reason we will be using something called
- 1:24:40as chroma DB so they are come there are
- 1:24:43couple of uh there are couple of vector
- 1:24:46databases that has been provided by Lin
- 1:24:48itself one is chroma one is f um as we
- 1:24:52go ahead you know how to create this
- 1:24:53kind of vector database in the cloud
- 1:24:55also I will show it to you so from Lang
- 1:24:57chain Community I will be using Vector
- 1:25:00stores and here I'm going to import one
- 1:25:03is nothing but chroma uh so with respect
- 1:25:06to this we will go ahead and create my
- 1:25:07DB and here I'm going to write chroma do
- 1:25:11from uncore documents okay from
- 1:25:16documents and here I'm going to
- 1:25:18basically give my entire document okay
- 1:25:21entire documents and I'll not give the
- 1:25:24entire documents let's just give the
- 1:25:25first 20 documents itself because it'll
- 1:25:28take more time to create the embeddings
- 1:25:31right and here the embeddings that I'm
- 1:25:32going to specifically use is nothing but
- 1:25:34open AI embeddings once I execute this I
- 1:25:36think I'm going to get an error saying
- 1:25:38that chroma is not available I don't
- 1:25:39know whether I've installed chroma or
- 1:25:41not so here you can see pip install
- 1:25:43chroma DB I really require chroma DB so
- 1:25:45again I'll go back to my requirement.
- 1:25:47txt the reason why I'm showing you all
- 1:25:49this completely from scratch so that you
- 1:25:51whatever error you face you should be
- 1:25:53able to fix it set up okay so I'm going
- 1:25:56to delete this and let's go ahead and
- 1:25:58write pip install uh one more library
- 1:26:01that I will be using is nothing but F
- 1:26:04CPU okay F CPU because f is also one
- 1:26:08type of chroma one type of vector
- 1:26:10database okay so minus r requirement.
- 1:26:13txt so let's install both the specific
- 1:26:16libraries it'll take some amount of time
- 1:26:17again it depends on your internet speed
- 1:26:19and how fast your system is but yes I
- 1:26:22think 5 CPU and chroma B is the kind of
- 1:26:25uh Vector databases that we will be
- 1:26:27using one assignment I'll give you try
- 1:26:29to also use Lance Vector database from
- 1:26:32again seeing the lanon documentation you
- 1:26:34can actually do it
- 1:26:36okay now this is done once uh this will
- 1:26:38probably be done then we can go ahead
- 1:26:40and check by executing it whether it is
- 1:26:42working now or not but at the end of the
- 1:26:44day here what we are actually doing we
- 1:26:47have imported open iddings the vector
- 1:26:49database that we are going to use is
- 1:26:51chroma then chroma from document I'm
- 1:26:54giving the entire document and using
- 1:26:55this embeddings it will be storing
- 1:26:57inside this particular Vector store now
- 1:26:59this DB we can store it in our local we
- 1:27:02can store it in the cloud wherever you
- 1:27:04specifically want okay so guys the
- 1:27:06installation has been completed now
- 1:27:08let's go ahead and execute this chroma
- 1:27:10part now here you'll be able to see that
- 1:27:12entire embedding will basically happen
- 1:27:14and again we are going to use the open a
- 1:27:16embedding for this and now this DB is
- 1:27:19nothing but our Vector database okay so
- 1:27:21if I probably consider Vector database
- 1:27:23and now all I have to do is that I can
- 1:27:25query anything with respect to this
- 1:27:27particular Vector database to retrieve
- 1:27:30any kind of result that I really want so
- 1:27:32I will create a query first of all so
- 1:27:34here let me go ahead and write my query
- 1:27:35so query is like I will go ahead and
- 1:27:37write who are the
- 1:27:39authors who are the authors of attention
- 1:27:44is all you need research paper okay so
- 1:27:48this is my query that I'm going to
- 1:27:50specifically ask let's see whether it'll
- 1:27:53be able to understand this or and it'll
- 1:27:55be able to give us the result so here I
- 1:27:57will go ahead and write DB
- 1:27:59do similarity search now there are
- 1:28:02multiple option similarity search
- 1:28:04similarity search by Vector if you want
- 1:28:06you can also convert your data into
- 1:28:08vectors by using again the openi imings
- 1:28:10and you can query it from here but we
- 1:28:11are just going to use the similarity
- 1:28:13search since we are just going to use
- 1:28:14the query over here right so if I write
- 1:28:17db. similarity search of query so this
- 1:28:20will basically be my result okay now
- 1:28:23let's go ahead and see my result okay
- 1:28:26and let's execute this so here you'll be
- 1:28:29able to see that I'm able to see
- 1:28:30multiple information like four documents
- 1:28:32has been over here so let's take the
- 1:28:35first document and let's see how the
- 1:28:37result is so here I'm going to basically
- 1:28:39take zero and inside that the field name
- 1:28:42is nothing but page content so I'm going
- 1:28:44to basically write my page content now
- 1:28:47here you'll be able to see Pro provided
- 1:28:48proper attribution is provided Google
- 1:28:50here by Grand permission and here you'll
- 1:28:53be able to see go gole brain all the
- 1:28:55email IDs all the researchers names are
- 1:28:58actually available so that basically
- 1:29:00means it is able to resear uh it is able
- 1:29:02to retrieve the results of the all the
- 1:29:05scientists who are involved all the
- 1:29:06researchers who are involved in creating
- 1:29:07this particular paper um I can also do
- 1:29:10one more thing I can go ahead and write
- 1:29:12what is
- 1:29:14attention uh is all you need okay
- 1:29:18attention is all you need Okay so let's
- 1:29:22see what kind of results I will be able
- 1:29:24to get and understand this is entirely
- 1:29:26rag pipeline which is being able to come
- 1:29:28from the entire documentation and here
- 1:29:30you'll be able to see that result is
- 1:29:31also coming uh let me do uh write
- 1:29:35something which is available in the
- 1:29:36research paper so let me open my
- 1:29:39research paper over here and let me ask
- 1:29:41some question directly okay from here
- 1:29:43you'll be able to see see when I'm
- 1:29:45searching attention is all you need it
- 1:29:47is coming from here itself right so let
- 1:29:49me use something over here m
- 1:29:55uh let me just write over here encoder
- 1:29:58is uh what is an attention function let
- 1:30:01me just go and search this okay let's
- 1:30:03see attention is something something
- 1:30:05some text is there over here so if I go
- 1:30:08ahead and execute
- 1:30:09it and here you'll be instead of
- 1:30:11performing a single attention function
- 1:30:13with the model Dimension values keys and
- 1:30:15all the information is basically coming
- 1:30:17up right and here is a very good result
- 1:30:19and this is directly coming from the
- 1:30:20vector database that is the most amazing
- 1:30:22thing over here right now you may be
- 1:30:24also thinking chish can we also use the
- 1:30:26F database fire deped database that we
- 1:30:29have used right so let me just show you
- 1:30:30with respect to that also F and here I'm
- 1:30:34going to use the fire Vector database
- 1:30:36and this will also give you an idea how
- 1:30:38you can actually store that embeddings
- 1:30:39into F database itself and we'll also do
- 1:30:43that so here I'm going to write from
- 1:30:44Lang
- 1:30:45chain Lang chain
- 1:30:48uncope
- 1:30:49Community do Vector stores I'm going to
- 1:30:54import my FIS F and then I'm going to
- 1:30:59also use TB is equal to FIS Dot from
- 1:31:04documents the same thing right so from
- 1:31:06underscore documents and here I'm going
- 1:31:09to use my documents okay and let's say I
- 1:31:14go ahead and do the embedding for the
- 1:31:16first 20 documents and then here also
- 1:31:18I'm going to use my open biddings and I
- 1:31:21think this is also my another DB so I
- 1:31:23will write it it at DB1 which is my f
- 1:31:26database okay uh from documents okay no
- 1:31:29worries uh so here the spelling mistake
- 1:31:31was there and I think this will also
- 1:31:33work now DB1 is also ready and what I
- 1:31:35can do I can use the same thing and
- 1:31:37paste it over here okay and just write
- 1:31:40DB1 do similarity search and here you
- 1:31:43can see instead of performing a single
- 1:31:44attention everything is probably coming
- 1:31:46up so I've just shown you the example of
- 1:31:49both F and uh chroma database chroma
- 1:31:53Vector database as I said one assignment
- 1:31:56will be given to you is regarding Lance
- 1:31:59Vector database you can go and search it
- 1:32:01for that in the in the in the langin
- 1:32:03documentation we are going to continue
- 1:32:05the langin series and now we will be
- 1:32:07developing Advanced rag pipeline using
- 1:32:10Retriever and chain Concepts that are
- 1:32:11available in Lang chain now before I go
- 1:32:14ahead I really want to talk about a
- 1:32:15funny incident that really happened uh
- 1:32:18recently just today itself so what I did
- 1:32:21what I do is that every day morning I
- 1:32:22usually go and play some badminton you
- 1:32:24know I play for one hours one and a half
- 1:32:26hour and usually a lot of my friends and
- 1:32:28neighbors usually come and play you know
- 1:32:30so today what happened after playing I
- 1:32:32went today in this look okay I played
- 1:32:34around three to four games and then one
- 1:32:36of my neighbors said hey Krish you're
- 1:32:39Kish right you just got identified right
- 1:32:41now just by seeing your should I
- 1:32:43identified you but your look has
- 1:32:44completely changed so let me know if
- 1:32:46this is true in the comment section of
- 1:32:47this particular video but I am liking
- 1:32:49this look uh you know it's like so much
- 1:32:53of less maintenance you don't have to
- 1:32:54maintain your beard your mustac or your
- 1:32:57hair also right it looks super cool now
- 1:33:00let's go ahead and uh work towards this
- 1:33:03specific project in our previous
- 1:33:05tutorial what we had actually done is
- 1:33:07that we had created this simple rack
- 1:33:09pipeline okay we had a data data source
- 1:33:13like we took PDF we took website then we
- 1:33:17uh load that particular data set using
- 1:33:19different different data injection
- 1:33:20techniques that were available in Lang
- 1:33:22chain then we did transformation wherein
- 1:33:25we broke down our bigger PDFs into
- 1:33:28chunks and then we converted all this
- 1:33:31particular chunks into vectors and
- 1:33:33stored it in a vector store and then
- 1:33:35with the help of query we are able to
- 1:33:38probably retrieve some of the data that
- 1:33:40is available in the vector store now
- 1:33:42this is one step now the further step
- 1:33:44after this particular query Vector Now
- 1:33:46understand query Vector are not that
- 1:33:48efficient you know when in terms of
- 1:33:50retrieving the entire results here we
- 1:33:53will also specifically used llm models
- 1:33:56okay so now what we will try to do is
- 1:33:58that using some prompts okay and we will
- 1:34:03take this specific prompts we will take
- 1:34:05this particular data using the concept
- 1:34:07of chain and retriever okay and
- 1:34:11understand this topic is very important
- 1:34:14because this is where your Advanced rack
- 1:34:17pipeline implementation will start using
- 1:34:19chain and retriever we will also use and
- 1:34:22in this chain and retriever what we do
- 1:34:24is that we specifically use llm models
- 1:34:26it can be open source it can be paid
- 1:34:29whatever model you want so we will
- 1:34:31specifically use this llm model and
- 1:34:33based on this prompt we will try to get
- 1:34:35the response on what we are specifically
- 1:34:38looking right so there will be a lot of
- 1:34:40customization that will be added once we
- 1:34:43implement this specific part in the
- 1:34:44first part we discussed about this and
- 1:34:47this is the second part that we are
- 1:34:48going to discuss okay how we can use
- 1:34:51chain how we can use retriever what
- 1:34:53exactly is chain how you can integrate
- 1:34:55in this particular llm model there is a
- 1:34:57concept of something called as stuff
- 1:34:59document chain what exactly it is so we
- 1:35:01will discuss everything all about it and
- 1:35:04here we also going to do a practical
- 1:35:06implementation so please make sure that
- 1:35:08you watch this video till the end and we
- 1:35:10are going to learn a lot of things okay
- 1:35:12so here the first step what we had done
- 1:35:14on already uh we have implemented this
- 1:35:17in our previous tutorial also so here
- 1:35:19you'll be able to see that I'm trying to
- 1:35:21read attention. PDF which is Pres
- 1:35:23present in a folder and then we just
- 1:35:25write loader. load and we get the
- 1:35:27documents okay so these are all the
- 1:35:29documents that will be available in this
- 1:35:31specific PDF okay then what we are
- 1:35:34specifically doing next step is that
- 1:35:35from lin. text plat we will be using
- 1:35:38recursive character text plater wherein
- 1:35:40we convert the entire document into
- 1:35:41chunks right and then we are probably
- 1:35:44using this text splitter and we are
- 1:35:47using a chunk size of th000 overlap of
- 1:35:4920 so this everything is implemented in
- 1:35:51my previous videos right so we are going
- 1:35:53going to split this entire document and
- 1:35:55save it in this particular documents in
- 1:35:57the previous tutorial we have
- 1:35:58implemented all these things now here
- 1:36:00what we are going to take do now we'll
- 1:36:02take all these documents and then we
- 1:36:04will convert it into a vector store
- 1:36:06right so Vector store for that we are
- 1:36:08using this F okay so here we are going
- 1:36:11we can use AMA embedding or open AI
- 1:36:13embedding right as I said you open AI
- 1:36:15embedding is very much Advanced and it
- 1:36:17will perform better than AMA embedding
- 1:36:20if you don't have opening a API key use
- 1:36:22Ama eming emding instead of open AI
- 1:36:25embedding over here you can just write
- 1:36:26AMA embedding right so from here I'll be
- 1:36:29using F which is again a kind of vector
- 1:36:31store and it has been developed by meta
- 1:36:34so fest. from documents document of 20
- 1:36:36so I'm just taking the first 20
- 1:36:38documents and I'm just writing open a
- 1:36:40biddings let's make it to 30 so that it
- 1:36:42will have some amount of data right now
- 1:36:45we are specifically using open AI
- 1:36:47bidding and this DB that you
- 1:36:48specifically see is a my Vector store
- 1:36:51okay so here you can see vector store f
- 1:36:54f of type okay perfect
- 1:36:57now any question that I ask attention
- 1:37:00function can be described as a mapping
- 1:37:02query and then we can take this Vector
- 1:37:03store and just write do similarity
- 1:37:05search on this query and we will get the
- 1:37:07result over here okay so this all things
- 1:37:10we have actually done in our previous
- 1:37:12video now is the most important thing
- 1:37:14how I can combine prompt along with
- 1:37:17chains and Retriever and then probably
- 1:37:20get a response based on the prompt okay
- 1:37:22so say since many people have the use of
- 1:37:25only open source uh they have the access
- 1:37:27of Open Source model llm model so I'm
- 1:37:30going to use AMA from lin. community.
- 1:37:32llms import olama then I'm going to use
- 1:37:35AMA over here model will be Lama 2 if
- 1:37:38you don't have Lama 2 just to go to
- 1:37:40command prompt after downloading AMA I
- 1:37:42hope everybody knows how to download it
- 1:37:44if you're seeing my series of videos
- 1:37:46here you can just write AMA run Lama 2
- 1:37:49right so once you write like this then
- 1:37:51the model will get downloaded right if
- 1:37:53it is already downloaded it will be
- 1:37:54coming something like this okay so this
- 1:37:57is the first step that you really need
- 1:37:58to do then I have written from lin.
- 1:38:00community. LM AMA load AMA so whatever
- 1:38:04AMA model we are specifically using that
- 1:38:06is Lama 2 so this is my open source
- 1:38:08model so if you see Lama llm it is
- 1:38:10nothing but AMA now is the time we will
- 1:38:13start designing our prompt template now
- 1:38:16in order to design the chat prompt
- 1:38:17template I will be using CH linore core.
- 1:38:21prompts import chat prompt template okay
- 1:38:23and then from chat pron template from
- 1:38:25template I'm just writing like this so
- 1:38:27I'm saying answer the following question
- 1:38:30based only on the provided context now
- 1:38:33see we are trying to develop a Q&A Q&A
- 1:38:36chatboard based on the context it should
- 1:38:38provide me the response
- 1:38:40previously what we are doing using
- 1:38:42Vector store we used to if you see the
- 1:38:46code over here we used to query the
- 1:38:48vector score right Vector store by using
- 1:38:50similarity search algorithm but here
- 1:38:52what we are doing here we are defining
- 1:38:54our own prompt and we saying hey answer
- 1:38:57the following question based on the
- 1:38:58provided context right I will and simply
- 1:39:01I'm writing away I'll tip you $1,000 if
- 1:39:04you find the answer helpful okay if the
- 1:39:06user find the answer helpful okay just
- 1:39:09at least by seeing money the AI May
- 1:39:11perform well and then we are giving our
- 1:39:13context and then question will be input
- 1:39:15okay how why I'm writing in this
- 1:39:18specific way because this chain and
- 1:39:19retriever right you'll be understanding
- 1:39:21this context will be autofilled and this
- 1:39:23input will also get autofilled okay how
- 1:39:25it will get autofilled I'll let you know
- 1:39:27so now what I will do I will execute
- 1:39:29this now I will go ahead and Implement
- 1:39:31about chain uh it is always a good idea
- 1:39:36okay to probably go to your browser and
- 1:39:39check about each and every topic that
- 1:39:41I'm explaining so what does chain refer
- 1:39:43to chain referred to a sequence of calls
- 1:39:46whether to an llm tool or data
- 1:39:49pre-processing step the primary
- 1:39:51supported way to do this is lcf okay now
- 1:39:54if you talk about chain over here there
- 1:39:57are multiple functions with respect to
- 1:39:59chain one of the function that I'm am
- 1:40:01going to use is create stuff document
- 1:40:03chain now what this exactly does this
- 1:40:06chain takes a list of documents and
- 1:40:08formats them into all into a prompt then
- 1:40:12passes that prompt to an
- 1:40:14llm see this this chains take a list of
- 1:40:17documents and formats them based on the
- 1:40:19prompt formats them into a prompt sorry
- 1:40:22not based on the prompt into the the
- 1:40:23problem that basically means over here
- 1:40:26if I go ahead and open my
- 1:40:29browser here in the context I definitely
- 1:40:32require my document sour self right
- 1:40:35based on that context and based on this
- 1:40:37input I will be able to give the answer
- 1:40:39right so based on this context and based
- 1:40:40on the input right context basically
- 1:40:42means all the documents that are there
- 1:40:44available in the vector store right
- 1:40:47inputs are what question I'm asking
- 1:40:49right so with the help of this create
- 1:40:52stuff document chain what is basically
- 1:40:54happening this chain takes a list of
- 1:40:56documents and formats them all into a
- 1:40:58prompt then passes that prompt to an llm
- 1:41:01it passes all the documents so that you
- 1:41:02should make sure that it fits within the
- 1:41:04context window the llm you are using so
- 1:41:07what it is exactly doing it will take up
- 1:41:08all the documents from the vector store
- 1:41:10it will put that put inside that
- 1:41:11particular prom template and then it
- 1:41:13will send the to the llm and then we
- 1:41:15finally get the response okay and that
- 1:41:17is what we'll be using similarly there
- 1:41:19are different different uh things also
- 1:41:21over here like create stuff document
- 1:41:23change is there create SQL query chain
- 1:41:25if you're working with respect to SQL
- 1:41:26database for natural language and this
- 1:41:28is one of the very important project
- 1:41:30that I'll also do in the future one or
- 1:41:32the other way I'll try to use one or the
- 1:41:35other functionalities to just make you
- 1:41:37understand how we can use all this
- 1:41:39functionalities itself right but it is
- 1:41:41always good that we have a specific use
- 1:41:44case okay now if I open this okay let's
- 1:41:48go ahead and create my chain how do I
- 1:41:50create my chain over here again it's
- 1:41:52very simple so so I will write from Lang
- 1:41:55chain Lang chain _ community so it is
- 1:41:58present inside Community itself or not
- 1:42:00Community sorry chains Lang chore chains
- 1:42:04dot combine
- 1:42:08documents
- 1:42:09import create Stu document chain now how
- 1:42:13do I know this okay I did not create
- 1:42:15this I have already seen the
- 1:42:17documentation okay that is the reason
- 1:42:18I'm writing then I will go ahead and
- 1:42:20create my document chain now inside this
- 1:42:24document chain as I said I'll be using
- 1:42:26create stuff document chain okay that we
- 1:42:29have already seen now inside this chain
- 1:42:31two things are basically required one is
- 1:42:34the llm model and the second one is the
- 1:42:37prompt that I have created because
- 1:42:40inside this prompt itself the list of
- 1:42:42documents will be added right whatever
- 1:42:44documents is basically coming from here
- 1:42:46right from my Vector store that will be
- 1:42:48added over here okay so once I create
- 1:42:51this so This basically becomes my
- 1:42:53document chain okay very much simple now
- 1:42:57after this we also have to learn about
- 1:42:59one very important thing which is called
- 1:43:01as
- 1:43:03retrievers okay so I will go ahead and
- 1:43:05write something called as
- 1:43:09retriever retriever Lang chain okay now
- 1:43:12what exactly retriever Lang chain is it
- 1:43:15is an interface that recur document
- 1:43:17given an unstructured query it is more
- 1:43:20General than a vector store right a
- 1:43:23retriever does not need to be able to
- 1:43:25store the documents only to return or
- 1:43:27retrieve them Vector store can be based
- 1:43:29as the backbone of the retriever now see
- 1:43:32there is a vector store which is having
- 1:43:34some information some Vector stored in
- 1:43:36it right if I want to take out any data
- 1:43:39from there right I can actually do a
- 1:43:41similarity search which we have already
- 1:43:42seen okay but langen what it did is that
- 1:43:46since we usually do a lot of programming
- 1:43:48in a way right where in classes are used
- 1:43:51interfaces are used so it created a
- 1:43:53separate interface which is called as
- 1:43:55Retriever and that interface has a
- 1:43:58backend source to that particular Vector
- 1:44:00store to retrieve any information right
- 1:44:04whenever a query is given right that
- 1:44:06entire Vector store will be passing the
- 1:44:09information through this retriever okay
- 1:44:11so what we will do is that here I will
- 1:44:15quickly open this I have also written
- 1:44:17some amount of description so that it
- 1:44:19will be helpful for you whenever you
- 1:44:22probably go go ahead and check it this
- 1:44:24entire materials okay so now what I will
- 1:44:26do I will just go ahead and write DB
- 1:44:30dot DB dot as retriever now once I do
- 1:44:35like this DB do as retriever this
- 1:44:37basically has become my retriever right
- 1:44:41so what we have done DB is our Vector
- 1:44:43store already it is there we have
- 1:44:45connected to an interface which is
- 1:44:47basically this particular variable now
- 1:44:49okay so if you go ahead and ex uh
- 1:44:53probably display this what is retrieval
- 1:44:55it is nothing but it is a vector store
- 1:44:56retrieval internally you'll be also able
- 1:44:59to see that what all it is implemented F
- 1:45:01and open AI Mings and all all the
- 1:45:03information are there now retriever is
- 1:45:05done chain is also done okay now is the
- 1:45:08time that what I will do I will try to
- 1:45:11use this Retriever and document chain
- 1:45:14both together to probably see when we
- 1:45:17combine both of them then only we'll be
- 1:45:19able to get the response right so with
- 1:45:23respect to this now let's go ahead and
- 1:45:25create my retriever chain okay so the
- 1:45:29next step is what since I need to
- 1:45:31combine both of them one is Retriever
- 1:45:34and one is the document chain right this
- 1:45:37document chain is responsible for
- 1:45:38putting the information in the context
- 1:45:40when we combine both of them then it
- 1:45:42becomes a retriever chain now what is
- 1:45:43the definition this chain takes an input
- 1:45:46as a user inquiry which is then passed
- 1:45:49to the retriever to fetch the relevant
- 1:45:51documents so it passes through the
- 1:45:53retriever it is connected to the vector
- 1:45:54store then those documents are then
- 1:45:57passed to an llm to generate the
- 1:45:58response and this llm that we are
- 1:46:01basically getting it it is basically
- 1:46:02coming from what this document chain
- 1:46:05understand the flow okay so let me just
- 1:46:07go ahead and mention this flow again so
- 1:46:10that it becomes very much easy for you
- 1:46:12so whenever the
- 1:46:14users this is my user okay whenever the
- 1:46:18user asks for any
- 1:46:20inquiry okay any inquiry so first what
- 1:46:24it is going it is going to this
- 1:46:26retriever okay very much important okay
- 1:46:29so this is my retriever this retriever
- 1:46:32is an interface to what Vector store
- 1:46:36which has all the information right so
- 1:46:38once we basically get the retriever then
- 1:46:40the next step what it happens it goes to
- 1:46:43what it goes to my llm model with some
- 1:46:47prompt right there will be some prompt
- 1:46:50involved to this and how this is
- 1:46:52basically happening
- 1:46:54with the help of stuff document
- 1:46:57chain so this stuff document chain has
- 1:47:00already both these things combined llm
- 1:47:03and prompt right and then finally we get
- 1:47:06our
- 1:47:08response I hope you're able to
- 1:47:10understand this right and this is what
- 1:47:11we have basically implemented over here
- 1:47:13now how to basically create a retriever
- 1:47:15chain so first for for all of this again
- 1:47:19I will be using a library um with
- 1:47:21respect to chains okay okay so form Lang
- 1:47:26chain Lang
- 1:47:28chain dot
- 1:47:30chains
- 1:47:32import create retrieval chain right and
- 1:47:36there are lot of things create QA with
- 1:47:38Source chain retrieval chain this chain
- 1:47:41that chain I will try to explain you all
- 1:47:43of things don't worry okay I will cast
- 1:47:45the right kind of use case and I will be
- 1:47:49showcasing you all these things don't
- 1:47:51worry about that okay then what I will
- 1:47:53do I will I will take this entire create
- 1:47:55retrieval chain and then I will create
- 1:47:58my uh retrieval chain so here I will
- 1:48:01write
- 1:48:03retrieval chain is equal
- 1:48:06to create retrieval chain and here I'm
- 1:48:09going to use first parameter that I'm
- 1:48:11going to use is retriever then the
- 1:48:13second parameter is nothing but document
- 1:48:15chain so once I have this chain right
- 1:48:18now I will be able to invoke any queries
- 1:48:21so I will go ahead and write retrieval
- 1:48:23chain dot invoke okay and now what are
- 1:48:28the parameters that I have to give
- 1:48:30nothing I have to give my input so the
- 1:48:33input will be given over here colon and
- 1:48:36whatever input that I can give let's say
- 1:48:39from the PDF I have put some input over
- 1:48:42here let me just copy and paste it okay
- 1:48:45so this is one of the text that is
- 1:48:46available in the PDF that is attention.
- 1:48:48PDF and now if I invoke this you'll be
- 1:48:51able to see that I will be able to get
- 1:48:53the entire response okay so retrieval do
- 1:48:56chain. invoke and again we are using
- 1:48:58open source llm model that is Lama 2
- 1:49:01okay yeah I've used open EMB bidding so
- 1:49:03here you can see this is my input this
- 1:49:05was the context right all the context
- 1:49:08information is there and finally I get
- 1:49:09the answer and this answer I will just
- 1:49:12try to save it over here something like
- 1:49:17response uh res
- 1:49:20response okay and then I will execute
- 1:49:26response response of answer so this
- 1:49:29finally becomes the my output that is
- 1:49:32probably coming over here okay so this
- 1:49:33if I execute it the answer to the
- 1:49:35question is right and all the
- 1:49:38information you can see the answer to
- 1:49:40the question and it is retrieving all
- 1:49:42the details right so here you'll be able
- 1:49:45to see that how beautifully with the
- 1:49:47help of llm we have constructed this
- 1:49:49entire thing and we have used this
- 1:49:52chains Retriever and this is the first
- 1:49:54step towards developing your Advanced
- 1:49:56rack pipeline right so whatever question
- 1:49:59you ask let me just open this and
- 1:50:01probably show you some more examples
- 1:50:04okay so what I will do I will just open
- 1:50:07my download
- 1:50:09page let's see my download page I'll ask
- 1:50:13for any statement okay just a second um
- 1:50:18attention Okay so this is my
- 1:50:21thing uh let me just go ahead and search
- 1:50:24for
- 1:50:25anything the decoder is the this and
- 1:50:28this okay so I'll be searching from here
- 1:50:30to here okay now let me go ahead and
- 1:50:34change my
- 1:50:36input and search for it so chain. invoke
- 1:50:40I've done and here I've got the response
- 1:50:44now let me just go and I uh the answer
- 1:50:46to this question is
- 1:50:48six um the decoder is also composed of
- 1:50:51stack of n6 oh it has basically taken
- 1:50:53this no worries okay let's take some
- 1:50:55more
- 1:50:58thing I'll write scaled do product
- 1:51:02attention some more
- 1:51:08examples oops uh
- 1:51:12error okay just a second now I think it
- 1:51:17should not
- 1:51:20be okay it is taking that question and
- 1:51:23it is trying to form some answers out of
- 1:51:25it
- 1:51:25okay got it got it it is not a mistake I
- 1:51:29thought it was a mistake out there scale
- 1:51:31is a type of this this this see I'm
- 1:51:33getting all the answers over here uh we
- 1:51:35are going to continue the Lang chain
- 1:51:37series and in this video we are going to
- 1:51:39probably develop an amazing multi-search
- 1:51:41agent rag application um what exactly is
- 1:51:44the project all about what all new
- 1:51:46things we are going to specifically
- 1:51:48learn and probably I think this is the
- 1:51:50most amazing thing that has been
- 1:51:52inserted in the Lang chain Library
- 1:51:54itself some of the amazing modules that
- 1:51:56are there which will actually help you
- 1:51:58to make your entire conversational
- 1:51:59chatbot quite amazing itself right so
- 1:52:02let me go ahead and discuss about this
- 1:52:04what what exactly we are going to do
- 1:52:05what kind of projects we are going to
- 1:52:06implement here so let's consider that I
- 1:52:09want to generate a gen AI powered llm
- 1:52:12application so this is my llm
- 1:52:13application that I really want to
- 1:52:15generate and this let's consider that it
- 1:52:17has dependencies on some of the other
- 1:52:20open source platforms or other websites
- 1:52:22all the data sources itself right like
- 1:52:24like RVE R if you don't know like all of
- 1:52:27the research papers that are available
- 1:52:28will be available over here if I
- 1:52:30probably consider with respect to
- 1:52:31Wikipedia right Wikipedia also has a
- 1:52:33huge amount of content similarly I may
- 1:52:35also have let's say my own company's PDF
- 1:52:38you know from where I also need to
- 1:52:39probably develop our Q&A applications
- 1:52:42right so all these things we will
- 1:52:43probably try to implement it now the
- 1:52:46main thing is that here you have
- 1:52:47multiple data sources and you really
- 1:52:49want to integrate all them as a rapper
- 1:52:52so that you'll be able to implement this
- 1:52:54entire Q&A solution right over here so
- 1:52:57here you're also going to learn about
- 1:52:58some new terms and right now it is
- 1:53:00becoming very popular like tools right
- 1:53:03tools what are tools in Lang chain what
- 1:53:05are agents in Lan chain what are
- 1:53:07toolkits we'll also be learning about
- 1:53:09toolkits right and how do you probably
- 1:53:12create a wrapper on top of this
- 1:53:13particular toolkits but if I just want
- 1:53:16to give a small brief introduction about
- 1:53:18tools you can see that here I have
- 1:53:20dependency on this platform on this plat
- 1:53:22I can probably use all these platforms
- 1:53:25as a separate tool so that I'll be able
- 1:53:27to ask any questions from this
- 1:53:29particular platform itself along with
- 1:53:31that I may also have my own customized
- 1:53:33PDF own custom data which will also be
- 1:53:35in the form of vector embeding so what I
- 1:53:38will do is that I will try to wrap this
- 1:53:39up in the form of toolkit and then with
- 1:53:42the help of Agents I will be able to
- 1:53:44execute any Q&A search that I really
- 1:53:46want to do it yes I have probably told a
- 1:53:49lot of terms and topics over here but
- 1:53:51let's go ahead and let's see how we can
- 1:53:52can actually implement it and all this
- 1:53:54implementation that you will probably be
- 1:53:56seeing will be quite amazing lot of
- 1:53:58learnings will be specifically there and
- 1:54:00you will definitely be able to learn
- 1:54:02many things out of it okay so let me
- 1:54:04quickly go ahead and open my uh code
- 1:54:08file and I will continue the same code
- 1:54:09file that I had actually implemented
- 1:54:11earlier itself right uh one more very
- 1:54:14important thing that I really want to
- 1:54:15talk about is that uh if you remember I
- 1:54:17have uploaded five videos till now and
- 1:54:20all those videos are with respect to
- 1:54:21some different different applications
- 1:54:23right and that is how we should
- 1:54:25definitely learn all these topics so
- 1:54:27that we can actually get an efficient
- 1:54:28way of how things are basically getting
- 1:54:30used okay so as usual what I'm actually
- 1:54:33going to do is that let me go ahead and
- 1:54:35search for Lang chain tools okay so here
- 1:54:38you you if you able to see here you have
- 1:54:41something called as Lang chain tools so
- 1:54:43tools are interfaces that an agent chain
- 1:54:46or llm can interact with the world right
- 1:54:48so if I really want data from some other
- 1:54:50data sources uh some other queries that
- 1:54:53I have you can also include Google
- 1:54:54search API over here and lot of tools
- 1:54:56are specifically given by uh lanin
- 1:54:58itself you know we have to really create
- 1:55:00a rapper and then we will be able to
- 1:55:02have a conversation with them so some of
- 1:55:04the examples with respect to the tool
- 1:55:05like what all tools are specifically
- 1:55:07provided you'll be able to see in langin
- 1:55:10these are all the built-in tools that
- 1:55:11you have Alpha Vantage fi R sa AWS
- 1:55:15Lambda Bing search Brave search Chat GPD
- 1:55:19plugins you know D image generator you
- 1:55:21can also able to generate images then
- 1:55:23you have Eden AI file system golden
- 1:55:25query Google Finance Google jobs Google
- 1:55:28Lens Google Places Google scholer Google
- 1:55:31search Google serer so you can probably
- 1:55:33use any of these particular tools to
- 1:55:35extract some of the data that you want
- 1:55:37let's say that I am planning to create a
- 1:55:40chatbot which will be research more
- 1:55:42oriented and I will probably ask
- 1:55:43questions that will be related to
- 1:55:45different topics research and all other
- 1:55:47than that I will also try to create a
- 1:55:49rapper on top of Wikipedia and along
- 1:55:51with that my under the customized uh PDF
- 1:55:54files okay so I will try to include all
- 1:55:56those thing and you can use any of this
- 1:55:58that you want based on your use cases
- 1:56:00but I will try to show you an
- 1:56:02application how I will go ahead with
- 1:56:04okay so let me quickly open a new folder
- 1:56:06over here so I will go ahead and create
- 1:56:08a folder and let me go ahead and write
- 1:56:10agents over here as my folder name and I
- 1:56:13am going to create a file which is
- 1:56:15called as agents. iynb file okay now
- 1:56:19inside this particular file I will go
- 1:56:21ahead and select my step by step I will
- 1:56:23try to show it to you how things will be
- 1:56:25working in this and how I'm going to
- 1:56:27build this entire thing okay so the
- 1:56:29first thing as usual uh as I said that I
- 1:56:31will be requiring uh RF so you have to
- 1:56:34probably go ahead and install this so I
- 1:56:37will go ahead and write pip install RF
- 1:56:39so okay dou S no worries so I will go
- 1:56:42ahead and install it it'll go it'll get
- 1:56:44installed in my V EnV environment once
- 1:56:47this is basically getting installed what
- 1:56:48I'm going to do is that I'm going to use
- 1:56:50Wikipedia I'm going to use also and I'll
- 1:56:53create as a rapper okay so first of all
- 1:56:55let's go ahead and create a rapper on
- 1:56:57top of Wikipedia so for that what I will
- 1:56:59do I will go ahead and write from Lang
- 1:57:01chain uh Lang chain undor community so
- 1:57:05it will be present inside this community
- 1:57:07itself all the tools that are available
- 1:57:09uh within the Lang chain itself then I'm
- 1:57:12going to import
- 1:57:14Wikipedia
- 1:57:16Wikipedia query run okay so I'm going to
- 1:57:20just write Wikipedia query run I hope
- 1:57:22this works let's see whether this works
- 1:57:24or not okay this is my Lang chore
- 1:57:27Community but I think it should be
- 1:57:29working now um from lin. community.
- 1:57:31tools import Wikipedia or query run
- 1:57:35along with this what I'm going to write
- 1:57:36from langin I'm also going to create a
- 1:57:39use some rapper class on top of it do
- 1:57:43utilities utilities
- 1:57:46import
- 1:57:48Wikipedia API rapper okay so I'm going
- 1:57:51to specific Al use this two things over
- 1:57:53here one is the Wikipedia query run and
- 1:57:55Wikipedia API rapper okay for Wikipedia
- 1:57:58you don't require a separate API itself
- 1:58:00already Lang chain is taking care of
- 1:58:02that so if I go ahead and write uh and
- 1:58:04probably execute this Wikipedia API
- 1:58:07wrapper I will say hey provide me the
- 1:58:09top K results right so how many results
- 1:58:11I want let's say I want one so I'll go
- 1:58:14ahead and write document uh content Car
- 1:58:16Max Max to Max I will probably require
- 1:58:19200 characters okay from whatever search
- 1:58:21I actually do from Wikipedia you can
- 1:58:23increase it so this will basically be my
- 1:58:25wrapper itself API wrapper okay so this
- 1:58:28in short is interacting with the
- 1:58:30Wikipedia to find out the so many number
- 1:58:32of results so this is basically giving
- 1:58:33some configuration details over here the
- 1:58:36next will be my tool as I said I will be
- 1:58:38using my Wikipedia query run tool okay
- 1:58:42and then this will be initialized and
- 1:58:43here I'm going to initialize my API
- 1:58:45wrapper with the API rapper that I've
- 1:58:48defined over here okay so this is what
- 1:58:50is my tool over here so I'm getting some
- 1:58:53error could not import Wikipedia python
- 1:58:55package please install it with Pip
- 1:58:57install Wikipedia so I will go over here
- 1:59:00and requirement. txt I will go ahead and
- 1:59:03write Wikipedia okay I will be requiring
- 1:59:05this Library along with this as I said
- 1:59:08I'm going to import also RF okay so let
- 1:59:11me quickly go ahead and open my terminal
- 1:59:13and I will start the installation over
- 1:59:15here okay so let me go ahead and write P
- 1:59:18install minus r requirement. txt so both
- 1:59:22these libraries will get installed that
- 1:59:23I specifically want initially you
- 1:59:25actually require it whatever is there
- 1:59:28the packages are available and Lang
- 1:59:29chist trying to integrate with that and
- 1:59:31that is the most amazing thing over here
- 1:59:33okay so now I don't think so we should
- 1:59:34be getting an error so now it looks good
- 1:59:37now if you go and write tools over here
- 1:59:39or tool tool name over here so here you
- 1:59:42can see Wikipedia query run if I go
- 1:59:44ahead and write tool. name you'll be
- 1:59:46able to see Wikipedia is my uh tool name
- 1:59:48okay now this is one of the tool
- 1:59:51similarly what I I will uh probably do
- 1:59:53is that I will also uh take a website or
- 1:59:57a PDF whatever it is right I will read
- 2:00:01all those kind of PDF okay so that I
- 2:00:03will also consider that as a data source
- 2:00:05so let me do one thing let me I will
- 2:00:08probably create another tool over here
- 2:00:09okay so let's see over here I will go
- 2:00:12ahead and go to this website okay so let
- 2:00:16me just see this website uh I've just
- 2:00:19copied this okay so this website this
- 2:00:23website okay so this is the website that
- 2:00:26I will also be using and I'll try to
- 2:00:27retrieve the content from here also so
- 2:00:30in order to read this content from this
- 2:00:32particular website I will be using
- 2:00:33web-based loader as you all know we have
- 2:00:36also discussed about that because that
- 2:00:37is also one of the data injection thing
- 2:00:39right so I will write from Lang chain
- 2:00:43community. document loaders and here I'm
- 2:00:46going to specifically import web based
- 2:00:49webbased loader okay along with this uh
- 2:00:52as you all know since I'm reading the
- 2:00:53content I will be using F I'll be using
- 2:00:55open AI Bings and all so let me copy it
- 2:00:58from here and let me paste it over here
- 2:01:00okay so I'll be using F I'll be using
- 2:01:02open a Bings I'll be using recursive uh
- 2:01:05character text splitter so that I'll be
- 2:01:07able to divide all those into chunks
- 2:01:09also so everything will be used over
- 2:01:11here in this particular case and one
- 2:01:13thing that you really need to understand
- 2:01:15why we are doing this because this is my
- 2:01:17own custom data let's consider this as
- 2:01:19my own custom data I need to probably
- 2:01:21convert this into a vectors so here I
- 2:01:23will go ahead and load my loader and
- 2:01:26here I will be using webbased loader and
- 2:01:28I will give my URL the URL that I had
- 2:01:30actually got from here so this URL will
- 2:01:34be basically reading the entire page
- 2:01:36okay once I probably get the loader.
- 2:01:39load okay uh loader. load it will load
- 2:01:43the entire content from that particular
- 2:01:44website so this will be my docs okay
- 2:01:48after getting the docs the next thing
- 2:01:50that I will do is my recursive character
- 2:01:52split okay and here I'm going to
- 2:01:55specifically use some Chun size so this
- 2:01:58will basically be my chunk underscore
- 2:02:01chunk uncore size is equal to
- 2:02:05th000 uh and then I will also be writing
- 2:02:08chunk uncore overlap which will be
- 2:02:10nothing but 200 okay so this is some
- 2:02:12default configuration I have actually
- 2:02:14taken in this um and then uh I will also
- 2:02:18write do splitcore documents I will
- 2:02:21split all all these documents that are
- 2:02:22available inside this docs okay and I
- 2:02:26will finally get my documents itself
- 2:02:29okay and this we have already done it
- 2:02:31many number of times I think in my
- 2:02:32previous tutorial also then I will go
- 2:02:34ahead and create my DB my Vector DB so I
- 2:02:37will go ahead and write Vector DB Vector
- 2:02:40DB and here I'm going to specifically
- 2:02:43write
- 2:02:44F FES do from
- 2:02:48documents from documents and and here
- 2:02:52I'm going to give my
- 2:02:54documents comma my openings that I'm
- 2:02:58specifically going to use for this
- 2:02:59purpose right and later on if I really
- 2:03:01want to convert this Vector database
- 2:03:03into retriever all I have to write is
- 2:03:05Vector DB do as
- 2:03:09retriever as retriever if you don't know
- 2:03:13what is retriever it is an interface
- 2:03:15which will be able to retrieve the
- 2:03:17result from this particular Vector
- 2:03:18database right so here will be my
- 2:03:21retriever right so this is my second
- 2:03:23important thing so let me go ahead and
- 2:03:25write
- 2:03:28retriever retriever okay so I've done
- 2:03:31I've created one tool I've created one
- 2:03:33retriever tool is for Wikipedia but
- 2:03:36still I have I also installed RV right
- 2:03:38so I'm also going to use RV for the same
- 2:03:40purpose first let's uh all this
- 2:03:43particular thing happen now you have
- 2:03:44that Victor um the vector store
- 2:03:47retriever completely over here okay now
- 2:03:50uh the next thing uh that I am probably
- 2:03:53going to do over here is that I will
- 2:03:55take this Retriever and use create
- 2:03:56retriever tool so that I can actually
- 2:03:59make it as a uh as a as a in short like
- 2:04:02if I really want to ask any question I
- 2:04:04really need to make this retriever as a
- 2:04:06create retriever tool okay so if you go
- 2:04:09ahead and search for Lang
- 2:04:11chain for Lang chain create
- 2:04:15retrieval create retriever tool okay so
- 2:04:20here you'll be able to see that this is
- 2:04:22what we are going to specifically use
- 2:04:24and create retriever tool you can see
- 2:04:26create a tool to do retrieval of all the
- 2:04:28documents so we are going to
- 2:04:29specifically use this other than this if
- 2:04:31you can definitely check out all the
- 2:04:34agents that are probably available over
- 2:04:35here for that purpose right and by that
- 2:04:38you will be able to implement things so
- 2:04:40here what I'm going to do I'm going to
- 2:04:41create my retriever uh tool itself so I
- 2:04:44will write from Lang
- 2:04:47chain dot tools Dot
- 2:04:53retriever
- 2:04:55import create retriever tool I will
- 2:04:57initialize this create retriever tool
- 2:05:00and here I'm going to
- 2:05:01use retriever is equal to or whatever
- 2:05:05retriever name I have and then this will
- 2:05:07basically be my lsmith search right so
- 2:05:11because that is with respect to the
- 2:05:12lsmith page okay L smithore search okay
- 2:05:17so that it'll be able to get
- 2:05:20identified okay like which which tool
- 2:05:23I'm basically hitting or which tool I'm
- 2:05:25basically searching okay and here I will
- 2:05:27give my third parameter and I will say
- 2:05:29hey search for information about
- 2:05:33lsmith I'll just copy and paste it I've
- 2:05:35already done this in one of my project
- 2:05:38so so here you can see the third
- 2:05:40parameter that I'm giving in the create
- 2:05:41retrieval tool is just like a prompt
- 2:05:43like what I really want this tool to do
- 2:05:46search for Information Gain about lsmith
- 2:05:48for any question about lsmith you must
- 2:05:49use this tool so in short when I do this
- 2:05:52Creator retrieval tool right it is
- 2:05:54basically creating a tool uh to do the
- 2:05:57search for that particular page right so
- 2:06:00here I'm going to write retrieval uncore
- 2:06:03tool okay and this will get initialized
- 2:06:05right so I have got one tool over here
- 2:06:08one tool is Wikipedia and the other tool
- 2:06:11if you go and see this retriever tool.
- 2:06:14name this is nothing but lsmith search
- 2:06:16now the third retrieval tool that I'm
- 2:06:18actually going to create uh is
- 2:06:20specifically my my own uh RI platform
- 2:06:24that I have actually developed so for
- 2:06:25this also I will be having one rapper
- 2:06:28and one query Run Okay so this will
- 2:06:30basically be for my Rift Rift basically
- 2:06:32means the website where all the research
- 2:06:34papers have been uploaded okay so let's
- 2:06:38create one more tool so this is for this
- 2:06:39particular tool okay and again the same
- 2:06:42thing that we will try to do is that we
- 2:06:44have to create a rapper API rapper Rift
- 2:06:47rapper where again my document Max
- 2:06:49search will be 200 and this will be B
- 2:06:51basically my for my query run and here
- 2:06:53I'm actually going to get my ri. name
- 2:06:56and here you'll be able to see that this
- 2:06:58is my tool right so this is inbuilt tool
- 2:07:04that is also provided by Lang chain
- 2:07:06Wikipedia and R is provided by Lang
- 2:07:09chain if you really want to create your
- 2:07:10own custom tool then you can also create
- 2:07:12like this but like I have actually shown
- 2:07:14you right at the end of the day you
- 2:07:16combine all these particular tools so
- 2:07:17let me go ahead and combine it so I will
- 2:07:19write uh tools is equal to and let's go
- 2:07:23ahead and combine this so the first tool
- 2:07:25that I have I think it is name is tool
- 2:07:28only okay so I at written tool so let me
- 2:07:31go ahead and write wiki wiki over here
- 2:07:33Wiki okay wiki wiki okay so here I'm
- 2:07:36going to combine all these things so
- 2:07:38first one is Wiki the second one is my
- 2:07:41ARF and the third one is my lsmith okay
- 2:07:46so Lang Smith uh this is nothing but it
- 2:07:49is a retrieval tool name right so I'm
- 2:07:51going to basically combine all this
- 2:07:53tools so finally I got my entire tools
- 2:07:56over here so this tools is nothing but
- 2:07:57it is a list of all the tools that you
- 2:08:00can see over here with respect to this
- 2:08:02now my next aim is basically to query
- 2:08:07from this specific tools right so for
- 2:08:09this I can do it in multiple ways uh and
- 2:08:12that is where we will be specifically
- 2:08:14using agents okay so let me just go
- 2:08:18ahead and tell you what is the main
- 2:08:20purpose of agent agents agents will be
- 2:08:23responsible in probably see if I go
- 2:08:26ahead and show you the documentation
- 2:08:28also let me go ahead and show you the
- 2:08:32documentation agents the core idea of
- 2:08:34the agent is use to Lang is to use a
- 2:08:37language model to choose a sequence of
- 2:08:39action to take in change the sequence of
- 2:08:41action is hardcoded in code in agent a
- 2:08:43language model is used as a reasoning
- 2:08:45engineering to determine uh which
- 2:08:47actions should take place in which order
- 2:08:49right now here you can see that I have
- 2:08:51have given one two three tool in that
- 2:08:53specific order so what my agent will
- 2:08:56basically do is that it will whenever I
- 2:08:58perform any request right whenever I
- 2:09:00give any input to my llm model it is
- 2:09:02first of all going to first search in
- 2:09:04Wiki if it is not able to get in from
- 2:09:06this particular tool it is going to go
- 2:09:07to Rift then it is going to go to
- 2:09:08retrieval tool right so from these three
- 2:09:11tools it is going to get the query and
- 2:09:12it is going to provide you the response
- 2:09:14okay so let me quickly go ahead and
- 2:09:16write from Lang
- 2:09:18chain. agents I'm going to import
- 2:09:22create create open AI tool agent and
- 2:09:25here I'm going to Define my agent name
- 2:09:27and let me go ahead and write create
- 2:09:29open AI tools agent name and here I'm
- 2:09:31going to give my
- 2:09:33llm my tools that I've actually created
- 2:09:36and one will be my prompt okay so the
- 2:09:38prompt and Tool have not yet defined so
- 2:09:41uh what I will do here I will show you
- 2:09:43an example like how you can probably
- 2:09:46call your prompts also that is already
- 2:09:49available in langen Hub but before that
- 2:09:51let me go ahead and call my open AI API
- 2:09:53so quickly I will go ahead and call it
- 2:09:56and then this is what I'm initializing
- 2:09:58my llm models as okay so I have actually
- 2:10:01created chat open API so this is what
- 2:10:03I'm actually going to use okay now let
- 2:10:05me go uh so this is my llm model the
- 2:10:07next thing is that how can I probably
- 2:10:09create a prompt one way that I've
- 2:10:12already showed you of creating a prompt
- 2:10:14is just by using chat promp template but
- 2:10:17in langin there is a module called as
- 2:10:19Hub there people have already created or
- 2:10:21L chain has already created some amazing
- 2:10:23prompts generic prompts and they have
- 2:10:24uploaded over there so in order to call
- 2:10:26from there so I will write from Lang
- 2:10:28chain uh from Lang chain import Hub okay
- 2:10:35and then we are going to Prem uh give
- 2:10:37the prompt we are going to get the
- 2:10:38prompt and the prompt will be of this
- 2:10:40name okay so we'll also see see get the
- 2:10:42prompt to use and you can modify this so
- 2:10:44there is a something called as open a
- 2:10:46function agents uh and this is the
- 2:10:49username that is present in langen hub
- 2:10:51if I go ahead and see what is the prompt
- 2:10:52over here so I'm getting an error let's
- 2:10:54see please install lanin Hub okay so we
- 2:10:57also require lanin Hub uh in order to
- 2:11:00use this see the reason why I'm showing
- 2:11:02you all this things because so many
- 2:11:04different options are there lanch Hub
- 2:11:07okay so let me quickly go ahead and run
- 2:11:11in the terminal pip install requirement.
- 2:11:15txt Okay so this I will probably Lang
- 2:11:18chain Lang chenore Hub let me see the
- 2:11:20error
- 2:11:22what was the error over
- 2:11:24there okay it should be something like
- 2:11:28this okay so I will go ahead and write
- 2:11:32or see in the requirement. txt the name
- 2:11:35is different now let me quickly go ahead
- 2:11:37and write it down over and install
- 2:11:40it right so here you can probably see
- 2:11:45yes the installation is done my agents
- 2:11:47is ready now let me go ahead and execute
- 2:11:49this now I think you should be able to
- 2:11:50see the m
- 2:11:51messages okay now you'll be able to see
- 2:11:54the messages over here now see by
- 2:11:56default whatever prompt is available in
- 2:11:58open aai function agents you'll be able
- 2:12:00to see I have system message prompt
- 2:12:02template there's prompt variable the
- 2:12:04input variable is there in template you
- 2:12:06are a helpful assistant so what we used
- 2:12:07to do manually everything is available
- 2:12:09over here the same thing it will have
- 2:12:11one human message one system message
- 2:12:14prompt template one human message prompt
- 2:12:15template right now uh you have the
- 2:12:17prompt you have everything now we can go
- 2:12:19ahead and create my AI tool agents once
- 2:12:22I probably create my open a tool agents
- 2:12:25now you can probably use this agent and
- 2:12:28execute to Pro get any kind of response
- 2:12:30now in order to use this particular
- 2:12:32agents we have to use something called
- 2:12:34as agent
- 2:12:35executor okay agent executor please
- 2:12:40understand the flow the flow is
- 2:12:41important and that is how you'll be able
- 2:12:44to understand this so from Lang
- 2:12:47chain. agents import
- 2:12:53agent executor okay so agent executor is
- 2:12:58my next I that I'm going to specifically
- 2:13:01use and I'll use this agent executor
- 2:13:04here I'm going to use my agent is equal
- 2:13:05to agent along with that I will use my
- 2:13:08tools is equal to tools okay whatever
- 2:13:11tools I've given and then this verbos
- 2:13:13will be true so that I'll be able to see
- 2:13:15all the details whenever I get any
- 2:13:16response and this will basically be my
- 2:13:19agent executor so this is basically
- 2:13:22responsible in executing anything right
- 2:13:25so now if I go and see my agent executor
- 2:13:28so here you can see all the things and
- 2:13:30it has also added runnable binding
- 2:13:33arguments over here right now in order
- 2:13:36to execute anything see if I write agent
- 2:13:39executor dot
- 2:13:42invoke so once I write invoke and I give
- 2:13:45my
- 2:13:47input and let me give the message tell
- 2:13:50me me
- 2:13:52about
- 2:13:56lsmith now you should just think that
- 2:13:58from where should this input come
- 2:14:00already in our tools we have R platform
- 2:14:03we have lsmith search right and we have
- 2:14:06Wikipedia so obviously this this agent
- 2:14:09will execute and it will interact from
- 2:14:12the tool that is related to lsmith so
- 2:14:15once I execute this here you'll be able
- 2:14:17to see what kind of response I usually
- 2:14:19get Okay so so here you can see tell me
- 2:14:22about lsmith lsmith is a platform for
- 2:14:24building production G application uh llm
- 2:14:27application and here and this is
- 2:14:29probably coming from the tool itself
- 2:14:30right now here uh mostly uh the thing
- 2:14:33that you could not see right you could
- 2:14:35not see over here what exactly the thing
- 2:14:38was the reason was very simple I did not
- 2:14:40write the verbos parameter properly now
- 2:14:42you'll be able to see what details
- 2:14:44you'll be getting see once you write
- 2:14:45verbos equal to true now you'll get all
- 2:14:47the details what it has hit now see
- 2:14:50invoking Langs Smith search right it is
- 2:14:53basically searching the langmi Search
- 2:14:55tool right whatever tool was there right
- 2:14:57let me go ahead and execute once again
- 2:14:59with respect to some different query
- 2:15:01right and here let me write tell me
- 2:15:04about machine learning now I don't know
- 2:15:07from where it will go ahead and execute
- 2:15:08it but let's see whether it'll go with
- 2:15:10Wikipedia or RF okay so agent executor
- 2:15:14enters invoking Wikipedia with machine
- 2:15:16learning see and automatically Wikipedia
- 2:15:19it is probably giving you the entire
- 2:15:20result okay let me also try with
- 2:15:22something like RV uh uh platform so uh I
- 2:15:26have one question with some research
- 2:15:28paper Okay research paper name so let me
- 2:15:31just go ahead and execute what's the
- 2:15:32paper all about the paper number is
- 2:15:35there and in RC will'll be able to find
- 2:15:37out this see now it is invoking the RF
- 2:15:40with query uh this particular tool and
- 2:15:43here you'll be able to get the response
- 2:15:45and that is the reason why I say this
- 2:15:47agent executor tools are probably the
- 2:15:49most important thing whenever you
- 2:15:51probably develop a rag application guys
- 2:15:53we are going to continue the Lang chain
- 2:15:55series and in this video we are going to
- 2:15:57create an amazing endtoend rag project
- 2:16:01uh with the help of Open Source llm
- 2:16:03models and grock inferencing engine an
- 2:16:06amazing project Al together over here
- 2:16:08I'm going to show you many more things
- 2:16:10and the best part is that many of you
- 2:16:12were specifically requesting only for
- 2:16:14open source llm models so here I will
- 2:16:16try to show you from embedding to using
- 2:16:18all the open source llm models along
- 2:16:20with with that what exactly is Gro
- 2:16:22inferencing engine we'll also discuss
- 2:16:24about it so here is the gro inferencing
- 2:16:26engine if you don't know about Gro it is
- 2:16:28on a mission to St the standard for Gen
- 2:16:29AI inferencing speed right and it
- 2:16:33specifically uses something called as
- 2:16:34lpu language processing unit okay it is
- 2:16:38a new type of end to-end processing unit
- 2:16:40system that provides the fastest
- 2:16:42inference for computationally intensive
- 2:16:44application with is with a sequential
- 2:16:46component to them why it is so much
- 2:16:48faster than GPU because it solves two
- 2:16:49llm bottleneck one is compute density
- 2:16:52and memory bandwidth I've already
- 2:16:54created a detailed video before and
- 2:16:56spoken more about what exactly is LP
- 2:16:59inferencing engine but now it's time
- 2:17:01that we go ahead and Implement some
- 2:17:02amazing Solutions out here right so let
- 2:17:04me go ahead and let me implement this
- 2:17:07end to end project and this project uh
- 2:17:09here I'm going to probably use streamlet
- 2:17:12over here so that you can actually see
- 2:17:13it in the form of uh web application so
- 2:17:16first of all as usual what I will do is
- 2:17:18that I will go ahead and uh see in the
- 2:17:20requirement. txt here you can see grock
- 2:17:22is also available and along with that
- 2:17:24we'll also be using langin grock so both
- 2:17:27this is the most important part along
- 2:17:29with that bs4 beautiful sou for so that
- 2:17:31we'll be also able to scrap from a
- 2:17:33website so that is what I'm actually
- 2:17:35going to do in my project so here you
- 2:17:36can see in grock I will create one
- 2:17:38folder that is called as or one file
- 2:17:40that is called as app.py Now quickly let
- 2:17:43me go ahead and start the coding over
- 2:17:44here first thing first uh I will first
- 2:17:47of all go ahead and import all the
- 2:17:48important libraries like import
- 2:17:50streamlink
- 2:17:51as St along with that along with
- 2:17:53streamlet I'm also going to go ahead and
- 2:17:55import OS okay now uh the first thing
- 2:17:58that you actually require is the API
- 2:18:00access so click on the API access of Gro
- 2:18:03and you will be able to access it
- 2:18:04completely for free so once you go to
- 2:18:07this API access page you'll be able to
- 2:18:09see that there is a something called as
- 2:18:10uh Self Serve through playground on
- 2:18:12grock so Gro Cloud also gives you a
- 2:18:14playground along with this if you really
- 2:18:16want to use it for a commercial purpose
- 2:18:18then you can see currently uh Lama 270b
- 2:18:21that is 70 billion parameter gives you
- 2:18:234096 context length and uh the response
- 2:18:27that you'll be probably getting is 300
- 2:18:28tokens per second this is quite fast
- 2:18:30when compared to open AI CH GPT
- 2:18:33specifically uh and the price per 1
- 2:18:36million toker is somewhere around
- 2:18:391.7.8 uh similarly Lama 27b you can see
- 2:18:42750 tokens per second then Mistral is
- 2:18:44there 480 tokens per second gamma 7B
- 2:18:47which is basically having 8K Contex L
- 2:18:49and this is somewhere around 32 get
- 2:18:51context L right 820 tokens per second
- 2:18:53and the price is also very much minimal
- 2:18:55so uh as usual see you can see doc has
- 2:18:58also demonstrated 15 times faster llm
- 2:19:00influencing performance on an artificial
- 2:19:02intelligence. leaderboard compared to
- 2:19:04the top cloud-based providers so this is
- 2:19:06awesome and you should definitely know
- 2:19:08this so in order to create the API I
- 2:19:10will go ahead and click on the
- 2:19:11playground on Gro uh once you go over
- 2:19:14here you here you'll be able to see the
- 2:19:15button of apis so just go ahead and
- 2:19:17click on create API give the API name
- 2:19:19and just click on sub submit once you do
- 2:19:21that you'll be getting an API name
- 2:19:23itself right and this API this secret
- 2:19:25key only I will be specifically using in
- 2:19:27my environment variable so uh I'll show
- 2:19:29you step by step already I have created
- 2:19:31those kind of API key so please make
- 2:19:34sure that you also update your
- 2:19:35environment variable I'll tell you with
- 2:19:37what name you really need to update
- 2:19:38right now here we have done this now
- 2:19:40since we are going to use this grock
- 2:19:42with Chad grock itself and that is
- 2:19:44already present in Lang chin right so
- 2:19:46here what I'm actually going to do I'm
- 2:19:48going to write it from Lang chin
- 2:19:51underscore sorry underscore
- 2:19:54grock import chat grock okay chat grock
- 2:19:59so this is the uh chat oh here I have
- 2:20:02made a spelling mistake Lang chain Lang
- 2:20:06chain Gro okay import Chad Gro so Chad
- 2:20:09grock is like how we use Chad API
- 2:20:11similarly Chad Gro is also there for
- 2:20:13this purpose as you all know that I'm
- 2:20:15going to probably take a website and
- 2:20:17read all my content from that specific
- 2:20:18website itself right so here what I'm
- 2:20:20going to do is then again from Lang
- 2:20:22chenore Community I'm going to use
- 2:20:25webbased loader again uh from Lang
- 2:20:27chenore Community uh then I'm going to
- 2:20:29use document loaders as you know this is
- 2:20:31the First Data injection technique that
- 2:20:33we can actually use import we web
- 2:20:38base web
- 2:20:40Bas documentor loaders webbase
- 2:20:44loader web base load okay so I will
- 2:20:48specifically use this particular langore
- 2:20:50community do documentor loader is import
- 2:20:52webbased loader along with this what I'm
- 2:20:55actually going to do as I said I'm going
- 2:20:56to only use open source models so first
- 2:20:58of all uh let's uh go ahead and do this
- 2:21:01and I'm going to use Lang chain and one
- 2:21:04of the embedding technique that I'm
- 2:21:05specifically going to use uh is AMA
- 2:21:08embedding because it is completely for
- 2:21:09free it is an open source itself so
- 2:21:11langore community. embeddings uh import
- 2:21:16AMA embedding so here you don't even
- 2:21:18have to worry about anything about open
- 2:21:20AIS right so embeddings I'm going to use
- 2:21:23it over here um uh along with this what
- 2:21:26we can do is that since we are going to
- 2:21:27read the entire document and convert
- 2:21:29that into smaller chunks so for that I
- 2:21:31will be using recursive character
- 2:21:32splitter so again from L chain under
- 2:21:37dot L chin dot again I'm seeing the
- 2:21:40documentation guys so I need to know
- 2:21:42where this library is actually present
- 2:21:44uh the recursive character text spitter
- 2:21:46so from Lang chain um I will be using
- 2:21:49dot text splitters
- 2:21:51tox text plater and here I'm going to
- 2:21:53import recursive character text plater
- 2:21:56okay so this is another library that I'm
- 2:21:58going to specifically use for this
- 2:21:59purpose and as you know that I've
- 2:22:01already shown you how to use create
- 2:22:03stuff document chain so for that also I
- 2:22:05will be using from Lang
- 2:22:08chain from Lang
- 2:22:11chain. chains. combine documents import
- 2:22:17create stuff document chain okay so this
- 2:22:19is the another library that I'm going we
- 2:22:20going to use um along with this I'll
- 2:22:23create my own custom chat prompt
- 2:22:25template so again from Lang chain dot oh
- 2:22:29sorry underscore code.
- 2:22:32prompts I'm going to
- 2:22:34import okay line
- 2:22:38chain uhor code. UT chat promp template
- 2:22:41okay so chat prompt template I'm going
- 2:22:43to use along with this and as you know
- 2:22:45after creating the document chain I also
- 2:22:46have to create the retrieval chain so
- 2:22:48from L chain
- 2:22:51do
- 2:22:52chains come on here from Lang chain.
- 2:22:57chains okay sometimes all the time when
- 2:23:00I'm writing Lang chin there is a
- 2:23:02spelling mistake come on okay
- 2:23:05import
- 2:23:06create uh create create create create
- 2:23:09retrieval underscore
- 2:23:12r r r i
- 2:23:15Vore chain okay so uh yes one more
- 2:23:20Library with respect to this I'm going
- 2:23:21to use all the specific things for my
- 2:23:24purpose uh and as you all know that I'm
- 2:23:26also going to use one more thing so that
- 2:23:28I'll be able to load all the environment
- 2:23:29variables so from dot EnV import load.
- 2:23:37EnV I'm also going to import OS I I've
- 2:23:40imported OS so load. EnV I'll just load
- 2:23:44this so that all my environment
- 2:23:45variables will loaded and one of the
- 2:23:47environment variable that I'm going to
- 2:23:48specifically use is grock API okay so
- 2:23:51let me load the grock API key okay so
- 2:23:56that whatever I'm specifically running
- 2:23:57I'll be able to use the open source llm
- 2:23:59model from this specific inferencing
- 2:24:01engine so here let me go ahead and write
- 2:24:03grock _ API _ key is equal to os.
- 2:24:08envirn okay and here I'm going to use
- 2:24:12crore API key that basically means
- 2:24:16whatever Gro API key I've have taken I
- 2:24:17have written in my environment variable
- 2:24:19with this key is is equal to whatever my
- 2:24:21API key I've got from that particular
- 2:24:23website okay so you also have to really
- 2:24:25do the same thing okay so whatever key
- 2:24:27you actually get you have to take this
- 2:24:28in the name and you have to probably go
- 2:24:30into environment variable so environment
- 2:24:32variable is somewhere here and just
- 2:24:34assign this with that whatever key name
- 2:24:35because I have created a lot of key over
- 2:24:37there and since we are continuing the
- 2:24:39Lin series I'm going to probably do in
- 2:24:40this specific project itself okay so
- 2:24:43once uh this is done uh here one more
- 2:24:45thing I'm going to specifically use uh
- 2:24:47in streamlit I'm going to use something
- 2:24:49called a session state so all those
- 2:24:50things I'll also be doing with respect
- 2:24:52to this okay and that will also help you
- 2:24:53to understand so here I'm going to write
- 2:24:55if
- 2:24:57Vector not in okay st. session state I'm
- 2:25:03going to create some session States so
- 2:25:05that you'll be able to understand so
- 2:25:06first thing that I'll be creating with
- 2:25:08the session state is nothing but my AMA
- 2:25:10embedding and probably you'll also get
- 2:25:12an idea in this video about many things
- 2:25:14session States and Streamlight and all
- 2:25:16okay so first of all I'm going to create
- 2:25:18my embeddings this embeddings I'm going
- 2:25:20to assigned to my all my embeddings okay
- 2:25:22so this is the first parameter that I'll
- 2:25:23be using then I'll be using session
- 2:25:26loader so session uncore State okay uh
- 2:25:31and along with this do loader so I will
- 2:25:33load some information from my website
- 2:25:36now what website I'm actually going to
- 2:25:38consider let's see uh initially I've
- 2:25:40used some kind of websites over here
- 2:25:42here at least somewhere I've used some
- 2:25:44websites let's pick up any of the
- 2:25:47website over there okay I'll probably
- 2:25:49take previous
- 2:25:50examples um this is done agents is the
- 2:25:53agent let's see what example I've
- 2:25:55actually taken okay let's pick up this
- 2:25:57website okay so I'm going to use
- 2:25:59webbased loader along with this website
- 2:26:01okay so here I'm going to write webbased
- 2:26:03loader and here will be basically my
- 2:26:05website link okay so I'm actually
- 2:26:07reading the content from this website
- 2:26:10okay so let me quickly open it over here
- 2:26:12for you so that you'll be also able to
- 2:26:14see it okay so it's uh doc dos Smith
- 2:26:17chain L Lang chain some information I
- 2:26:20want from here so I will try to pick it
- 2:26:21up from here itself okay so this becomes
- 2:26:23my loader now you know after getting the
- 2:26:25loader what we really need to do is that
- 2:26:27we need to uh uh from this particular
- 2:26:30website we need to get the entire
- 2:26:31documents so I will create another
- 2:26:34session States session uncore State okay
- 2:26:38dot docs and I will say loader dot oops
- 2:26:43not loader it should be this one st.
- 2:26:45session state.
- 2:26:47loader
- 2:26:49do load okay so once I load it uh again
- 2:26:53the same thing whatever we have
- 2:26:54specifically done now after getting the
- 2:26:56docs what we have to do is that we have
- 2:26:57to probably use this st. session State
- 2:27:02now you know what we specifically do
- 2:27:04after that you know we get the final
- 2:27:05documents or chunk documents right so
- 2:27:07I'll write chunk um documents because I
- 2:27:11need to do over here as recursive
- 2:27:13character splitter right so here I'm
- 2:27:15going to use recursive character
- 2:27:16splitter and here inside this recursive
- 2:27:18character splitter I have to probably
- 2:27:20consider this as my docs
- 2:27:23okay oh sorry over here I will probably
- 2:27:26be assigning my or instead of writing
- 2:27:29this chunk underscore documents I will
- 2:27:31write text spitter so this will
- 2:27:32basically be my text spitter here uh I
- 2:27:35will be using chunk chunk uh underscore
- 2:27:39size is equal to 10,000 or th000 th000
- 2:27:43I'll go ah and right chunk undor overlap
- 2:27:46will be somewhere around 200 right so
- 2:27:48this is done uh good we have we have our
- 2:27:52text splitter again that is also saved
- 2:27:55in the session itself now I'm going to
- 2:27:57basically go ahead and write st. session
- 2:28:00uh session uncore State and here I'm
- 2:28:03going to create my final documents final
- 2:28:06documents okay and this final documents
- 2:28:09will be used along with this st. session
- 2:28:13state. textor splitter and here we are
- 2:28:16going to basically uh use do splitcore
- 2:28:19documents
- 2:28:20okay and we are going to probably take
- 2:28:22the documents over here documents is
- 2:28:24nothing but all the documents that is
- 2:28:26available over here along with this we
- 2:28:28going to use the embedding that is
- 2:28:31nothing but uh St do session state do
- 2:28:36embeddings right
- 2:28:38um embeddings I think it should be
- 2:28:42coming up right I think it is the same
- 2:28:45thing St do state. embeddings right so
- 2:28:48this basically becomes your final
- 2:28:50document okay so final documents and
- 2:28:53here you can probably see all the things
- 2:28:54are available right with respect to all
- 2:28:57the uh State session states that are
- 2:28:59basically getting created now the next
- 2:29:01thing uh that I also need to do after
- 2:29:02probably getting the form all the
- 2:29:04documents form then I have to really
- 2:29:06convert that into vectors also and store
- 2:29:08it in a vector store so from Lang chain
- 2:29:11uncore
- 2:29:12community on inside this community I'm
- 2:29:14going to specifically use my Vector
- 2:29:18stores okay so Lang Lang Lang Lang Lang
- 2:29:23Lang all the time c will be coming
- 2:29:25before G so how many of you are also
- 2:29:27doing the same mistake like me okay so
- 2:29:29from this one I'm going to
- 2:29:31import
- 2:29:32F okay now this F uh that I have
- 2:29:36actually initialized again I'm going to
- 2:29:38store it inside my session session unor
- 2:29:41state DOT name it as vectors is equal to
- 2:29:45I'll be using
- 2:29:47F F.T from
- 2:29:51documents and inside this as you know
- 2:29:54that since we are going to use this
- 2:29:55functionality of from documents two
- 2:29:57important things I have to really give
- 2:29:58one is all my documents all my final
- 2:30:00documents so here uh I will give my
- 2:30:03first parameter as final documents over
- 2:30:05here okay and the second uh one that I'm
- 2:30:08specifically going to give is nothing
- 2:30:09but my embeddings right so this will
- 2:30:12specifically be my embeddings
- 2:30:16right done so this is perfect uh here
- 2:30:19you'll be able to see that I'm able to
- 2:30:21see all the documents everything as such
- 2:30:24and uh this is all in short my uh these
- 2:30:27vectors will get created now I can
- 2:30:29probably ask any questions from this
- 2:30:30particular vectors okay but since I
- 2:30:32really need to create this as an end to
- 2:30:33end project so I'm going to use multiple
- 2:30:36things one is st. title okay and here
- 2:30:39I'm going to basically use uh uh
- 2:30:43chat grock chat
- 2:30:47grock demo
- 2:30:50okay chat grock demo now let me go ahead
- 2:30:53and create my llm my llm is nothing but
- 2:30:55chat grock and inside this I'm going to
- 2:30:58specifically take my groor API key which
- 2:31:01will be initialized to my groor API key
- 2:31:04right so whatever grock uncore API key
- 2:31:06I'm actually getting it okay um along
- 2:31:09with this uh the model that I'm going to
- 2:31:10specifically use there multiple models
- 2:31:12as already said over here so let me
- 2:31:15check out what all models are there so
- 2:31:18you have this gamma 7B it right or you
- 2:31:22have this Mistral 87b 32768 so I will
- 2:31:26use gamma 7B it so let me quickly go
- 2:31:29ahead and over here and I'll let me
- 2:31:31write in my name model _ name is equal
- 2:31:34to so gamma I think it is capital letter
- 2:31:37gamma
- 2:31:407B so this will
- 2:31:43be
- 2:31:45gamma
- 2:31:467B it I think I spelling is right right
- 2:31:51uh it's Capital it t is it capital it or
- 2:31:561T okay if it does not work I'll change
- 2:31:58the model name no worries I have three
- 2:32:00other options Capital it okay I think it
- 2:32:03should it should be Capital it okay so
- 2:32:05once this is done uh my Gro my model
- 2:32:07name everything is basically created uh
- 2:32:10then uh this is my llm models now what I
- 2:32:12will do is that I will also go ahead and
- 2:32:15create my prompts so let me go ahead and
- 2:32:17write prompt chat prompt template do
- 2:32:20fromom template so they are also some
- 2:32:22templates that is defined you can also
- 2:32:23create uh chat prom template from
- 2:32:25scratch okay so I will say answer the
- 2:32:34question or so here I'm going to
- 2:32:37basically use some context also
- 2:32:40answer
- 2:32:42the answer the
- 2:32:46questions based on the
- 2:32:50provided
- 2:32:52context context only okay
- 2:32:59um so here I'll write please
- 2:33:03provide provide the most accurate
- 2:33:09response based on
- 2:33:11the based on the context okay so this
- 2:33:14will basically be my thing and uh uh one
- 2:33:18very important thing is that uh I can
- 2:33:20also specify based on
- 2:33:23the based on the question okay now let
- 2:33:26me go ahead and Define my context so
- 2:33:28here I will basically Define my context
- 2:33:30and this will uh this will be ending
- 2:33:33over here so let me go ahead and write
- 2:33:36it so this will basically be my context
- 2:33:38and here I can give my context like this
- 2:33:42now the next thing that I usually give
- 2:33:44is nothing but my question which will be
- 2:33:46my input parameter over here right so
- 2:33:48this will basically be my input okay so
- 2:33:51this becomes my chat prompt template uh
- 2:33:52this is very good now as you know what
- 2:33:55are the next step we have to probably
- 2:33:56use document chain so I will go ahead
- 2:33:58and use document chain over here then I
- 2:34:01will specifically use all the vectors in
- 2:34:03the form of as retrieval right so that
- 2:34:05this is just like an interface to
- 2:34:07probably read all the data context that
- 2:34:09I specifically get from these particular
- 2:34:11vectors now since uh we are using all
- 2:34:13these things right like we are using
- 2:34:15this chart promp template we are using
- 2:34:16some context based information then
- 2:34:18document chain retriever and create
- 2:34:20retrieval chain will also come into
- 2:34:21existence now create retrieval chain
- 2:34:23already I have explained in my previous
- 2:34:25video here I'm going to combine my
- 2:34:26document chain and the retriever so both
- 2:34:29of them will be specifically combined
- 2:34:30and now I will go ahead and probably
- 2:34:33write my prompt prompt will be STD do
- 2:34:37textor input and here I'm going to
- 2:34:39Define
- 2:34:41my input
- 2:34:44your prompt here so guys now next step
- 2:34:48what I can actually do is that uh llm is
- 2:34:50ready my prompt is ready my retrieval
- 2:34:52chain is ready everything is ready now
- 2:34:54uh all I have to do is that I will write
- 2:34:56if prompt okay if the prompt is there uh
- 2:35:00I will go ahead and write my response
- 2:35:02okay and with respect to response I will
- 2:35:04be using this retrieval chain so let me
- 2:35:06go ahead and write retrieval chain do
- 2:35:09invoke okay and whatever input I'm
- 2:35:12specifically giving right with respect
- 2:35:14to this particular input and that should
- 2:35:16be in the form of
- 2:35:18dictionaries okay and here I'm going to
- 2:35:20write
- 2:35:21input
- 2:35:23colon prompt right so done so this is
- 2:35:26also done perfect I'll be able to get
- 2:35:29the response over here now uh it's
- 2:35:31always the best way that uh if I really
- 2:35:34want to get the response right uh I go
- 2:35:36ahead and probably use uh some timer out
- 2:35:39there right so that you'll be able to
- 2:35:41see it like how much time it is probably
- 2:35:43taking so import time I have imported
- 2:35:45time over here now in as soon as
- 2:35:48probably I go ahead and H hit uh The
- 2:35:50Prompt itself right as soon as I press
- 2:35:53enter you know the timer should probably
- 2:35:54start over here so I'll write starter
- 2:35:57time dot uh process time okay so this
- 2:36:01will basically be my process time over
- 2:36:03here and then I will go ahead and write
- 2:36:05print okay or I don't have to print also
- 2:36:09over here nothing okay what time it will
- 2:36:11start and all we can probably do it but
- 2:36:13again I can go ahead and write print
- 2:36:17uh response time time colon okay and
- 2:36:21whatever is the response time I can
- 2:36:23specifically uh do the subtraction over
- 2:36:26here itself right and here uh I can just
- 2:36:29write something like this uh the current
- 2:36:31time that is time do process time okay
- 2:36:35process time minus start or whatever is
- 2:36:39the start time right so I can
- 2:36:41specifically get this and I'll be
- 2:36:42getting the response itself and once I
- 2:36:44get the response I will go ahead and
- 2:36:45write st. write and this will basically
- 2:36:48be my response of answer
- 2:36:52okay whatever answer I'm specifically
- 2:36:54getting okay so yes almost done each and
- 2:36:57everything over here um and I think uh
- 2:37:00we'll be able to get all the things uh
- 2:37:02with respect to this but again it is a
- 2:37:04good idea that uh you know you also try
- 2:37:06to create an expander where you probably
- 2:37:08get all the context also what it is
- 2:37:10basically getting retri so a small four
- 2:37:12to five lines of code that I will be
- 2:37:14adding it over here right with a Strate
- 2:37:17expander you can see I'm taking up all
- 2:37:19the context from that context I'm taking
- 2:37:22the page content and displaying it over
- 2:37:24here right now let's go ahead and run
- 2:37:26this I think it should be working
- 2:37:27absolutely fine uh amazing end project
- 2:37:31where we definitely learn a lot of thing
- 2:37:33and here finally you'll be able to see
- 2:37:35streamlet run
- 2:37:38agents uh sorry app.py right but I think
- 2:37:42it should be running and we'll see the
- 2:37:43speed because the speed will be the most
- 2:37:46important thing so let me go ahead and
- 2:37:47CD CD grock and now same thing I will go
- 2:37:50ahead and write now I feel now the main
- 2:37:53the most excited thing that I will
- 2:37:55probably be excited about this
- 2:37:57application is how quickly I'm able to
- 2:37:58get it so text pl. split documents St
- 2:38:01two position number three were given
- 2:38:02let's
- 2:38:03see this kind of Errors usually comes
- 2:38:06but it's okay recursive
- 2:38:08cator
- 2:38:10uh is it regarding recursive text
- 2:38:14Splitter Splitter
- 2:38:17documents okay where did I give
- 2:38:20three uh splitter documents let me see
- 2:38:23in the documentation uh but again this
- 2:38:26kind of Errors will definitely be coming
- 2:38:28up okay here I don't require embeddings
- 2:38:30okay so one is only required I just saw
- 2:38:33the uh document so that's it okay
- 2:38:36sometime it happens but it's
- 2:38:37okay now probably whatever question I
- 2:38:40asked from here okay let's see I will go
- 2:38:43ahead and ask
- 2:38:45this now I think it should be running
- 2:38:51let's see let's see let's see let's see
- 2:38:53it's stopping b a
- 2:38:55second but there are lot of content from
- 2:38:58here so that is the reason I think it is
- 2:38:59taking so much of time I think for the
- 2:39:01first time for the indexing purpose it
- 2:39:03is probably taking a lot of time let me
- 2:39:05delete this once again um terminal and
- 2:39:08let me do one thing okay let me to just
- 2:39:10improve the performance right I will
- 2:39:13just not take all the documents over
- 2:39:14here I will just take some documents
- 2:39:16okay uh let's probably take the initial
- 2:39:2050 documents that is how I'm going to
- 2:39:22probably do it okay uh initial 50
- 2:39:25documents if we are able to do that much
- 2:39:27I think uh it'll work out um I don't
- 2:39:31want the maximum number of files that
- 2:39:34will probably create me a problem over
- 2:39:36here okay command prompt let's see open
- 2:39:40CD grock okay uh stream late I think
- 2:39:45it'll take some time because I'm saying
- 2:39:48that as soon as the pages get getting
- 2:39:49loaded this needs to be embedded or
- 2:39:51indexed okay so stream late run app.py
- 2:39:55let's see if this works faster uh I will
- 2:39:58not show you the other one then probably
- 2:40:00it'll take some time you know because
- 2:40:01the entire website is basically getting
- 2:40:04indexed and uh let's see how much time
- 2:40:06that vectors will probably get created
- 2:40:08that is how things are basically
- 2:40:09happening over here um because we are
- 2:40:11taking the first 50 documents but I
- 2:40:13hardly see that 100 to 200 documents
- 2:40:15because it's a big website that this
- 2:40:17document. smith. blank chain right so
- 2:40:20you can see this is a big big page and
- 2:40:23there are so many things that is already
- 2:40:24available over here okay let's see how
- 2:40:27things goes ahead and okay uh st.
- 2:40:31session has no attribute Vector did you
- 2:40:32forget to initialize it okay one more
- 2:40:34error one more error error error error
- 2:40:37error okay let me see St vectors Vector
- 2:40:42vectors okay vectors is used over here
- 2:40:44let me see okay
- 2:40:47vectors I understood the error
- 2:40:49it's okay we can understand that
- 2:40:53okay okay now I have again reloaded it
- 2:40:56it is going to take some time hardly I
- 2:40:58think hardly 10 to 15 seconds because it
- 2:41:00is going to Index this entire page and
- 2:41:03for the first time indexing it is it is
- 2:41:05going to take that much time so guys uh
- 2:41:07whenever I'm probably searching things
- 2:41:09right and it is giving me some of the
- 2:41:10document similarity search but uh with
- 2:41:12respect to the summarization from the
- 2:41:13Lang chain it is not coming up I find
- 2:41:16out that one of the reason is that uh
- 2:41:18GMA 7B model you know it has a very less
- 2:41:21context length you know so if I probably
- 2:41:23consider over here uh and probably see
- 2:41:25in the API accs right uh there are
- 2:41:27multiple models that we have
- 2:41:28specifically used right one is uh mr8
- 2:41:31into 7B gamma 7B only 8K context L 32k
- 2:41:34context L let's do one thing let's try
- 2:41:36some other model over here okay the
- 2:41:39mistol model and see whether it will be
- 2:41:41improving the performance or not or
- 2:41:43whether it'll be improving the accuracy
- 2:41:44or not so you should be knowing all
- 2:41:46these things I'm not going to edit any
- 2:41:48part of the video over here so that you
- 2:41:50know you get an idea like how things
- 2:41:52works and here now let me go ahead and
- 2:41:55run this and reload it completely and
- 2:41:59now we will try to see it okay uh how
- 2:42:01the accuracy is but again we going to
- 2:42:03focus over here and see that how things
- 2:42:05are with respect to this right but at
- 2:42:07the end of the day uh it is being able
- 2:42:09to provide this context you know
- 2:42:10whenever I ask any specific question
- 2:42:12based on that context so uh I can just
- 2:42:15ask how to install lsmith how to create
- 2:42:17an API key uh um set how to set up an
- 2:42:20environment something like that okay so
- 2:42:23here how to set up an environment so
- 2:42:27let's go ahead and work it
- 2:42:29out I think it should
- 2:42:32be there okay it should be able to
- 2:42:35probably give me some kind of response
- 2:42:37at least now and again let's see this
- 2:42:39part
- 2:42:42also okay it's working but I think uh
- 2:42:46the document similarity search and
- 2:42:47everything we will be able to see it
- 2:42:50okay and along with that you'll also be
- 2:42:52seeing uh uh many more things right so
- 2:42:55many things that you can probably search
- 2:42:57out of it so let's
- 2:42:59see I think for the indexing purpose
- 2:43:01only it is probably taking time so the
- 2:43:03response time is less see to set up an
- 2:43:06environment this this this all the
- 2:43:08information are specifically over here
- 2:43:10so this looks absolutely amazing
- 2:43:12absolutely good you know and that is how
- 2:43:14you can actually do it and just you can
- 2:43:16imagine like what happens if you
- 2:43:17probably take an open source l m models
- 2:43:19with a higher context length right so
- 2:43:21definitely try it out from your end uh
- 2:43:24again you can ask any questions as such
- 2:43:26uh let's ask one more question uh over
- 2:43:29here um how to create an API key okay
- 2:43:33how to create an API
- 2:43:36key create an API key and if I execute
- 2:43:40it so here you can actually see the
- 2:43:42response is there and to create an API
- 2:43:44in lsmith you can follow the following
- 2:43:46steps all the content that is present in
- 2:43:48the website is shown here you can
- 2:43:49probably see the entire document
- 2:43:50similarity search so guys uh I hope you
- 2:43:54are loving the entire Lang chain series
- 2:43:56we have almost completed almost each and
- 2:43:59every module specifically to langin that
- 2:44:01is actually required to create end to-
- 2:44:03endend projects and we have also
- 2:44:05developed multiple projects over here uh
- 2:44:07we have used both paid and open source
- 2:44:09llm models now one of the most requested
- 2:44:12video was that chish how can we work uh
- 2:44:15considering Lang chin along with hugging
- 2:44:17face libraries and making sure that you
- 2:44:19use only open source llm models and try
- 2:44:22to create some amazing end to end
- 2:44:23project so in this video I'm going to
- 2:44:25use Lang chain having face and open
- 2:44:27source llm models like Mistral that is
- 2:44:28specifically hosted in hugging face and
- 2:44:30then we'll try to develop a Q&A rag
- 2:44:33complete rag app and uh I hope you will
- 2:44:36be liking this particular video please
- 2:44:38make sure that you watch this video till
- 2:44:39the end because there will be a lot of
- 2:44:41learnings that you'll be able to find
- 2:44:43from this particular video too so let me
- 2:44:45quickly go ahead and share my screen so
- 2:44:47here you can actually see I've created a
- 2:44:49fer called as hugging face and there are
- 2:44:51some us sensus data which I probably
- 2:44:53downloaded from the internet in the form
- 2:44:54of PDF and I have uploaded in this
- 2:44:56specific folder right so we will go
- 2:44:59ahead and probably read this again we we
- 2:45:02are going to use completely open source
- 2:45:03llm models like mistol using hugging
- 2:45:05face itself and then we are going to
- 2:45:07create the entire Q&A application so
- 2:45:09let's quickly go ahead and do this and
- 2:45:11initially as you know that initially we
- 2:45:13need to load all the data injection step
- 2:45:15that is loading all the libraries all
- 2:45:18all the PD itself so for that I will be
- 2:45:20importing from Lang
- 2:45:22chain undor Community okay do document
- 2:45:28loaders
- 2:45:31import Pi PDF loader okay so this is one
- 2:45:35of the uh things that I'll be requiring
- 2:45:37then from Lang chain undor Community do
- 2:45:41doent loaders I'm also going to make
- 2:45:43sure that I use a PDF directory also for
- 2:45:45that so here I'm going to import Pi PDF
- 2:45:49directory loader okay and then from
- 2:45:52since I after reading it I need to do
- 2:45:54the character splittings uh divide that
- 2:45:57documents into chunks so for that I'm
- 2:45:59going to use recursive character
- 2:46:00splitter along with this again as we
- 2:46:03know that we'll also use some kind of
- 2:46:05vector store over here so I'm going to
- 2:46:06use the vector store called as F and uh
- 2:46:09as you all know we are also going to use
- 2:46:10hugging face so for hugging face as I
- 2:46:13said all the embedding techniques also
- 2:46:14I'm going to use from hugging face
- 2:46:16itself so for that in Lang chin also you
- 2:46:18have this embedding techniques where you
- 2:46:20have hugging face uh BG embedding which
- 2:46:22is completely an open source and which
- 2:46:24is good enough right so we also going to
- 2:46:26use it um along with this I'm also going
- 2:46:28to import numpy as NP if I specifically
- 2:46:31require numpy I don't think so I will be
- 2:46:33requiring but I'm going to just use this
- 2:46:36okay um two more amazing libraries that
- 2:46:38I'm going to use from L chain since I
- 2:46:41also have to make sure that I create a
- 2:46:42template so from Lang chain. prompts I'm
- 2:46:47going to import
- 2:46:49prompt template okay so this is also
- 2:46:51what is specifically required and one
- 2:46:53more right one more uh chains I will
- 2:46:56specifically require again from Lang
- 2:46:58chain dot
- 2:47:01chains import retrieval QA right so
- 2:47:05retrieval QA chain we will specifically
- 2:47:08be requiring so all these libraries we
- 2:47:09are basically imported uh and we are
- 2:47:11going to use this for this particular
- 2:47:13purpose now let's go read the PDFs
- 2:47:20from the folder okay now here you have
- 2:47:24loader is equal to Pi PDF directory
- 2:47:28loader and here I'm going to give my
- 2:47:30sensus folder right so here I will go
- 2:47:32ahead and write dot start usor sensus
- 2:47:37okay so this sensus folder I'm going to
- 2:47:38specifically read and then I'm going to
- 2:47:40use this loader do load and I'm going to
- 2:47:44split uh I'm going to basically get my
- 2:47:46documents okay so once I probably get
- 2:47:49the documents then what I will do I will
- 2:47:51create my text
- 2:47:53spitter and for this I'm going to use my
- 2:47:55recursive character text spitter and for
- 2:47:58this uh the chunk size chunk undor size
- 2:48:01I will be taking th000 okay and
- 2:48:04chunk chunk uncore overlap will be
- 2:48:08somewhere around 200 okay so all these
- 2:48:11things as you all know I've written this
- 2:48:13kind of code a lot uh and then finally
- 2:48:16my final documents
- 2:48:19okay will be nothing but I will be using
- 2:48:21this text splitter and then I will split
- 2:48:24all the documents so I will write split
- 2:48:26all the
- 2:48:27documents uh with considering all my
- 2:48:30documents over here and let's go ahead
- 2:48:32and see my final documents first final
- 2:48:35document I'll just try to see I don't
- 2:48:37have to display the entire thing so uh
- 2:48:39this will probably read all the PDF file
- 2:48:42inside that particular us sensus folder
- 2:48:44which is present over here all the four
- 2:48:45PDF files and then it will probably give
- 2:48:47me a thing so here you can see one p
- 2:48:50error is there so here let me go ahead
- 2:48:52and write it chunk size now I think it
- 2:48:54should be working fine and all the PDF
- 2:48:56all the materials will be available in
- 2:48:57the description of this particular video
- 2:48:59guys for you all of you right so here
- 2:49:01you can see and the total number of
- 2:49:03length of final documents you can
- 2:49:05probably see is somewhere around 316 so
- 2:49:08here you can see page content H
- 2:49:09insurance cover status everything is
- 2:49:11available over here and this is the
- 2:49:13total number of documents that I'm
- 2:49:14actually able to get it okay now uh the
- 2:49:17next thing that I will will be
- 2:49:18specifically requiring is the embedding
- 2:49:20technique what embedding technique I'm
- 2:49:21going to use as I said I'll be creating
- 2:49:24hugging or let me just go ahead and
- 2:49:26write see you can use AMA embedding
- 2:49:28anything but since I am planning to do
- 2:49:30it with uh embedding using hugging face
- 2:49:32so I will be using all the hugging face
- 2:49:34components and these all are also very
- 2:49:36good completely open source and
- 2:49:38available for you from hugging face so
- 2:49:40here I'm going to basically write
- 2:49:42hugging face and biddings and uh the
- 2:49:45next thing that I will specifically
- 2:49:46require is my model underscore name this
- 2:49:50is the first parameter that I will be
- 2:49:51giving and then model number underscore
- 2:49:53name will be nothing but I have explored
- 2:49:57some of the model over
- 2:49:58here that is this one right bu this one
- 2:50:02is also there okay so one aming
- 2:50:03technique is this one I can also use uh
- 2:50:06sentence Transformers okay so let me
- 2:50:08just show you instead of using this I
- 2:50:10can also use this so I'll write down a
- 2:50:13comment over
- 2:50:14here oops just a second I'll just write
- 2:50:16down the comment over here
- 2:50:21okay so this also you can specifically
- 2:50:23use let's go ahead and use sentence
- 2:50:24Transformers if you want okay and uh if
- 2:50:28you don't want you can also use this no
- 2:50:30worries it is up to you okay both any of
- 2:50:33them can be specifically used it is up
- 2:50:35to you okay and these are some of the
- 2:50:36free available embedding techniques that
- 2:50:38is basically available okay so now I
- 2:50:43have actually created this I will go
- 2:50:44ahead and write my next one so before
- 2:50:47that let me do one thing
- 2:50:49okay and okay so the model name is
- 2:50:51driven then I will be using model KW R
- 2:50:54GS and I know I don't have to even use
- 2:50:57GPU right because with the help of GPU
- 2:50:59with the help of CPU this is possible
- 2:51:01because I have very less documents so
- 2:51:03I'll be using device device colon CPU
- 2:51:08okay so this will basically be my device
- 2:51:10with respect to this model arguments col
- 2:51:13okay the next parameter that I'm going
- 2:51:14to specifically use encode KW R GS and
- 2:51:19incode _ KW RGS will
- 2:51:21be here I'm going to use a parameter
- 2:51:23which is called as normalize so you may
- 2:51:26be thinking Krish from where are you
- 2:51:28probably considering this I'm just
- 2:51:31checking the documentation from the
- 2:51:32hugging phase itself right so if you go
- 2:51:34ahead and search for this right and
- 2:51:36you'll be also able to see some of the
- 2:51:37examples right so here you can see this
- 2:51:40okay so here you just click on this and
- 2:51:42here you'll be able to get all the
- 2:51:44information there will be some code
- 2:51:45files also which you'll be able to see
- 2:51:47sentence Transformer is also there see
- 2:51:48everything is over here right all mini
- 2:51:51this one only I told right so similarly
- 2:51:52you can probably go and check for many
- 2:51:54of if you want okay now the next thing
- 2:51:57that you really need to do is that you
- 2:51:58have to set your access token of hugging
- 2:52:00face unless and in order to access all
- 2:52:02these models hugging face token needs to
- 2:52:05be there so I will go and click on
- 2:52:06settings in my hugging face account
- 2:52:08there'll be something called an an
- 2:52:09excess token okay and just make sure
- 2:52:11that you create this particular new
- 2:52:12token so once you probably create it
- 2:52:14you'll be able to see it okay uh and
- 2:52:16then you can copy it and you can
- 2:52:17specifically use it but anyhow I will
- 2:52:19show you where we'll be specifically
- 2:52:21using now if I go ahead and execute it
- 2:52:24so here could not import sent
- 2:52:27Transformer install sentence
- 2:52:28Transformers okay I need to install
- 2:52:30sentence Transformers so let me quickly
- 2:52:32go ahead and update my requirement. txt
- 2:52:35file see whenever error comes some type
- 2:52:39of things is always going to happen but
- 2:52:41it's okay we should not be afraid of
- 2:52:43Errors you know errors will probably
- 2:52:46help us to do anything that we you want
- 2:52:48okay P install minus r requirement. txt
- 2:52:53so here you can see now the sentence
- 2:52:55Transformers will also get installed and
- 2:52:58finally you'll be able to see that okay
- 2:53:00everything is getting installed itself
- 2:53:02okay perfect perfect perfect perfect
- 2:53:04sentence Transformers is coming over
- 2:53:06here and now it'll be able you'll be
- 2:53:09able to see that okay on once it is
- 2:53:11installed then I think then you'll be
- 2:53:13able to execute this okay so we'll wait
- 2:53:16till this installation basically happens
- 2:53:18so if if you have not subscribed and
- 2:53:19please make sure that you write
- 2:53:20something in the comment section how are
- 2:53:22all these videos for you all are you
- 2:53:24able to understand I hope many many
- 2:53:26people I see whatever feedback that I'm
- 2:53:28getting from people with respect to the
- 2:53:30transition I feel that yes the videos
- 2:53:32are doing something in your life at
- 2:53:34least some amazing things in your life
- 2:53:36and I hope to do as long as I can okay
- 2:53:39but again my main aim is to teach you in
- 2:53:41such a ways that you learn learn learn
- 2:53:44learn things in a way that always it
- 2:53:46matters in your life right and that is
- 2:53:47what I'm actually looking at it okay so
- 2:53:50let's wait uh sometime sometime sometime
- 2:53:54some amount of time usually takes for
- 2:53:56this particular installation but I think
- 2:53:57once this installation takes place we
- 2:54:00good to go okay and I'll also show you
- 2:54:02how you can actually set up the hugging
- 2:54:05face you have actually created the
- 2:54:06hugging face tokens right but uh how to
- 2:54:10set it up as an environment variable
- 2:54:12still it is saying that it is not
- 2:54:14installed yes installation is taking
- 2:54:15some amount of time so let me pause the
- 2:54:17video till then I think it is going to
- 2:54:19take some time and then we will continue
- 2:54:21so guys the installation is taken place
- 2:54:23now you can go ahead and execute it and
- 2:54:25I think it should not give me an error
- 2:54:27now and your embeding hugging fish
- 2:54:29should be imported over here okay so
- 2:54:32perfect uh let's see uh it is going to
- 2:54:34take some amount of time again it's
- 2:54:36going to take somewhere around at least
- 2:54:371 minute because this particular
- 2:54:38embedding is quite big oh 13.1 seconds
- 2:54:41this is absolutely amazing and this is
- 2:54:43really good now after you have this
- 2:54:45hugging face embeddings we will try to
- 2:54:47use this hugging face embedding and try
- 2:54:49to just check on one of the file okay so
- 2:54:51I'll just go ahead and write embed
- 2:54:53uncore just to check whether it is
- 2:54:55working fine or not emid query and here
- 2:54:58I'm going to basically take my final
- 2:55:00underscore documents of zero okay so
- 2:55:04I'll just take the first one okay first
- 2:55:07one um and uh probably I will just go
- 2:55:11ahead and use the page uncore content
- 2:55:13because it'll be available over here uh
- 2:55:16now what I'm actually going to do if I'm
- 2:55:17specifically using these hugging face
- 2:55:19emings okay I will also go ahead and
- 2:55:21import numpy let's see import
- 2:55:24numi as NP and let me convert this into
- 2:55:28an array np. array
- 2:55:31okay I think so it should not be giving
- 2:55:34an error so we are just trying to see
- 2:55:37okay perfect so whatever was available
- 2:55:40in the first document of page content
- 2:55:41this is how the embedding is basically
- 2:55:43shown for the entire words okay whatever
- 2:55:46the words are specifically present in
- 2:55:47that particular embedding and uh if you
- 2:55:50probably go ahead and see this what is
- 2:55:52the shape of this particular array okay
- 2:55:55I will also print that specific shape
- 2:55:57okay let's go ahead and print this
- 2:56:01first print this first okay and then we
- 2:56:05will print
- 2:56:07it I will paste this do shape okay I
- 2:56:12think you'll be able to see the shape
- 2:56:14384 okay and it is also getting printed
- 2:56:16so perfect now what we going to do uh if
- 2:56:19this embedding technique is working fine
- 2:56:21then what we'll do we'll convert for uh
- 2:56:24the words into vectors by using this
- 2:56:26embedding technique and store it in a
- 2:56:27vector store so for that I already have
- 2:56:30imported FS so I'm going to probably
- 2:56:32create my Vector store and I'm going to
- 2:56:34write my f Dot and then I'm going to say
- 2:56:37from documents uh did I import F yeah it
- 2:56:43is imported from
- 2:56:44documents and from the documents what
- 2:56:47I'm actually going to do is is that I'm
- 2:56:48going to give my final
- 2:56:51documents my final documents till let's
- 2:56:54say I
- 2:56:55give 120 records okay there are
- 2:56:58somewhere on 310 records uh I'm not
- 2:57:01putting all because it is going to take
- 2:57:03time okay just to show it to you but
- 2:57:05later on once once you have time you can
- 2:57:07go ahead and increase this number and
- 2:57:09here I'm going to basically use hugging
- 2:57:11face embeddings okay so Vector store
- 2:57:13will basically get created so if I go
- 2:57:15ahead and execute this again it is going
- 2:57:17to take some amount of time at least 30
- 2:57:19to 40 seconds because there are so many
- 2:57:21documents over here and all this will be
- 2:57:23embedding right it'll get embedded into
- 2:57:26words and as you can understand every
- 2:57:28document will be getting converted into
- 2:57:30384 based on the chunks that we have
- 2:57:33specifically 384 vectors okay so this
- 2:57:35will basically be
- 2:57:38my this will be my Vector store creation
- 2:57:41okay and this is what is the step that
- 2:57:43we have specifically done in every step
- 2:57:46right Vector store creation perfect so
- 2:57:49let's wait for some time and I think it
- 2:57:51is 30 seconds it has crossed since uh
- 2:57:54120 before when I tried to do it it took
- 2:57:57me around 30 seconds because they were
- 2:57:59only 100 documents okay so 43.4 seconds
- 2:58:03perfect now we will try to use this
- 2:58:06Vector store and perform query using
- 2:58:09similarity search okay so similarity
- 2:58:13search will be basically done over
- 2:58:16here similarity search search will be
- 2:58:18done okay and once we specifically do
- 2:58:20the similarity search we will be able to
- 2:58:22see or we'll be able to get some kind of
- 2:58:24response over here okay so how to do the
- 2:58:26similarity search first of all I will go
- 2:58:28ahead and write my query uh with respect
- 2:58:31to the query you'll be able to see I
- 2:58:33will just write a question what is the
- 2:58:36health
- 2:58:37insurance okay now see this question
- 2:58:40that you'll be saying I did not just
- 2:58:42write it by purposely or somewhere uh uh
- 2:58:45here uh what I will be doing with what
- 2:58:48is the health
- 2:58:50insurance
- 2:58:52insurance coverage okay I what I did is
- 2:58:55that I just went to this folder
- 2:58:59okay and uh when I probably go ahead and
- 2:59:02see this folder I will just open my
- 2:59:04first file okay and this is where I show
- 2:59:07this question what is health insurance
- 2:59:09coverage so I will take up this question
- 2:59:11itself okay and I'll will paste it over
- 2:59:13here okay now once I paste it so this is
- 2:59:16the query that I'm actually searching
- 2:59:18I will go ahead and write relevant
- 2:59:20uncore documents since I need to
- 2:59:22probably retrieve that result that is
- 2:59:25present over there so what I will do I
- 2:59:27will use Vector
- 2:59:29store Vector store dot
- 2:59:34similarity
- 2:59:36similarity _ search okay and whatever
- 2:59:40query I have specifically
- 2:59:42written okay whatever query I have
- 2:59:45written and let's go ahead and print all
- 2:59:47the relevant
- 2:59:52documents let's go ahead and print all
- 2:59:54the relevant documents so once I print
- 2:59:57it I think I should be able to oh
- 3:00:00relevant relevant relevant
- 3:00:04relevant is this not the same
- 3:00:06thing okay so here you can see page two
- 3:00:10what is health insurance and here you'll
- 3:00:12be able to see the answer this brief
- 3:00:14prevents uh stage level everything uh
- 3:00:17you are able to see this right
- 3:00:18completely right and in order to get
- 3:00:21this what I will do to exactly get the
- 3:00:24page content so I will write underscore
- 3:00:26page content so whatever question I'm
- 3:00:28specifically asking you'll be able to
- 3:00:30see this is the brief present state
- 3:00:32level estimates of health insurance
- 3:00:34cover is it same or not so this brief
- 3:00:39presents state level estimates of health
- 3:00:41insurance coverage using data from
- 3:00:42American Community s server survey
- 3:00:45American Community survey so here you
- 3:00:47can see the US sensors and all
- 3:00:49everything is working absolutely fine
- 3:00:51okay uh sometime you also may be
- 3:00:54requiring uh you know more results right
- 3:00:57more let's say right now I'm just
- 3:00:59getting one result let's say I want two
- 3:01:01to three results now two to three
- 3:01:03similar kind of results now what I can
- 3:01:04actually do is that um or uh according
- 3:01:07to that particular text or query that
- 3:01:09I've asked the most relevant document I
- 3:01:11specifically want so what I can do I can
- 3:01:13basically write this Vector store okay
- 3:01:16vector
- 3:01:18store and I will specifically call as
- 3:01:22retriever function I hope everybody
- 3:01:24knows what is as retriever because we
- 3:01:26have discussed more different thing
- 3:01:28about it completely as retriever is just
- 3:01:30a kind of interface that gets connected
- 3:01:33to a vector store so that you'll be able
- 3:01:34to get more results more amazing results
- 3:01:37based on the similarity search and here
- 3:01:39I will say search type similarity but my
- 3:01:43search underscore
- 3:01:45arguments okay will be nothing but my
- 3:01:49search underscore arguments will be
- 3:01:51nothing but K is equal to
- 3:01:523 K colon 3 okay so this is what I will
- 3:01:57be probably getting the vector store
- 3:01:59okay and uh you can probably consider
- 3:02:02this as my retriever itself right so I
- 3:02:04will save this
- 3:02:06as retriever okay and then let's
- 3:02:14print retriever okay so here you can see
- 3:02:18F hugging face embeddings all the things
- 3:02:21and the number of search arguments like
- 3:02:23most relevant documents I require is
- 3:02:24three okay and now I can also use this
- 3:02:27particular retriever to invoke anything
- 3:02:29that I specifically want but before I
- 3:02:32invoke understand I also require an llm
- 3:02:35model now for those llm model as I said
- 3:02:37I'm going to use hugging face llm model
- 3:02:39now that is the reason the excess token
- 3:02:41that are actually created right I'm
- 3:02:43going to set up that excess token with
- 3:02:45my hugging face so I will write os.
- 3:02:47Environ
- 3:02:48okay and here first let me go ahead and
- 3:02:50import
- 3:02:52OS import OS os. environment my hugging
- 3:02:56face Hub API token so I'm going to set
- 3:02:59this up as my API token because from
- 3:03:02here hugging face Hub only will be
- 3:03:04downloading the model we'll be using the
- 3:03:05model and here we are going to
- 3:03:07specifically use my token key right I'm
- 3:03:10hardcoding the token over here because
- 3:03:12I've have copied it from there itself
- 3:03:14but don't use this because I'm going to
- 3:03:15regenerate that particular token okay it
- 3:03:17will be of no use okay now let's go
- 3:03:21ahead and if if you don't know about
- 3:03:23hugging face Hub guys what exactly is a
- 3:03:25hugging face and all uh I'll be writing
- 3:03:28some description over here for you all
- 3:03:30right so hugging face is a platform with
- 3:03:32over 350k models 75k data sets and 150k
- 3:03:36demo apps all in spaces all open source
- 3:03:38and publicly available in an online
- 3:03:40platform where people can easily
- 3:03:41collaborate and build ml together so I'm
- 3:03:44also going to use this uh uh same
- 3:03:47hugging face Hub and then I'm going to
- 3:03:49write from
- 3:03:51langin do
- 3:03:55community Lang chain uncore
- 3:03:59Community dot llms
- 3:04:04import hugging hugging face Hub right so
- 3:04:07I'm going to specifically use hugging
- 3:04:09face Hub I will create HF is nothing but
- 3:04:12hugging face
- 3:04:13Hub and now I will show you how you can
- 3:04:16call your models right the main
- 3:04:18parameter over here is nothing but you
- 3:04:20have to give your repore ID okay now
- 3:04:23here one repo ID since you are going to
- 3:04:25use the open source model is nothing but
- 3:04:26mistol right so this is basically a
- 3:04:29skeleton for you you can go ahead and
- 3:04:31replace the model whatever you want
- 3:04:33right so we going to use mistol 7B okay
- 3:04:36again it is up to you whatever model you
- 3:04:38specifically want to use only you have
- 3:04:39to give your repo ID along with this one
- 3:04:41more parameter that you really want to
- 3:04:43give is model arguments okay so in the
- 3:04:46model arguments here we will
- 3:04:48specifically give temperature parameter
- 3:04:50okay so temperature will be nothing but
- 3:04:52it will be 0.1 and the next parameter
- 3:04:55that you specifically going to give is
- 3:04:56nothing but Max underscore length Okay
- 3:05:00and this Max underscore length will be
- 3:05:02nothing but 500 okay so these are the
- 3:05:05two parameters that you really need to
- 3:05:06create uh so that you will be able to
- 3:05:09use this particular open source model
- 3:05:11understand one thing this will be
- 3:05:12directly using from the U hugging face
- 3:05:15Hub itself okay you don't need to
- 3:05:16download it locally for downloading if
- 3:05:18you want to download it locally and
- 3:05:20probably want to check it out so I will
- 3:05:21also give you the code for that you can
- 3:05:23which you can try it out okay now let me
- 3:05:25go ahead and write the same query so I
- 3:05:27will say query is equal to um what is
- 3:05:31the
- 3:05:33health same query
- 3:05:37insurance coverage okay so this is the
- 3:05:39query that I have now in order to invoke
- 3:05:42it I will use the same H HF do invoke
- 3:05:46okay and then I'm going to basically
- 3:05:48give my query so here you can see now I
- 3:05:51will be able to get my response and this
- 3:05:53is the most generic response right what
- 3:05:55is the health insurance cover I have
- 3:05:57just asked this is the most generic
- 3:05:58response which mral knows but my main
- 3:06:01aim is to probably create a Q&A app
- 3:06:04right Q&A app specifically for rag
- 3:06:06application so still it is not
- 3:06:08communicating communicating with my data
- 3:06:10that is available in my PDF okay so
- 3:06:12right now this is just given me a
- 3:06:13general uh General output okay General
- 3:06:16output what is available with respect to
- 3:06:18the knowledge of the internet now the
- 3:06:20next step what we are specifically going
- 3:06:22to do see understand if you want to make
- 3:06:24sure that we interact with our PDFs this
- 3:06:26hugging face uh llm models we have to
- 3:06:28probably create our own promp template
- 3:06:30one more thing that I really wanted to
- 3:06:31show is that um if you want to download
- 3:06:35locally right hugging face models can be
- 3:06:37run locally through hugging face
- 3:06:38pipeline so here is the uh new code
- 3:06:41before we used to use hugging face Hub
- 3:06:43here you have hugging face pipeline same
- 3:06:45code for TAS generation everything you
- 3:06:47can probably execute this and this will
- 3:06:49basically be uh able to generate it okay
- 3:06:52but I'm not going to use this since I've
- 3:06:53already trying to use from this right so
- 3:06:55it is going to take some amount of time
- 3:06:57with respect to execution perfect now
- 3:07:00this is done now as I know I need to use
- 3:07:03this llm model to interact with my PDF
- 3:07:05so for that I will try to create my
- 3:07:06prompt
- 3:07:08template okay now the prompt template
- 3:07:10will be nothing but
- 3:07:12I'll I'll be
- 3:07:22use
- 3:07:23the
- 3:07:25following piece of
- 3:07:27context okay to answer the
- 3:07:32question the question asked
- 3:07:36okay so uh here is the simple prompt
- 3:07:40that I have used use the following piece
- 3:07:42of
- 3:07:43context uh piece of context to answer
- 3:07:46the use the following piece of to answer
- 3:07:48the question
- 3:07:52asked
- 3:07:54please try to
- 3:07:56provide the
- 3:07:58answers only based on the context okay
- 3:08:01so I'm just giving a simple prompt okay
- 3:08:04pretty simple prompt okay now my context
- 3:08:07will be over here C and txt okay and
- 3:08:10then my question will be nothing but
- 3:08:12it'll be over here and I think we have
- 3:08:13done this many number of times in my
- 3:08:15previous video okay and and uh if I want
- 3:08:19one more thing I can probably give I
- 3:08:21will just write helpful answers okay and
- 3:08:25I'll keep it blank okay so this is my
- 3:08:27prompt template that I'm going to use
- 3:08:29and then in order to make it as a this
- 3:08:31I'm going to use my prompt template
- 3:08:32prompt template uh my template will be
- 3:08:35assigned to this same prompt same same
- 3:08:38prompt uh I think this is assigned to
- 3:08:40this prompt okay so this will basically
- 3:08:43be my
- 3:08:44prompt okay and then my input
- 3:08:48variables will be having two things one
- 3:08:52is context
- 3:08:56okay context and the other one is
- 3:08:59question
- 3:09:01oops same question just a
- 3:09:07second
- 3:09:09question okay so context and question we
- 3:09:12are setting it as an input variable and
- 3:09:13this basically becomes my prompt itself
- 3:09:16okay so I'm going to execute this okay
- 3:09:19now understand if I want to combine okay
- 3:09:23I if I want to combine my Lang chain
- 3:09:27right my my sorry not Lang chain my my
- 3:09:30template with the llm models obviously
- 3:09:32what you really need to do so that we
- 3:09:34also get the context in the question
- 3:09:36it's create retrieval QA right so create
- 3:09:38retrieval QA chain right so if you
- 3:09:40remember that in my previous video one
- 3:09:42more way that I can specifically do is
- 3:09:44by using this retrieval QA right and in
- 3:09:47order to use this retrieval QA here what
- 3:09:50I will do I will just write from chain
- 3:09:53type okay from chain type and here I'll
- 3:09:56start giving my parameters that I
- 3:09:58require first parameter is nothing but
- 3:10:00llm llm will be nothing but HF whatever
- 3:10:03the hugging face library that we have
- 3:10:04created I will create my chain type as
- 3:10:08stuff okay so chain type will be nothing
- 3:10:11but
- 3:10:13stuff the next parameter that we are
- 3:10:15specifically going to do is my retriever
- 3:10:18which will be assigned to my retriever
- 3:10:19itself which is basically defined return
- 3:10:22Source document you can keep it as true
- 3:10:26or false so that you'll be able to
- 3:10:28understand from where it is basically
- 3:10:29coming up so return Source documents
- 3:10:32which will be assigned to True okay and
- 3:10:34the next parameter is nothing but it is
- 3:10:36my chain type chain type KW RGS okay and
- 3:10:42you can also check out this entire
- 3:10:44documentation from the from the Lang
- 3:10:48chain documentation so prompt will be
- 3:10:49nothing but it will be assigned to this
- 3:10:51particular prompt okay sorry this prompt
- 3:10:54so this is done like most of the things
- 3:10:56have been completed over here but
- 3:10:58understand one thing in retrieval QA you
- 3:11:00have to give your hugging face your
- 3:11:02chain type stuff your retriever return
- 3:11:05Source document so that you need to
- 3:11:07understand from where it is coming and
- 3:11:08CH time arguments is nothing but with
- 3:11:10respect to the prompt so this prompt
- 3:11:12will return some of the documents it
- 3:11:13will be setting up in the context then
- 3:11:15question will go over there and entire
- 3:11:17this retrieval q and will work okay so
- 3:11:19here I'm going to write it as
- 3:11:23retrieval QA right so this will
- 3:11:26basically be there let me quickly go
- 3:11:28ahead and execute it okay now it's final
- 3:11:31that you just need to run it in order to
- 3:11:33run it here is the question right so now
- 3:11:37finally we can use this retrieval QA
- 3:11:39that we have actually created and we
- 3:11:40invoking with respect to the query that
- 3:11:42we have already WR what is the health
- 3:11:44coverage and finally let's go ahead and
- 3:11:46check our result so here you can see
- 3:11:48what is health and insurance covers the
- 3:11:50brief presents the state level estimates
- 3:11:52of this American Community survey the US
- 3:11:55cons US Census Bureau conducts ACS
- 3:11:57throughout the year the service asks
- 3:11:59responds to report the coverage at a
- 3:12:01time so every information is
- 3:12:02specifically given now you can go ahead
- 3:12:04and ask some other questions also if you
- 3:12:07want um let me go ahead and ask this
- 3:12:11differences in the uninsured rate by
- 3:12:14state okay so I'll go ahead and ask this
- 3:12:17let me go ahead and write my new query
- 3:12:19so query is equal
- 3:12:29to let me just go ahead and close this
- 3:12:34in okay so here is my query so let me go
- 3:12:38ahead and execute it now if I go ahead
- 3:12:40and see this it should be able to give
- 3:12:42me the response so here is a comparison
- 3:12:44of ASM measure of health insurance so
- 3:12:46everything is probably matching over
- 3:12:48here see unsur rates of this this this
- 3:12:50is coming up okay so all the information
- 3:12:53are specifically coming up from here
- 3:12:55this is perfect uh now we have I've also
- 3:12:58shown you how you can probably work with
- 3:13:00Lang chain and hugging face so let me go
- 3:13:02ahead and update uh this also if you
- 3:13:05want okay um insert sell CH sale to
- 3:13:10insert okay so perfect this is it uh I
- 3:13:16hope you like this this particular video
- 3:13:18uh at the end of the day uh the one
- 3:13:20thing that I really want to say is that
- 3:13:22more you practice things more you see
- 3:13:24things definitely you'll be able to
- 3:13:25achieve multiple things over here so yes
- 3:13:28I hope you like this particular video
- 3:13:29this was it from my side I'll see you in
- 3:13:31the next video have a great day ahead
- 3:13:32thank you one all take care bye-bye
About this transcript
This page contains the full transcript of Complete Langchain Course For Generative AI In 3 Hours by Krish Naik, generated from the public captions YouTube serves with the video. The transcript has 34,431 words across 4,794 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.