YouTube2Text

Complete Langchain Course For Generative AI In 3 Hours — Transcript

by Krish Naik · 34,431 words · 4,794 segments · language en · Watch on YouTube

Full transcript

  1. 0:00hello all my name is krishak and welcome
  2. 0:02to my YouTube channel so guys here is
  3. 0:04one amazing one short video on Lang
  4. 0:06chain in order to learn generative AI so
  5. 0:09if you are interested in creating
  6. 0:10amazing llm application or gen AI power
  7. 0:13uh application then this specific video
  8. 0:16is definitely for you if you don't know
  9. 0:18about Lang chain it is a complete
  10. 0:19framework that will actually help you to
  11. 0:21create Q&A chatbots rag application and
  12. 0:24many more the most interesting thing
  13. 0:26will be that I will be covering all the
  14. 0:28paid llm models along with that open llm
  15. 0:30models even though that they are hosted
  16. 0:32in hunging face so we will be getting to
  17. 0:34know each and everything about it and
  18. 0:36how we can specifically use in Lang
  19. 0:37chain so I hope you enjoy this
  20. 0:39particular video and please make sure
  21. 0:41that you watch this video till the end
  22. 0:43so thank you let's go ahead and enjoy
  23. 0:45the series uh before I go ahead guys uh
  24. 0:48since uh you know there's some there
  25. 0:50should be some motivation for me also so
  26. 0:52I will keep the light Target to th000
  27. 0:55please make sure that you hit like share
  28. 0:57with all your friends and we'll also
  29. 0:59keep a target of comments okay 200
  30. 1:01comments I know you will be able to do
  31. 1:03it so let's keep that specific Target
  32. 1:05and let's understand what all things we
  33. 1:07are going to learn uh about Lang chain
  34. 1:10and then we'll also understand the
  35. 1:12second topic that we are going to
  36. 1:13understand in this specific video is
  37. 1:15about the Lang chain ecosystem and how
  38. 1:17it is related to each other now uh right
  39. 1:20now in the langin documentation if you
  40. 1:22probably see the recent updates that are
  41. 1:25there mainly uh most of the modules
  42. 1:28revolve around this particular topics in
  43. 1:30Lang chain okay so over here you'll be
  44. 1:32able to see lsmith uh here you'll be
  45. 1:34able to see Langer if I talk about
  46. 1:37lsmith recently I had also made a video
  47. 1:39on this uh just a simple video but I
  48. 1:41will try to create more videos on that
  49. 1:43when we go in this specific Series so
  50. 1:45lsmith is if I probably give you some
  51. 1:47examples it is it'll help you to monitor
  52. 1:50your application it'll help you to debug
  53. 1:53your application so in short whatever
  54. 1:56mlops activities is specifically
  55. 1:58required with respect to mon in
  56. 2:00deploying sorry debugging testing you
  57. 2:02know so third point I will say testing
  58. 2:04you can specifically use this amazing
  59. 2:06module in Lang langin that is called as
  60. 2:08lsmith the best thing will be that all
  61. 2:11the reports all the analytics you'll be
  62. 2:13able to see very much easily in this
  63. 2:16ecosystem itself in the langin ecosystem
  64. 2:18so there is a dashboard in langin which
  65. 2:19you'll be able to see it okay now how we
  66. 2:22going to use in this use this entire
  67. 2:24technique in some projects we'll be
  68. 2:26seeing completely end to end and we'll
  69. 2:28also be able to understand this so if I
  70. 2:31talk about lsmith it is mostly of U if I
  71. 2:34say llm Ops okay so this part that is
  72. 2:38right now required uh in many many
  73. 2:40companies so that part we'll also be
  74. 2:42able to cover it that is the reason why
  75. 2:44I like langen because it is providing
  76. 2:45you the entire ecosystem irrespective of
  77. 2:48any llm model okay any llm model now
  78. 2:51coming to the second thing over here you
  79. 2:52have Langer let's say that you have
  80. 2:54created your llm application you
  81. 2:57obviously want your entire llm
  82. 2:59application in the the form of apis
  83. 3:01right without writing much code yes you
  84. 3:03can write the code from scratch with the
  85. 3:05help of flask or some other some other
  86. 3:07libraries but here Lang uses something
  87. 3:10called as fast API okay and because of
  88. 3:13this fast API you know creation of this
  89. 3:16particular apis becomes very much easy
  90. 3:19so we'll be also able to understand it
  91. 3:21before the deployment if I have actually
  92. 3:23created my own llm app how I can
  93. 3:26actually create all the services in the
  94. 3:28form of apis that we'll try to see with
  95. 3:30respect to the Langer now coming to the
  96. 3:33next thing there are some amazing
  97. 3:35Concepts and important Concepts in Lang
  98. 3:36chain from data inje to data
  99. 3:38transformation and all in that major
  100. 3:41major topics are with respect to chains
  101. 3:43we'll try to understand about chains and
  102. 3:45probably in the next video once I
  103. 3:46probably start the Practical
  104. 3:47implementation the first thing that I'm
  105. 3:49actually going to cover is with respect
  106. 3:50to chains and I'm also going to discuss
  107. 3:54something called as agents and retrieval
  108. 3:56right not only that U you'll be able to
  109. 3:58see there is a concept of LC okay now in
  110. 4:01this LC we will be discussing and this
  111. 4:04full form is Lang chain expression
  112. 4:06language right so there are lot of
  113. 4:08Concepts that are specifically used in
  114. 4:10LC we'll also see that how it is
  115. 4:12basically important while you are
  116. 4:14building what are techniques it actually
  117. 4:16has when you're creating your own
  118. 4:18generative AI power application right
  119. 4:20along with that uh there are three main
  120. 4:22topics also which I will be able to
  121. 4:24cover it while I will be discussing all
  122. 4:26these things that is about model iio
  123. 4:28retriever agent tooling and all uh these
  124. 4:30are Concepts that you should really know
  125. 4:32uh the main aim of this entire series is
  126. 4:35not to make you understanding
  127. 4:36theoretical concept but uh it's more to
  128. 4:39understand how you can create amazing
  129. 4:41generative AI applications irrespective
  130. 4:43of any llm model now see guys one of the
  131. 4:46question that I get from many people hey
  132. 4:47Kish uh I'm using this specific llm
  133. 4:50model I don't have openi access I don't
  134. 4:52have API access tell me what should I do
  135. 4:54you know uh let's say many people say
  136. 4:57that hey Krish I don't have credit card
  137. 4:58for open AI
  138. 5:00right can you show me some examples with
  139. 5:02respect to open source models like
  140. 5:05Google gini or some other mrr what about
  141. 5:08open source models right see llm over
  142. 5:10here as I said Lang chin is an amazing
  143. 5:12framework to build the entire
  144. 5:13application and creating the best llm is
  145. 5:17already a rat race so if I probably say
  146. 5:19this is a rat race by Tech Giants right
  147. 5:22so Google will be competing meta will be
  148. 5:24competing um uh you know anthropic will
  149. 5:27be competing um openi will be comp
  150. 5:29rating so you don't even have to worry
  151. 5:31about this right whatever models will be
  152. 5:33probably coming up in the future don't
  153. 5:35worry about this the main thing is that
  154. 5:37how you can use this llm app in a
  155. 5:39generic way to build any kind of
  156. 5:41application so here whatever model it
  157. 5:43may come you just need to stay up to
  158. 5:45date right which model has the best
  159. 5:47accuracy and all that will basically
  160. 5:49happen over here right later on all the
  161. 5:51integration part will be completely
  162. 5:53generic okay now let's go ahead and
  163. 5:56understand the entire Lang chain
  164. 5:58ecosystem like what are are the very
  165. 6:00important things so this is a diagram
  166. 6:01that I have already taken from the Lang
  167. 6:03chin so as I already discussed with
  168. 6:05respect to lsmith the first model that
  169. 6:07you see over here we basically say it as
  170. 6:09observ observability right and with the
  171. 6:12help of lsmith you will be able to do
  172. 6:14debugging playground evaluation
  173. 6:17annotation and monitoring when I say
  174. 6:19annotation it's all about creating your
  175. 6:21own custom data set which will require
  176. 6:24uh with respect to finetuning or
  177. 6:25creating your gen AI powered application
  178. 6:28the next thing is with respect to
  179. 6:29deployment and recently uh right now
  180. 6:31Lang Ser has actually come it'll be in
  181. 6:34the form of API so here it is written
  182. 6:36right chains as rest API whatever
  183. 6:38Services you are specifically providing
  184. 6:40Lang chain soon will also come up with
  185. 6:42only one click deployment mechanism once
  186. 6:44you probably create this entire apis
  187. 6:46with the help of langub the next thing
  188. 6:48is that you just need to deploy it okay
  189. 6:51then um and already I have created a
  190. 6:54couple of videos on Langs Smith and Lang
  191. 6:56langsa but don't worry uh in this entire
  192. 6:59series I'm going to again start from
  193. 7:00fresh combine new topics and create a
  194. 7:03project Okay the third thing that you
  195. 7:05really need to understand is about
  196. 7:07templates okay so there are different
  197. 7:09different templates reference the
  198. 7:11application uh with respect to Lang
  199. 7:14chain you need to understand these three
  200. 7:16important things chains agent and
  201. 7:18retrieval strategies so we'll try to
  202. 7:20understand that how these things work
  203. 7:21and understand guys you will be able to
  204. 7:23get the code with respect to Python and
  205. 7:24JavaScript but my main aim will be with
  206. 7:27respect to python because in some of the
  207. 7:28article it was already said that AGI
  208. 7:30application is going to get created in
  209. 7:32Python okay then you also have some
  210. 7:34integration components so we are
  211. 7:37understanding about the ecosystem
  212. 7:39because all these things we are going to
  213. 7:40discuss in this specific playlist itself
  214. 7:42so here you have model iio here you have
  215. 7:44retrieval here you have agenting tool so
  216. 7:47retrieval you also will be having
  217. 7:49features to read your data set from
  218. 7:51different different uh data sources how
  219. 7:54you can actually create vector edings
  220. 7:55and all and all are there right in model
  221. 7:57iio you have various techniques with
  222. 7:59respect to model chain prompt example
  223. 8:02selector and output parcel and finally
  224. 8:05you'll be also seeing that we'll be
  225. 8:06focusing on this amazing thing which is
  226. 8:08called as protocol which is basically
  227. 8:10coming under Lang chain core and here we
  228. 8:12are going to discuss about Lang chain
  229. 8:14expression language right so there are
  230. 8:17some important Concepts like
  231. 8:18paralyzation fallback tracing batching
  232. 8:20streaming a sync and composition so all
  233. 8:23these things we are basically going to
  234. 8:24cover and then we will be focusing on
  235. 8:27end to end projects how you can use all
  236. 8:31these Concepts together right understand
  237. 8:34one thing guys when we create L when we
  238. 8:36use Lang ser and start creating rest
  239. 8:38apis we'll also be writing our we'll
  240. 8:42also be writing our uh client side code
  241. 8:45so that we'll be able to access those
  242. 8:47kind of apis right so all these things
  243. 8:50in the form of ecosystem will get
  244. 8:52completely covered trust me again why
  245. 8:55I'm saying this is this is important
  246. 8:57because tomorrow whatever llm models may
  247. 9:00come right how advanced it may be Lang
  248. 9:03chain will be a generic framework which
  249. 9:05will actually help you to build any kind
  250. 9:07of llm application in this video I will
  251. 9:09be showing you how you can create
  252. 9:11chatbot applications with the help of
  253. 9:13both paid apis llm along with that we'll
  254. 9:16also see how you can integrate with open
  255. 9:18source llms now you should definitely
  256. 9:20know both the specific ways how you can
  257. 9:23actually do it one way to basically
  258. 9:26integrate any open source llm is through
  259. 9:28hugging face but as as you know that I'm
  260. 9:30focusing more on the Lang chain
  261. 9:32ecosystem and with respect to hugging
  262. 9:34face I've already uploaded a lot of
  263. 9:35videos in my YouTube channel and how you
  264. 9:37can actually call these kind of Open
  265. 9:39Source llms but since we are working
  266. 9:41with the langen ecosystem we will try to
  267. 9:43use all the components that are
  268. 9:45available in langen as you all know guys
  269. 9:47uh this is a fresh playlist and
  270. 9:49obviously my plan is that this month I
  271. 9:52will be focusing entirely on langin many
  272. 9:55more videos will be coming up many more
  273. 9:56amazing videos along with end to endend
  274. 9:59applic
  275. 10:00fine tuning many more things is going to
  276. 10:02come up so please make sure that we'll
  277. 10:04keep a like Target for every video and
  278. 10:06for this video the like Target is 1,000
  279. 10:08and at least 200 comments and please
  280. 10:10make sure that you watch this video till
  281. 10:12the end because it is going to be
  282. 10:14completely practical oriented okay and
  283. 10:17uh if you really want to support please
  284. 10:19make sure that you subscribe the channel
  285. 10:21and take up membership plan from my
  286. 10:22YouTube channel so that it will help me
  287. 10:25and with the help of those benefits I
  288. 10:27will be able to create more videos as
  289. 10:28such so let me quickly go ahead and
  290. 10:30share my screen so here is my screen
  291. 10:32over here and you'll be able to see in
  292. 10:35the GitHub that you'll be finding in the
  293. 10:37description of this particular video
  294. 10:38you'll be having folders like this so
  295. 10:40today is the third tutorial not third
  296. 10:43second tutorial uh in the first and
  297. 10:45second we just understood that what all
  298. 10:46things we are going to learn but in this
  299. 10:49is the real practical implementation
  300. 10:51that is probably there so as usual the
  301. 10:53first thing that we are going to do is
  302. 10:54that create our V andv environment how
  303. 10:57to create it cond create minus pvnv
  304. 11:00python is equal to 3.10 you can probably
  305. 11:02take 3.10 version and I have already
  306. 11:04shown you how to create virtual
  307. 11:06environments in many number of videos
  308. 11:08then you'll be using EnV file so this
  309. 11:10will basically be my environment
  310. 11:12variable um in this environment variable
  311. 11:14I will be putting three important
  312. 11:16information one is Lang chain API key uh
  313. 11:20the second one is open a API key and
  314. 11:22Lang chain project you might be thinking
  315. 11:24this open API key I've kept it as open
  316. 11:27no it is not I've changed some of the
  317. 11:29numbers over here so don't try it out
  318. 11:31it'll be of no use okay and then the
  319. 11:34third environment variable that I'm
  320. 11:36actually going to create is my Lang chin
  321. 11:38project name that is tutorial one I have
  322. 11:40written it over here the reason why I
  323. 11:43have written this because whenever I try
  324. 11:45to go ahead and see in my lsmith right I
  325. 11:48will be able to see observe the entire
  326. 11:50I'll be able to monitor each and every
  327. 11:52calls from the dashboard itself how we
  328. 11:54will be using this everything I will be
  329. 11:56discussing about it okay so all these
  330. 11:58things will spe specifically get
  331. 11:59required and uh all this will be used in
  332. 12:02our environment variable so these are
  333. 12:04the three parameters I have already
  334. 12:05created myv file so let's go ahead and
  335. 12:08start the coding okay and you have to
  336. 12:10make sure that you code along with me
  337. 12:12because this is the future AI
  338. 12:15engineering things are basically coming
  339. 12:16up I'll just show you initially with the
  340. 12:18foundation model later on this
  341. 12:20complexity will keep on increasing so
  342. 12:22let's go ahead and start our first code
  343. 12:25now what is our main aim what we are
  344. 12:28trying to do in our first project let me
  345. 12:30just discuss about because these are all
  346. 12:32the things that we going to discuss in
  347. 12:33the future but first thing that we will
  348. 12:36try to create is our normal chat GPT
  349. 12:38application okay I'll not say chat GPT
  350. 12:41but a normal chatbot okay and this
  351. 12:43chatbot will be important it will be
  352. 12:46helping you to probably create chatbot
  353. 12:48with the help of both paid and open open
  354. 12:51open source llm model so this will be
  355. 12:53the chatbot that we will be creating one
  356. 12:56way is that we will be using some paid l
  357. 12:59l m now paid llms one example I can show
  358. 13:02it with the help of open AI API okay
  359. 13:05open AI API the second one that I will
  360. 13:09try to probably show it uh or you can
  361. 13:11also use cloudy API so that is from a
  362. 13:15company called as anthropic okay that
  363. 13:18you can do and one more I will try to
  364. 13:19use it with the help of Open Source
  365. 13:22llm see calling apis is a very easy task
  366. 13:27okay but the major thing is that since
  367. 13:30we have so many modules we are going to
  368. 13:32use Lang chain as suggested right and in
  369. 13:35Lang chain we definitely have so many
  370. 13:37modules how we can use this modules for
  371. 13:40different different calls and along with
  372. 13:43this whenever we are developing any
  373. 13:45chatbot application what all
  374. 13:47dependencies we have specifically right
  375. 13:51dependencies now if you probably see
  376. 13:53this diagram here you'll be able to see
  377. 13:55there will be model prompt output parcel
  378. 13:58so in our video in this video I'm going
  379. 14:01to see some of the features with respect
  380. 14:02to lsmith I'm going to see some of the
  381. 14:05features with respect to chains and
  382. 14:06agents and I'm also going to use some of
  383. 14:09the feature present in model and output
  384. 14:11parcel so all this combination we going
  385. 14:13to specifically use and that is the
  386. 14:15reason how this is how I'm going to
  387. 14:17create the all the projects that we are
  388. 14:18doing entire videos that are probably
  389. 14:21going to come up will be much more
  390. 14:23practical oriented okay so now let's
  391. 14:25start our first chatbot application so
  392. 14:28here I will go ahead and write from Lang
  393. 14:31chin okay from
  394. 14:34linore open a since I'm going to use
  395. 14:36open a
  396. 14:38import chat open AI okay
  397. 14:43chat open a so this is the first one
  398. 14:47that we're going to basically do from
  399. 14:48Lang chain see this three things will
  400. 14:52definitely be required then one is chat
  401. 14:54openi or whatever open you whatever chat
  402. 14:57model that you're going to use how to
  403. 14:59call Open Source I will also be
  404. 15:00discussing about that first of all we'll
  405. 15:02start with opening API itself okay so
  406. 15:04from Lang chinor
  407. 15:06core. prompts I'm going to
  408. 15:10import chat prompt template okay chat
  409. 15:14prompt template so this is the next
  410. 15:15thing that we are probably going to use
  411. 15:17chat prompt template okay at any point
  412. 15:21of time whenever you create a chat bot
  413. 15:24right this chat prom template will be
  414. 15:26super important right here is what
  415. 15:27you'll you'll basically give the initial
  416. 15:30prompt template that is actually
  417. 15:31required Okay the third library that I'm
  418. 15:34actually going to import is from Lang
  419. 15:35chain uncore core dot output uncore
  420. 15:41parsers okay
  421. 15:43input H
  422. 15:46Str
  423. 15:48output parcel okay now this three are
  424. 15:53very important this string Str Str
  425. 15:55output processor is the default output
  426. 15:57processor whenever your llm model gives
  427. 15:59any kind of response you can also create
  428. 16:02a custom output parer that also I will
  429. 16:04be showing you in the upcoming videos
  430. 16:06okay this custom output parcel you can
  431. 16:09do anything with respect to the output
  432. 16:10that probably comes you want to do a
  433. 16:12split you want to make it as a capital
  434. 16:13letter anything right you can write your
  435. 16:15own custom code with respect to this but
  436. 16:17by default right now I'm going to use
  437. 16:19just St Str output parsel now along with
  438. 16:22this the next thing that I'm actually
  439. 16:23going to do is that I'm going to use
  440. 16:25streamlet as St okay stream streamlet as
  441. 16:29St then I'm going to also import OS and
  442. 16:33since I'm also going to use from
  443. 16:35EnV import load. EnV so that we'll be
  444. 16:41able to import all our libraries okay so
  445. 16:44let's see whether everything is working
  446. 16:46fine or
  447. 16:49not okay U from EnV so here I'm going to
  448. 16:53basically write
  449. 16:56python loore
  450. 16:59sorry python app.py I'm just running it
  451. 17:02so that everything works fine and all
  452. 17:04our libraries will also get ined
  453. 17:06cannot python app.py okay I have to
  454. 17:09probably go to my chatbot folder CD
  455. 17:12chatbot so now I'll clear my screen
  456. 17:15python
  457. 17:19appp oh
  458. 17:24sorry from streamlet as St okay import
  459. 17:28stream as H I have to write so that is
  460. 17:31the reason it was coming all this errors
  461. 17:33now let's see if everything is working
  462. 17:36fine Lang chain core so here you can
  463. 17:39probably see that there is a spelling
  464. 17:41mistake okay but I'm just going to keep
  465. 17:43all the errors like this so that you'll
  466. 17:46be able to see it python app.py if
  467. 17:49everything works fine uh output parser
  468. 17:52okay P Capital
  469. 17:55um so I think my suggestion box is not
  470. 17:59working well and that is the reason now
  471. 18:01everything is working fine uh here you
  472. 18:04can see that I'm not getting any error
  473. 18:05so let's start our coding and let's
  474. 18:07continue it okay so we have imported all
  475. 18:09these things right now now as I
  476. 18:11suggested guys since we are going to use
  477. 18:13three environment variables one is the
  478. 18:15open API key Lang chain API key and
  479. 18:17along with that I will also make sure
  480. 18:20that the tracing to capture all the
  481. 18:22monitoring results I will keep this
  482. 18:24three environment variable one is
  483. 18:25opening API key lch tracing verion to
  484. 18:29and langin API key so langin API key
  485. 18:32will actually help us to know that where
  486. 18:35the entire monitoring results needs to
  487. 18:37be stored right so that dashboard you'll
  488. 18:39be able to see all the monitoring
  489. 18:41results will be over here and tracing we
  490. 18:43have kept it as true so it is
  491. 18:45automatically going to do the tressing
  492. 18:46with respect to any code that I write
  493. 18:48and this is not just with respect to
  494. 18:50paid apis with open source llm also
  495. 18:52you'll be able to do it now this is the
  496. 18:54second step that I've actually done now
  497. 18:55let's go ahead and Define my promt
  498. 18:57template simple so here I'm going to
  499. 19:00write my prompt
  500. 19:02template okay promt template so here I'm
  501. 19:06going to Define prompt is equal to chat
  502. 19:09prompt template dot okay from uncore
  503. 19:14messages
  504. 19:16okay and here I'm going to Define my
  505. 19:18promt template in the form of list the
  506. 19:20first thing that with respect to my
  507. 19:23promp template that I'm going to give is
  508. 19:24nothing but system and system here I say
  509. 19:28that you you
  510. 19:29are
  511. 19:31a helpful
  512. 19:35assistant
  513. 19:36please
  514. 19:38respond to the queries okay please
  515. 19:43respond to the questions or queries
  516. 19:45please response to the user queries okay
  517. 19:49whatever queries that I'm going to
  518. 19:50specifically ask a simple prompt that
  519. 19:53you can probably see over here the next
  520. 19:55statement uh after this is what
  521. 20:01so this will be my next see if I'm
  522. 20:04giving a system prompt I also have to
  523. 20:05give a user prompt right user prompt
  524. 20:07will be whatever question I ask so this
  525. 20:10will be user and here I will define
  526. 20:12something like
  527. 20:13question colon question I can also give
  528. 20:17context if I want but right now I'll
  529. 20:19just give it as a question a simple
  530. 20:20chatbot application so that you'll be
  531. 20:23able to start your practice of creating
  532. 20:25all the chat bots so now I will go ahead
  533. 20:28and my streamlet framework okay see the
  534. 20:32learning process will be in such a way
  535. 20:34that I will try to create more projects
  536. 20:36and use functionalities that are there
  537. 20:38right and in this way you'll be able to
  538. 20:40work it in an amazing way okay so here
  539. 20:42I'm going to basically write st. title
  540. 20:44Lang chain demo with the opening API
  541. 20:47std. textor input search the text topic
  542. 20:50you want okay now let us go ahead and
  543. 20:53call my open AI llms okay open AI llm so
  544. 20:57here I'm going to be basically write llm
  545. 20:59and whenever we use openi API so it will
  546. 21:02be nothing but chat open Ai and here I'm
  547. 21:04going to give my model name the model
  548. 21:06name will be nothing but GPT GPT 3.5
  549. 21:11turbo so I'm going to use turbo because
  550. 21:13the cost is less for this i' I put $5 in
  551. 21:16my openingi account okay just to teach
  552. 21:18you so please make sure that you support
  553. 21:21so that I will be able to explore all
  554. 21:23these tools and create videos for all of
  555. 21:25you okay and finally my output parser
  556. 21:28see always remember Lang chain provides
  557. 21:31you features that you can attach in the
  558. 21:34form of chain right so here three main
  559. 21:36things we have created one is the chat
  560. 21:38prom template next one is the llm and
  561. 21:40next one is the output parcel obviously
  562. 21:43this is the first thing that we require
  563. 21:45after this we integrate with our llm and
  564. 21:47then finally we get our output so string
  565. 21:49output parser is responsible in getting
  566. 21:51the output itself finally chain is equal
  567. 21:54to we will just combine all these things
  568. 21:56so here I'm going to write prompt L LM
  569. 21:59and then finally my output parsel right
  570. 22:02I will show you going forward how we can
  571. 22:05customize this entire output parsel and
  572. 22:06all and finally if I write if input text
  573. 22:11if input undor text colon now whenever I
  574. 22:16write any input and probably press enter
  575. 22:19Then I should be able to get this output
  576. 22:21so std. WR and here I'm going to just
  577. 22:23write chain. invoke and finally I get
  578. 22:29I give my input as question and that
  579. 22:32input is assigned to my input text input
  580. 22:36text right so this is what we are going
  581. 22:38to basically do right st. write now this
  582. 22:42is what we are doing a simple chatbot
  583. 22:44application but along with this we have
  584. 22:47implemented this this this feature is
  585. 22:49specifically for Langs Smith Langs
  586. 22:52Smith
  587. 22:54Lang Smith tracking okay this will be
  588. 22:58amazing for to use okay and this is the
  589. 23:02recent updates that are there so
  590. 23:04whatever code I'm writing will be
  591. 23:05applicable going forward in various
  592. 23:08things that are probably going to come
  593. 23:09up okay now let's go ahead and run this
  594. 23:12so in order to run it you'll just need
  595. 23:16to write nothing but streamlet
  596. 23:20Run app.py Okay oops there is an error
  597. 23:26app.py and here I'll to allow access
  598. 23:29okay so right now you'll be able to see
  599. 23:31over here Lang chain series test llm but
  600. 23:34my my my project name was Project one
  601. 23:37okay so now if I go ahead and hit hey hi
  602. 23:40okay and just press enter you'll be able
  603. 23:43to see that we'll be getting this
  604. 23:45information over here and here you can
  605. 23:47see my project something let me reload
  606. 23:51it tutorial one right so this is the
  607. 23:53first request that is already been H and
  608. 23:56here you'll be able to see your enable
  609. 23:58sequest chat prom template right all the
  610. 24:00chat prom template output message your
  611. 24:03helpful assistance pleas response to the
  612. 24:04user queries right along with this you
  613. 24:07will be seeing chat open AI API and with
  614. 24:10respect to this what was the cost
  615. 24:11everything you are able to track so
  616. 24:14027 is the cost that actually took with
  617. 24:18respect to this and finally my string
  618. 24:19output parser how can you assist today
  619. 24:22with respect to this output parsel it is
  620. 24:23just going to give me the response
  621. 24:25clearly now when I develop my own custom
  622. 24:28output parel I'll be able to track
  623. 24:29everything so here what you are able to
  624. 24:31do you are able to monitor each and
  625. 24:33everything that is there right all the
  626. 24:35request that is probably coming up okay
  627. 24:37so provide me a python
  628. 24:40code a python code to swap two
  629. 24:45numbers okay so once I execute this and
  630. 24:48here you'll be able to see that I'm able
  631. 24:50to get the output and answer everything
  632. 24:52is over here and for this you'll be able
  633. 24:54to see the cost will be little bit High
  634. 24:56okay if you don't agree with me or let's
  635. 25:00see with respect to tutorial one the
  636. 25:01second request that I've actually got
  637. 25:034.80 seconds yes it took a little bit
  638. 25:06more time and here the cost was
  639. 25:090211 so it is based on the token size
  640. 25:12right for every token it is bearing some
  641. 25:14kind of cost perfect uh this was the
  642. 25:16first part of this particular tutorial
  643. 25:18now let's go to the second part uh the
  644. 25:20second part is more about making you
  645. 25:23understand that how you can call um open
  646. 25:26source llms in your local itself and how
  647. 25:29you can actually use it so for this
  648. 25:30first of all I will go ahead and
  649. 25:32download olama okay AMA is an amazing
  650. 25:35thing because you'll be able to run all
  651. 25:38the large language models locally uh the
  652. 25:41best thing about AMA is that it
  653. 25:42automatically does the compression and
  654. 25:44probably in your local you'll be able to
  655. 25:46run it let's say if you have 16 GB Ram
  656. 25:48you will just have to wait for some
  657. 25:50amount of time to get the response but
  658. 25:52Lama 2 and code Lama you can
  659. 25:54specifically use it over here all the
  660. 25:55open source llm model and it supports a
  661. 25:57lot of Open Source LM models and yes uh
  662. 26:00in Lang chain ecosystem the integration
  663. 26:02has also been provided over here so what
  664. 26:05I'm actually going to do over here is
  665. 26:06that I'll show you first of all just go
  666. 26:08ahead and download it this is available
  667. 26:10both in Mac Mac Linux and windows
  668. 26:12wherever you want just download it after
  669. 26:14you downloaded it what you really need
  670. 26:16to do is just go ahead and install it it
  671. 26:18is a simple exe file for Windows MSI
  672. 26:20file for Mac OS and then Linux is a
  673. 26:22different version so you just need to
  674. 26:24double click it and start installing it
  675. 26:26once you install it here uh somewhere in
  676. 26:28the bottom this AMA will be start
  677. 26:30running okay now once AMA installation
  678. 26:33is done now what I will do over here I
  679. 26:36will create another file inside my
  680. 26:39chatbot okay and create another file
  681. 26:44local
  682. 26:46llama okay local Lama py now local Lama
  683. 26:51py what we are going to basically do
  684. 26:53over here is that uh with respect to the
  685. 26:55local llama I will first first of all go
  686. 26:59ahead and import some of the library see
  687. 27:01code will be almost same right there
  688. 27:03also I'll be using chat open API chat
  689. 27:05prom template string output parser so
  690. 27:07I'll copy the same thing over here I'll
  691. 27:08paste it over here now along with this
  692. 27:10what I'm going to do I have to import
  693. 27:12olama right because that is the reason
  694. 27:14why we will be able to download all the
  695. 27:16specific models okay so Lang chain
  696. 27:18community. llm see over here whenever we
  697. 27:22need to do the third party integration
  698. 27:23so that will be available inside langin
  699. 27:25Community okay so AMA is third party
  700. 27:28cont configurations uh let's say you're
  701. 27:31using some Vector embeddings that is
  702. 27:32also third party so everything will be
  703. 27:34available over here okay now this is
  704. 27:36done langore community. LM import AMA
  705. 27:39and then we have this output parser
  706. 27:40string output parser core. prompts that
  707. 27:43is nothing but chart prom template and
  708. 27:45everything is there okay now let's go
  709. 27:47ahead and write import streamlet as St
  710. 27:51so I'm going to going to use the
  711. 27:53streamlet over here along with this
  712. 27:56import OS
  713. 27:58and not only that we will also go ahead
  714. 28:01and import from
  715. 28:04EnV
  716. 28:06import load
  717. 28:08uncore
  718. 28:09dot loore
  719. 28:13dob
  720. 28:14okay now we'll initialize it load
  721. 28:18underscore
  722. 28:20Dov okay once we initialize all this
  723. 28:22random all this uh environment variables
  724. 28:26as usual I will be importing this three
  725. 28:28things now see in my previous code when
  726. 28:31I was using open aipi promt template we
  727. 28:33have written it over here right same
  728. 28:34promt template we'll also write it over
  729. 28:36here because it we just need to repeat
  730. 28:38it because the main thing is that you
  731. 28:40really need to understand how with the
  732. 28:42help of AMA I can call any open source
  733. 28:43models okay so here it is and then
  734. 28:46finally you'll be able to see where is
  735. 28:49my uh code to call my open AI llms that
  736. 28:52we going to see over here so this is
  737. 28:55done now stream late framework also I
  738. 28:56will try to call it over here here okay
  739. 28:59it's more about copy paste the same
  740. 29:01thing that we have actually implemented
  741. 29:03and then you will also be seeing this is
  742. 29:06the code that we going to implement it
  743. 29:08okay but here we are calling chat open
  744. 29:11AI okay I specifically don't want chat
  745. 29:13open AI instead I will be calling AMA
  746. 29:16okay so AMA whatever Library we have
  747. 29:19imported so AMA okay and then here we
  748. 29:23are specifically going to call a Lama 2
  749. 29:26okay now before call any models now
  750. 29:29which all model are specifically
  751. 29:30supported if you go ahead and see in the
  752. 29:32GitHub right of AMA you'll be seeing the
  753. 29:34list of everything every every every
  754. 29:37libraries that it supports like Lama 2
  755. 29:38mral dolphin F 52 neural chat code Lama
  756. 29:42all are mostly open source GMA GMA is
  757. 29:44also there but before calling this what
  758. 29:46you really need to do is that just go to
  759. 29:48your command prompt let's say that I
  760. 29:49want to use GMA GMA model okay so what I
  761. 29:52have to do or I have to use llama model
  762. 29:54right so in order to do this I have to
  763. 29:57just write AMA run whatever model name
  764. 29:59because initially it needs to download
  765. 30:01it right uh this will get downloaded
  766. 30:03from some open source some GitHub it can
  767. 30:06be GitHub it can be hugging face
  768. 30:07somewhere right some location there will
  769. 30:09be there we have to download that entire
  770. 30:11model so let's say that I want to go
  771. 30:12ahead and write o run gamma so this what
  772. 30:15will happen it will pull the entire
  773. 30:17gamma model right wherever it is so here
  774. 30:19you can see pulling will basically
  775. 30:21happen now this is right now 5.2 GB
  776. 30:23right for the first instance you really
  777. 30:25need to do it now since I I I am writing
  778. 30:28the code with respect to Lama 2 I've
  779. 30:29already downloaded that model so that is
  780. 30:31the reason I'm showing you another
  781. 30:32example over here run gamma now once
  782. 30:35this entire downloading happens then
  783. 30:37only I'll be able to use the gamma model
  784. 30:39in my local with the help of AMA so I
  785. 30:42hope you have got an idea about
  786. 30:44it now what I'm actually going to do so
  787. 30:47here I've called AMA model Lama 2 okay
  788. 30:49then again output parser is this and I'm
  789. 30:51combining prompt llm on output parser
  790. 30:54and everything will be almost same and
  791. 30:55that is the most amazing thing about
  792. 30:57Lang
  793. 30:58the code will be only generic now only
  794. 31:00you need to replace open AI or paid or
  795. 31:02open source it is up to you again I'm
  796. 31:04saying you guys the system that I'm
  797. 31:06currently working in has a 64GB Ram uh
  798. 31:09it has Nvidia Titan RTX which was gifted
  799. 31:12by Nvidia itself so with respect to this
  800. 31:15uh amazing system I will be able to run
  801. 31:17very very much quickly that is what I
  802. 31:19feel so let's go ahead and run it so
  803. 31:22here what I'm actually going to do I'm
  804. 31:23going to write
  805. 31:25python uh so it is stream streamlet so
  806. 31:28streamlet
  807. 31:30run local Lama py so once I execute it
  808. 31:36here you'll be able to see now now
  809. 31:39instead of open a API I should had okay
  810. 31:41no module name Lang chain Community
  811. 31:43let's see where is Lang chain Community
  812. 31:45okay I have to also make sure that in my
  813. 31:48requirement. txt I go ahead and use this
  814. 31:53langin community and I need to import
  815. 31:56this Library since and need to do that
  816. 31:58and that is the reason I'm getting an
  817. 32:00error so if I go ahead and write pip
  818. 32:02install minus r requirement.
  819. 32:06txt
  820. 32:08oops
  821. 32:09CD dot dot okay now if I go ahead and
  822. 32:12write pip install minus r requirement.
  823. 32:16txt so here you'll be able to see my
  824. 32:19requirement. will get installed this Lin
  825. 32:21Community will get installed once I'm
  826. 32:23done with this then I can probably go
  827. 32:25ahead and run my code okay so this will
  828. 32:27take some amount of time so if you
  829. 32:29liking this video please make sure that
  830. 32:30you hit like uh there are many things
  831. 32:32that are probably going to come up and
  832. 32:34it'll be quite amazing when you learn
  833. 32:35all this things okay so uh once this is
  834. 32:38done then what will happen is that we
  835. 32:40can and you can use any model up to you
  836. 32:42okay and I don't want this open key also
  837. 32:46only this two information I specifically
  838. 32:48want I'll be able to track all these
  839. 32:50things okay and later on I'll also show
  840. 32:53you how you can create this in the form
  841. 32:54of apis again it'll some time it'll take
  842. 32:57this
  843. 32:58but uh let me know uh how do you think
  844. 33:00all these tutorials are blank chain I
  845. 33:03see a lot of purpose for this particular
  846. 33:06Library it's is quite amazing that
  847. 33:07people are doing um the company is doing
  848. 33:10amazingly well in this open source in
  849. 33:11world and it is developing multiple
  850. 33:13things over there so now I will go ahead
  851. 33:15and write CD chatbot I will go inside my
  852. 33:18chatbot and then I will run this python
  853. 33:21local Lama py once I execute this now I
  854. 33:25don't think it should be an error
  855. 33:28okay it should be streamlit come on
  856. 33:31streamlit run local llama oops local
  857. 33:35Lama py not python run streamate run now
  858. 33:39here you have again I'll be getting open
  859. 33:42AI text over here let me change this
  860. 33:44also so that I can make it
  861. 33:47perfect with Lama
  862. 33:512 okay so I've executed it saved it I
  863. 33:54will rerun it I'll say hey high so once
  864. 33:58I execute it you'll be seeing that it'll
  865. 34:00take some amount of time in my system
  866. 34:02even though I have a 64 GB Ram but I'll
  867. 34:04get the output over here so assistant
  868. 34:06says hello how can I help you today now
  869. 34:08if I probably go ahead with respect to
  870. 34:10this dashboard uh let's see where it is
  871. 34:14so now tutorial one you'll be able to
  872. 34:16see that this will increase okay there
  873. 34:18will be one more over here right so I've
  874. 34:21reloaded this
  875. 34:23page okay and you'll be able to see it
  876. 34:26okay you'll be able to see the new olama
  877. 34:28request see hey hi 4.89 second token 39
  878. 34:32but there is no charges because it is an
  879. 34:35open source model right so here you'll
  880. 34:37be able to see if I extend this there
  881. 34:40you'll be able to see chat PR template
  882. 34:41ama ama is over here now this AMA is
  883. 34:44specifically calling llama 2 over there
  884. 34:46and whatever open source libraries that
  885. 34:48you specifically want just to call this
  886. 34:50it is very much simple you have to just
  887. 34:52go into the GitHub and download any
  888. 34:54model first of all just by writing o
  889. 34:56Lama run that particular model name and
  890. 34:59once it is downloaded it is good that
  891. 35:00you can probably go ahead with and use
  892. 35:02it okay now I will say uh provide me a
  893. 35:06python
  894. 35:08code python code to swap two numbers
  895. 35:13okay if you want more coding well
  896. 35:16chatbot you can directly use code Lama
  897. 35:18if you want okay so here you can see all
  898. 35:20the examples are there and this was
  899. 35:22quite fast right so this is good you
  900. 35:24know so if you have the right kind of
  901. 35:26things so here you can see 4 seconds it
  902. 35:29has probably taken okay AMA is over here
  903. 35:32all the information is probably over
  904. 35:34here prompt and completion and all right
  905. 35:37hello guys so we are going to continue
  906. 35:39the langin series already in our
  907. 35:41previous video we have already seen how
  908. 35:43to create chat Bots with the help of
  909. 35:45both openai API and open source llm
  910. 35:47models like Lama 2 we have also seen
  911. 35:50what is the use of AMA how you can run
  912. 35:52all these open source model locally in
  913. 35:55your system and uh along with this this
  914. 35:57we also created multiple end to-end
  915. 35:59projects using both of them now what we
  916. 36:02are going to do in this specific video
  917. 36:04one more step which is very much
  918. 36:05important for our production G
  919. 36:07deployment that is creating apis you
  920. 36:10know for all this kind of llm uh models
  921. 36:13we will be able to create apis and uh
  922. 36:16through this you will also be able to do
  923. 36:18the deployment in a very efficient
  924. 36:19manner now how we are going to create
  925. 36:22this specific apis there is a very
  926. 36:23important component uh which is called
  927. 36:26as Lang serve in Lang chain we're going
  928. 36:28to use that along with this we are going
  929. 36:30to use fast API um and not only that
  930. 36:33we'll also create a sag Swagger UI which
  931. 36:36is already provided by Lang chin uh the
  932. 36:39Lang serve library that we are
  933. 36:40specifically going to use now it is
  934. 36:42important guys you know this specific
  935. 36:44step because tomorrow if you are also
  936. 36:47developing any application you obviously
  937. 36:49want to do the deployment for that
  938. 36:51particular application so creating uh
  939. 36:54the entire API for this application will
  940. 36:56be the first task that will be required
  941. 36:58so uh yes let's continue let's go ahead
  942. 37:01and uh discuss this entire thing first
  943. 37:03of all how we are going to go ahead
  944. 37:05first of all I'm going to show you the
  945. 37:07theoretical intuition how we going to
  946. 37:08develop it and then we will start the
  947. 37:10coding part so let me quickly go ahead
  948. 37:13and share my screen what we are actually
  949. 37:15going to do over here over here I se you
  950. 37:17have seen that I've written apis for
  951. 37:19deployment okay so if I consider this
  952. 37:22diagram this is the most simplistic
  953. 37:24diagram that I could draw okay now let's
  954. 37:27consider see um the at the end of the
  955. 37:30day in companies right uh there will be
  956. 37:32different different uh applications this
  957. 37:34applications are obviously created by
  958. 37:36software Engineers right it can be a
  959. 37:38mobile app it can be a desktop app web
  960. 37:40app and all now for this particular app
  961. 37:43if I want to integrate uh any foundation
  962. 37:46model or any fine-tuned foundation model
  963. 37:49like llms and all um so what I really
  964. 37:52need to do is that I need to integrate
  965. 37:53this with the form of apis at the end of
  966. 37:56the day see what we are going to do over
  967. 37:57here this side is my llm models itself
  968. 38:00right it can be a fine-tuned llm models
  969. 38:02it can be a foundation model I want to
  970. 38:04use those functionality along with my
  971. 38:06web app or mobile app so what we are
  972. 38:08doing is over here is that we will
  973. 38:10create this specific apis now this apis
  974. 38:13will be having routes okay routes and
  975. 38:17this routes will be responsible whether
  976. 38:19we have to probably interact with open
  977. 38:21AI or whether we have to interact with
  978. 38:23other llm model like Cloud 3 cloudy 3 or
  979. 38:26llama 2 open source model model so any
  980. 38:28number of llm models whether it is open
  981. 38:30source or uh whether it is uh paid API
  982. 38:34models specifically for llm we can
  983. 38:36definitely use it now this is what we
  984. 38:38are going to do in this video we will
  985. 38:41create this separately we will create
  986. 38:43this separately and at the end of the
  987. 38:45day I'll also give you an option through
  988. 38:47routes how you can integrate with
  989. 38:49multiple llm models right so I hope you
  990. 38:52have got an idea with respect to this
  991. 38:54and any number of llm models it may
  992. 38:55probably come you can probably integrate
  993. 38:57it at the end of the day whichever model
  994. 38:59is suitable for you you can use for
  995. 39:01different different functionality and
  996. 39:03the reason why I'm making this video
  997. 39:05understand one thing guys because in
  998. 39:06llms also you have different performance
  999. 39:09metrics some model is very good at some
  1000. 39:12performance metrics over there like MML
  1001. 39:14other other metrics are definitely there
  1002. 39:16so this is an option where we can use
  1003. 39:17multiple llm models now what we are
  1004. 39:20going to do quickly I will go ahead and
  1005. 39:22open my code document so in in my
  1006. 39:25previous video already you have seen I
  1007. 39:27had actually developed till here right I
  1008. 39:29have basically if you see over here we
  1009. 39:32have created this first folder that is
  1010. 39:34chatbot and inside the chatbot we had
  1011. 39:36created app.py then local Lama py right
  1012. 39:40we with this did this entire thing and
  1013. 39:42as I said every tutorial I'll keep on
  1014. 39:45creating folders and developing our own
  1015. 39:47project over here now let's go ahead and
  1016. 39:49create my second folder and this time
  1017. 39:51this will be apis okay so I'll just go
  1018. 39:54ahead and write something like API okay
  1019. 39:57now with respect to this API as I said
  1020. 40:00whatever we do with this local Lama or
  1021. 40:03app.py right over here I've used open a
  1022. 40:05API key here I used open source models
  1023. 40:08so we'll try to integrate both of them
  1024. 40:10in the form of routes okay so that we'll
  1025. 40:12be able to create an API so let me
  1026. 40:14quickly go ahead and write over here
  1027. 40:16app. Pui so one will be my app. Pui
  1028. 40:19which will be responsible in creating
  1029. 40:20all the apis the second one will
  1030. 40:22specifically be my client.py now
  1031. 40:25client.py in this specific diagram is
  1032. 40:28just imagine like this one web app or
  1033. 40:30mobile app because we are going to
  1034. 40:31integrate this apis with this mobile app
  1035. 40:33or web app okay so quickly let's do this
  1036. 40:36uh first of all I will go ahead and
  1037. 40:38start writing the code in
  1038. 40:40app.py before I go ahead uh we have to
  1039. 40:43make sure that we need to update all the
  1040. 40:45requirement. txt almost all the
  1041. 40:47libraries have installed it but I'm
  1042. 40:49going to install more three libraries
  1043. 40:51one is langu fast API and uvon okay
  1044. 40:54since I'm going to create my entire
  1045. 40:55Swagger documentation of API using fast
  1046. 40:58API right so all these three libraries
  1047. 41:00I'll be using it so first of all I will
  1048. 41:02go ahead and install all these
  1049. 41:05libraries that we'll do once we run the
  1050. 41:07code right now let's go ahead and write
  1051. 41:08my app.py code okay now as usual first
  1052. 41:13of all uh let me just open my terminal
  1053. 41:17okay and let me do one thing with
  1054. 41:20respect to the terminal I will go ahead
  1055. 41:22and write pip
  1056. 41:25install pip install
  1057. 41:27minus our requirement.
  1058. 41:31txt okay first of all I need to just
  1059. 41:34write CD dot dot okay then I'll clear
  1060. 41:38the screen and then go ahead and write
  1061. 41:40paper install minus r requirement. txd
  1062. 41:44now here you'll be able to see that my
  1063. 41:45entire installation will start taking
  1064. 41:47place and here uh the other three
  1065. 41:50packages that I have actually written
  1066. 41:51right Lang serve and all that will get
  1067. 41:53particular installed okay now till then
  1068. 41:56installation is B basically going on let
  1069. 41:58me go ahead and write my code so I will
  1070. 41:59write from Fast
  1071. 42:02API
  1072. 42:05import fast API okay so this is the
  1073. 42:09first
  1074. 42:11uh first library that I'm going to
  1075. 42:13import along with this I have to also
  1076. 42:15make sure that I create or I import my
  1077. 42:18uh chat prom template so from Lang chain
  1078. 42:23since we are going to create that entire
  1079. 42:24apis in this okay prompt
  1080. 42:28import chat prom template
  1081. 42:35right so this is done then
  1082. 42:39from line chain
  1083. 42:43dot chatore models
  1084. 42:47import chat open aai so this is the next
  1085. 42:50one since I need to make sure that I
  1086. 42:53need to create a chat chat application
  1087. 42:55so that is the reason why I'm using this
  1088. 42:56chat models okay uh this is the next
  1089. 42:59library that I'll be going ahead and
  1090. 43:01importing along with this I'll also use
  1091. 43:03langu which will be responsible in
  1092. 43:05creating my entire apis right so from
  1093. 43:08Lang serve import add routes okay so
  1094. 43:11through this I will be able to add all
  1095. 43:14the routes over there right whatever
  1096. 43:16routes suppose one route will be that I
  1097. 43:18need to interact with my opening API one
  1098. 43:21one route will be to interact with the
  1099. 43:23Lama 2 and all So based on that I will
  1100. 43:25go ahead and import this next thing is
  1101. 43:29import
  1102. 43:31uon okay uon will be required over
  1103. 43:35here
  1104. 43:39oops okay next is import OS see I can
  1105. 43:44probably enable my GitHub co-pilot and I
  1106. 43:47can probably write the code but I don't
  1107. 43:49think so that will be a better way uh I
  1108. 43:51usually use this AI tool which is called
  1109. 43:53as blackbox uh so that it will help me
  1110. 43:55to write my code faster
  1111. 43:57and uh you know it also explains about
  1112. 43:59the code so I'll probably create another
  1113. 44:01video about it okay so how to basically
  1114. 44:03use this then one more thing that I
  1115. 44:05really want to import over here is my
  1116. 44:07olama so from langin community.
  1117. 44:11llms LMS
  1118. 44:14import o Lama okay so this is done all
  1119. 44:19the libraries that is specifically
  1120. 44:21required by my code uh I have actually
  1121. 44:23written that okay and these are all the
  1122. 44:26things that I will require to create my
  1123. 44:27open a API now this is done now what I'm
  1124. 44:30actually going to do over here is that
  1125. 44:31I'm just going to write os. environment
  1126. 44:34and first of all I will initialize my
  1127. 44:36open AI API key so I will write open
  1128. 44:38aore API _ key okay and this
  1129. 44:43specifically I will load it from os.
  1130. 44:48getenv and then I will go ahead and
  1131. 44:51write open aior API
  1132. 44:55uncore key okay so this is the first
  1133. 44:58thing that we really need to do before I
  1134. 45:00do this I will just go back to my o
  1135. 45:03app.py and I will just initialize
  1136. 45:07this okay load. EnV let me quickly copy
  1137. 45:11this entire thing and paste it over
  1138. 45:15here and I will initialize
  1139. 45:18this load
  1140. 45:22[Music]
  1141. 45:23uncore
  1142. 45:25Okay so this will actually help me to
  1143. 45:28initialize all my environment variable
  1144. 45:31perfect uh I've also loaded my open API
  1145. 45:34key now let's start this fast API now in
  1146. 45:36order to create the fast API uh I have
  1147. 45:39to create an app here I've given title
  1148. 45:41langin server version 1.0 and the third
  1149. 45:45information I basically want is the
  1150. 45:47description now after this I can use
  1151. 45:49this app and I can keep on adding my
  1152. 45:52routes okay so what I will do uh addore
  1153. 45:56routes and this routes is basically to
  1154. 45:59add all the routes over there right for
  1155. 46:01so the first time when we are adding
  1156. 46:03this particular routes you have to make
  1157. 46:04sure that I give all the information
  1158. 46:06like whether I'm going up with my app
  1159. 46:09let's say I go with this chat open a API
  1160. 46:14chat open
  1161. 46:15AI open AI okay and the third
  1162. 46:19information that I will probably give is
  1163. 46:21my path so this is my one of my one of
  1164. 46:25my uh route you can just consider this
  1165. 46:28open AI route and this is my model that
  1166. 46:30I will specifically be using so this is
  1167. 46:32just one way how you can actually add
  1168. 46:34route okay but let me just add some more
  1169. 46:37things because see at the end of the day
  1170. 46:39when we created our first application we
  1171. 46:41used to combine prompt llm and output
  1172. 46:44parser in this specific way so what
  1173. 46:46we'll do over here is that when we are
  1174. 46:47creating routes we also need to make
  1175. 46:49sure that we add all the routes in such
  1176. 46:51a way that I also integrate my prompt
  1177. 46:54template with it okay so here I'm going
  1178. 46:56to say model is equal to chat open
  1179. 47:01AI chat open Ai and I'm going to
  1180. 47:03initialize this particular
  1181. 47:05model and then let me go ahead and
  1182. 47:07create my other model also see o Lama I
  1183. 47:09will just use my llama 2 Okay so this
  1184. 47:12model also I need to basically create it
  1185. 47:14or call it okay because I I want to use
  1186. 47:15multiple models so here I'm going to
  1187. 47:17write
  1188. 47:19llm and here
  1189. 47:21AMA and this will basically be my model
  1190. 47:24is equal to
  1191. 47:28llama 2 okay so I'm going to use the
  1192. 47:31Llama 2 model so this is my one model
  1193. 47:33over here this is my another model over
  1194. 47:35here okay now let me go quickly go ahead
  1195. 47:38and create my prompt one so my prompt
  1196. 47:40one will be my chat prompt template
  1197. 47:43chart promp
  1198. 47:45template dot frore
  1199. 47:49template okay and here I'm going to
  1200. 47:51basically give one chat prompt okay
  1201. 47:54let's say one of my interaction one I
  1202. 47:57want to use open a API uh for open a API
  1203. 48:01let's say I want to create an essay so
  1204. 48:03I'll say write me an
  1205. 48:05essay write me an
  1206. 48:08essay about a specific topic that topic
  1207. 48:11I will be giving it okay about some
  1208. 48:14topic okay some topic
  1209. 48:17okay
  1210. 48:19around with 200 words or with 100 words
  1211. 48:23okay so this is my first prom template
  1212. 48:26okay I'm saying this will be my prom
  1213. 48:28template write me an essay about
  1214. 48:30whatever topic I give with 100 words
  1215. 48:32okay something like this so this let's
  1216. 48:34go ahead and write this this is my first
  1217. 48:36promt template then I will create my
  1218. 48:39second prompt template okay this is
  1219. 48:41important just just hear me out okay and
  1220. 48:43this promt template will be responsible
  1221. 48:46in interacting with my open source model
  1222. 48:48so let me say write me a poem I'll say
  1223. 48:50write me a poem about this specific
  1224. 48:52topic with 100 words so in short this
  1225. 48:55first prom template will will be
  1226. 48:57interacting with this model that is
  1227. 48:58chart open API prompt 2 will be
  1228. 49:00interacting with llm model okay whatever
  1229. 49:03llm model I written over here that is
  1230. 49:04Lama 2 now let me go ahead and add this
  1231. 49:07routes so here I'll say add routes okay
  1232. 49:11and again as usual I will write app now
  1233. 49:14here you see I will be combining prompt
  1234. 49:17or model right model will be chat open
  1235. 49:20API and you know this prompt one is
  1236. 49:22specifically for my chat open API right
  1237. 49:26then I will also give the route path so
  1238. 49:28my path will be something like this okay
  1239. 49:32and this will be my API right so here
  1240. 49:34say let's say I'll write slay that
  1241. 49:37basically means this path is responsible
  1242. 49:39in interacting with the open API and
  1243. 49:42this is denoted by slash essay so that
  1244. 49:45API URL that you'll be getting will be
  1245. 49:48ending with slay okay the other route
  1246. 49:51and I can keep on adding any number of
  1247. 49:52routes as you want so another route will
  1248. 49:54be like with promp two okay and here I'm
  1249. 49:58going to basically use my llm and let me
  1250. 50:00just go ahead and write this as/ poem
  1251. 50:03okay/ poem so this is my another route
  1252. 50:06this is my another route okay and
  1253. 50:08finally I've created two apis in short
  1254. 50:11and now here I will write if underscore
  1255. 50:12uncore name underscore uncore is double
  1256. 50:15equal to underscore uncore maincore
  1257. 50:18uncore
  1258. 50:19right now what we are going to do over
  1259. 50:22here this is the starting of the
  1260. 50:24application I will say uvon
  1261. 50:27run and here I'm going to use my app
  1262. 50:31comma host will specifically be my Local
  1263. 50:33Host see here I'm giving you the Local
  1264. 50:36Host uh this application you can run it
  1265. 50:39in any server that you want right so
  1266. 50:41that is the saying that is the reason
  1267. 50:42why I'm saying this is the first step
  1268. 50:44towards building that production grade
  1269. 50:46application okay and the port number
  1270. 50:48will be 8,000 perfect so this is done I
  1271. 50:51think uh it looks really really amazing
  1272. 50:53we have written the complete code over
  1273. 50:54here and this is is my entire app.py
  1274. 50:58with all the API so that basically means
  1275. 51:00if I see the diagram over here this API
  1276. 51:03part I actually created routes along
  1277. 51:05with prompt template I've created and
  1278. 51:07I've used two apis one is open aai and
  1279. 51:10one is Lama tool two routes I've
  1280. 51:11specifically used now my time is to
  1281. 51:14basically create this web app and mobile
  1282. 51:15app okay and I here I will just try to
  1283. 51:17create a simple web app the reason why
  1284. 51:20I'm creating this simple web app because
  1285. 51:21it will be able to interact with this
  1286. 51:23okay now what I will do let's go ahead
  1287. 51:26and run this and see whether everything
  1288. 51:28is running fine or not okay so here what
  1289. 51:31I will do I will go to my CD which
  1290. 51:34folder this is this is basically my API
  1291. 51:36folder okay so CD
  1292. 51:39API oops
  1293. 51:41Port let me just write
  1294. 51:45it Port okay done CD I'll save this CD
  1295. 51:52API okay and then here I'm going to
  1296. 51:55write python app.py okay now once I
  1297. 51:58execute this from Lang chain uh Lang
  1298. 52:01chain. prompts just let me see the
  1299. 52:03documentation whether it is correct or
  1300. 52:05not it should be prompts okay so a small
  1301. 52:09issue over here it should be prompts now
  1302. 52:12let me just go ahead and execute it now
  1303. 52:14I think it should work
  1304. 52:17fine uh so here you can see import error
  1305. 52:23uh SSE Starlet Okay so so this is one of
  1306. 52:27the dependency that is probably coming
  1307. 52:29up uh I will quickly go ahead and update
  1308. 52:31my requirement. txt okay and let me do
  1309. 52:36one thing just let me write pip install
  1310. 52:39this particular application
  1311. 52:41okay so I will go and write pip
  1312. 52:45install control V oops pip
  1313. 52:50install and SSC Starlet okay so once
  1314. 52:53this installation will probably happen I
  1315. 52:55think now we'll not get an error now if
  1316. 52:57I write python app.py it should run I
  1317. 53:01guess so it is now running okay uh so
  1318. 53:04let's go ahead and open this Local Host
  1319. 53:07uh now here you can see I'm getting
  1320. 53:09details not found but if you really want
  1321. 53:11to see that entire API that is basically
  1322. 53:13created you can just write slash docs
  1323. 53:17now here you can see your entire langin
  1324. 53:19server see I've created open aai input
  1325. 53:22schema everything is given essay essay
  1326. 53:24is also there poem is also there and all
  1327. 53:26right so all the apis is almost created
  1328. 53:29see here you can see what is the input
  1329. 53:31what is the output output schema what is
  1330. 53:33is basically required everything is
  1331. 53:35probably given over here and this is
  1332. 53:36basically called as a Swagger UI
  1333. 53:38documentation okay the entire Swagger UI
  1334. 53:40documentation is done now
  1335. 53:43perfect your apis part is basically
  1336. 53:46created now how do we interact with this
  1337. 53:48apis that is the most important part so
  1338. 53:50for that what we are going to basically
  1339. 53:52do I'm going to uh let let let let let
  1340. 53:57let this terminal be hidden over here
  1341. 53:59I'm going to create my client.py okay
  1342. 54:02now with respect to the client.py what
  1343. 54:04we are going to do and let me do one
  1344. 54:06thing till then I will go ahead and
  1345. 54:09disable this extension okay because I
  1346. 54:12don't want this extension to disturb
  1347. 54:16things okay
  1348. 54:18disable
  1349. 54:23perfect I will show you this extension
  1350. 54:25it is a very powerful extension okay now
  1351. 54:28this client. py is my app it can be my
  1352. 54:31app okay so first of all what I'll do I
  1353. 54:33will go ahead and import
  1354. 54:35request
  1355. 54:37okay after importing request I'm going
  1356. 54:39to write import streamlet
  1357. 54:43as stream late as St okay so two
  1358. 54:47libraries I'm going to import request
  1359. 54:50and streamlet understand I'm creating a
  1360. 54:52web app I can create a front end that
  1361. 54:54will interact with the API okay so here
  1362. 54:57first of all I will write two definition
  1363. 54:59or two important function one
  1364. 55:01is
  1365. 55:03uh
  1366. 55:06getor open aore response and here I'm
  1367. 55:11going to basically go ahead and write my
  1368. 55:13input underscore
  1369. 55:15text okay here I will call I will
  1370. 55:20probably call use this request object
  1371. 55:22and create my response now in order to
  1372. 55:25create the response in order to call the
  1373. 55:26API how do I do it so here I'm going to
  1374. 55:29write request dot
  1375. 55:31post and how to basically call it so
  1376. 55:34first of all I need to give the URL
  1377. 55:37understand we are already running this
  1378. 55:39URL right this entire Local Host if you
  1379. 55:41probably see over here everything is
  1380. 55:42running over here right if you if you
  1381. 55:45see this okay if you probably see this
  1382. 55:48and try to try to see this entire URL
  1383. 55:52okay you can directly see that in order
  1384. 55:55to call this API
  1385. 55:56I will be using a URL that is already
  1386. 55:59provided by this particular Swagger UI
  1387. 56:01that is nothing but let's say I want to
  1388. 56:03call the essay URL okay now in order to
  1389. 56:07call the essay URL which is using the
  1390. 56:09open a API here you can see HTTP Local
  1391. 56:12Host 8000 / invoke so this is my entire
  1392. 56:15API URL which will be responsible in
  1393. 56:17calling this and here we also know that
  1394. 56:20we need to give one input so what I will
  1395. 56:22do I will go ahead and write over here
  1396. 56:24as Json is equal to and in the form of
  1397. 56:27Json I will give one of my input so
  1398. 56:30input colon okay and here I will write
  1399. 56:35topic why topic because see here what we
  1400. 56:37are given over here if you see over here
  1401. 56:39topic is there right now this topic will
  1402. 56:42be nothing but whatever input text I am
  1403. 56:45giving to this particular function that
  1404. 56:47same input text will be visible over
  1405. 56:49here okay so this is what we have
  1406. 56:52actually done over here right so input
  1407. 56:55topic colon input so text so this is
  1408. 56:57what is the input I will give and it
  1409. 57:00will hit this particular URL along with
  1410. 57:02this particular input post okay and then
  1411. 57:05finally I get my response now what I
  1412. 57:07will do I will go ahead and take this
  1413. 57:10response convert into a Jon and it has a
  1414. 57:13key dictionary value pairs which where
  1415. 57:16my output content will be present inside
  1416. 57:18this variable called as output and one
  1417. 57:21more thing that I require is basically
  1418. 57:23content okay so inside this key my
  1419. 57:25entire response will be available the
  1420. 57:28next thing that I'm actually going to do
  1421. 57:29is similar with the help of AMA response
  1422. 57:32and here we are going to use Lama 2 so
  1423. 57:35get AMA response input text again
  1424. 57:37request. poost now instead of using
  1425. 57:39this/ / invoke we are going to use SL
  1426. 57:43po/ invoke why/ po/ invoke because SL
  1427. 57:46poem will be responsible in interacting
  1428. 57:48with Lama 2 okay and then I get my Json
  1429. 57:51again I uh I get my response here I'm
  1430. 57:53writing response. Json of output okay
  1431. 57:56okay so these are my two functions that
  1432. 57:58I've actually created to get the
  1433. 58:00response now what let me do one thing
  1434. 58:02now let me go ahead and create my
  1435. 58:03streamlet framework very simple now now
  1436. 58:06from here everything will be simple okay
  1437. 58:08so st. title this this is there I've
  1438. 58:11created two textbox one is input text
  1439. 58:14and one is input text one first text box
  1440. 58:17I'm saying write an essay on whatever
  1441. 58:18topic the second text box I'm writing
  1442. 58:20write a poem of any other topic okay so
  1443. 58:23first one we'll be interacting with the
  1444. 58:25openi application this the second one
  1445. 58:26will be interacting with Lama 2 okay and
  1446. 58:29finally I'm going to call this
  1447. 58:32particular two function that I have
  1448. 58:34created if input. text if I write any
  1449. 58:37text in the first time then it should
  1450. 58:38basically interact with the openi
  1451. 58:41response whatever response I'm getting
  1452. 58:42it will display it over here if input
  1453. 58:44text one I'll just call the AMA response
  1454. 58:48which is interacting with the Llama 2 on
  1455. 58:50this particular URL okay and then I will
  1456. 58:52get the over here the output so this is
  1457. 58:55my entire application which is
  1458. 58:57interacting with the API which is
  1459. 58:59already running over here right now with
  1460. 59:01respect to this client.py what I'm
  1461. 59:03actually going to do I'm going to create
  1462. 59:05another command prompt and let me run
  1463. 59:06this okay so here I will say uh cond
  1464. 59:13deactivate and I will say
  1465. 59:16cond activate
  1466. 59:18VNV okay and let me just go ahead and
  1467. 59:21run this now see python client.py okay
  1468. 59:27okay sorry it should be
  1469. 59:28streamlit
  1470. 59:30streamlit
  1471. 59:32run client.py okay so this is my client
  1472. 59:36side okay file does not exist okay oh I
  1473. 59:39will say CD and I will go to my folder
  1474. 59:42that is API now let me go ahead and
  1475. 59:44write streamlet run client.py now see
  1476. 59:46this this is my Swagger UI the API is
  1477. 59:50running over here and this is my front
  1478. 59:52end application which is basically in
  1479. 59:54now it will interact with with this apis
  1480. 59:57okay now if I write the first one the
  1481. 59:59first the first anything in the first
  1482. 1:00:01text box this is going to interact with
  1483. 1:00:03the open API so I'll say write an essay
  1484. 1:00:05on machine
  1485. 1:00:07learning okay so here you can see name
  1486. 1:00:11get open AI response is not defined why
  1487. 1:00:14this is the error let's
  1488. 1:00:16see open AI
  1489. 1:00:19response oops just a second this
  1490. 1:00:22function name is does not match
  1491. 1:00:26and this also o Lama response does not
  1492. 1:00:29match or what okay now I think it should
  1493. 1:00:31work let's reload it
  1494. 1:00:35okay now you can see automatically
  1495. 1:00:37machine learning is a powerful
  1496. 1:00:38technology that enables computer this
  1497. 1:00:40this this so the first text box is
  1498. 1:00:42interacting with the open aipi write a
  1499. 1:00:45po poem on machine learning let's say if
  1500. 1:00:47I give the same thing if I execute it
  1501. 1:00:50now this is going to interact with the
  1502. 1:00:51Llama 2 so machine learning is a field
  1503. 1:00:52of arti that allows computers to make
  1504. 1:00:54decision or still running sorry
  1505. 1:00:56uh this was the first response that I
  1506. 1:00:58got from them
  1507. 1:01:00uh okay it's running I guess let me
  1508. 1:01:03reload
  1509. 1:01:04it write a poem on machine learning okay
  1510. 1:01:09and I can also write my own custom
  1511. 1:01:11prompt if I want everybody I was
  1512. 1:01:13thinking that we could make a bit of
  1513. 1:01:15interesting by adding some extra
  1514. 1:01:16challenges so and so so what do you say
  1515. 1:01:19something something is given okay uh and
  1516. 1:01:21if I probably see over here with respect
  1517. 1:01:23to the prompt input text one this is
  1518. 1:01:25also going over here uh this is my input
  1519. 1:01:28text okay perfect so everything works
  1520. 1:01:30fine and here you'll be able to see
  1521. 1:01:31write a poem about uh this particular
  1522. 1:01:34topic with
  1523. 1:01:37um for a five years child okay so now
  1524. 1:01:41let's see I'll just try to change the
  1525. 1:01:44prompt and see whether it is working
  1526. 1:01:45fine or not so this has got reloaded it
  1527. 1:01:48uh let's see whether this is reloaded or
  1528. 1:01:50not now if I go ahead and reload this
  1529. 1:01:54write a poem on on
  1530. 1:01:57unicorn okay I'm just writing something
  1531. 1:02:01unicorn I think it should be able to
  1532. 1:02:02give the
  1533. 1:02:03poem shimmering coat in various colors
  1534. 1:02:06here are 100 words that describe a
  1535. 1:02:08unicorn okay something something
  1536. 1:02:10information is basically and this is
  1537. 1:02:12basically interacting with the entire
  1538. 1:02:13Lama 2 hello guys we are going to
  1539. 1:02:16continue the Lang chain series and in
  1540. 1:02:18this specific videos and in the series
  1541. 1:02:20of upcoming videos we are going to
  1542. 1:02:22discuss about rag pipeline now rag uh
  1543. 1:02:26the full form is retrieval augmented
  1544. 1:02:28generation one of the very important use
  1545. 1:02:30cases you may probably solving when you
  1546. 1:02:33specifically use llm models and most of
  1547. 1:02:36the use cases right now in companies are
  1548. 1:02:38demanding this kind of skill sets you
  1549. 1:02:40know where you can actually develop rag
  1550. 1:02:42let's say you have a set of documents
  1551. 1:02:44and you should be able to query that
  1552. 1:02:46specific documents and get the result
  1553. 1:02:48quickly if you have different kind of
  1554. 1:02:51files let it be a readme file a text
  1555. 1:02:53file a different data source file you
  1556. 1:02:55should be able to read it convert that
  1557. 1:02:56into a vectors and able to retrieve any
  1558. 1:02:58queries specifically from those kind of
  1559. 1:03:01data sources so uh as I said uh we will
  1560. 1:03:04be implementing this completely from
  1561. 1:03:06scratch from basic to Advanced in this
  1562. 1:03:09specific videos we'll understand the
  1563. 1:03:10entire architecture and then we will do
  1564. 1:03:12a lot of practical intuitions okay so uh
  1565. 1:03:16in any rag pipeline these are the major
  1566. 1:03:19components that will probably exist so
  1567. 1:03:21the first component is specifically
  1568. 1:03:23called as load data source now whenever
  1569. 1:03:26we say load data source initially we may
  1570. 1:03:29have see rag is all about quering from a
  1571. 1:03:31defin different different data source
  1572. 1:03:33all together right so we may be having
  1573. 1:03:36files that may be having PDF it can be a
  1574. 1:03:38MD file readme file it can be a Excel
  1575. 1:03:41file it can be a txt file it can be a
  1576. 1:03:44database file it can be different
  1577. 1:03:45different files all together right and
  1578. 1:03:47in the first so first step that we see
  1579. 1:03:50over here it is basically called as load
  1580. 1:03:52Source data this step is also called as
  1581. 1:03:55data injection okay data injection now
  1582. 1:03:59in Lang chain the most amazing thing is
  1583. 1:04:01that it definitely have a lot of
  1584. 1:04:04different kind of data injection tools
  1585. 1:04:06which will be able to load the data in
  1586. 1:04:08various manner so in our current video
  1587. 1:04:11we are going to implement each and every
  1588. 1:04:13of this component from data injection
  1589. 1:04:14till the query Vector store okay then
  1590. 1:04:18after ingesting the data you can
  1591. 1:04:20probably do load you can transform and
  1592. 1:04:23you can embid okay we will discuss about
  1593. 1:04:25this what exactly is load transform and
  1594. 1:04:27embid specifically when we do loading
  1595. 1:04:30that is nothing but we are reading from
  1596. 1:04:31a specific data source then we perform
  1597. 1:04:34some type of feature engineering over
  1598. 1:04:37here if we want like in transform stage
  1599. 1:04:40here the data the complete data will be
  1600. 1:04:43broken into smaller chunks okay now why
  1601. 1:04:47do we divide this data into smaller
  1602. 1:04:48chunks it is very much important to
  1603. 1:04:51understand because whatever llm models
  1604. 1:04:54we specifically use right is definitely
  1605. 1:04:57has some kind of context size right so
  1606. 1:05:00based on this context size it is always
  1607. 1:05:02a good good way to basically convert
  1608. 1:05:07this entire data which can be of many
  1609. 1:05:10number of PDFs it can be U many number
  1610. 1:05:13of pages in this specific PDF we will
  1611. 1:05:15try to divide this particular thing into
  1612. 1:05:17chunks of data so this is also what
  1613. 1:05:19we'll going to see in the practical way
  1614. 1:05:21then finally we go ahead with embeddings
  1615. 1:05:24embeddings basically means how we can
  1616. 1:05:26convert all these chunks into vectors
  1617. 1:05:30okay how we can actually use vectors in
  1618. 1:05:33order to probably convert this chunks
  1619. 1:05:35right and finally all these vectors will
  1620. 1:05:38be further stored in some kind of vector
  1621. 1:05:41stored database okay so it can be a
  1622. 1:05:44database over here and the main reason
  1623. 1:05:46of this specific database is that we
  1624. 1:05:48will be able to query this particular
  1625. 1:05:51database in an efficient manner right
  1626. 1:05:53with respect to any query that we have
  1627. 1:05:55have right so whatever vectors are
  1628. 1:05:57basically stored if I have a query if I
  1629. 1:06:00hit the query on this particular
  1630. 1:06:01database I should be able to get the
  1631. 1:06:03result based on the context of the query
  1632. 1:06:06so this is the entire rag pipeline that
  1633. 1:06:08we specifically use in the upcoming
  1634. 1:06:11series of videos we are going to use
  1635. 1:06:13different different Vector databases in
  1636. 1:06:15different different clouds also okay so
  1637. 1:06:17right now we will try to implement all
  1638. 1:06:19these things that you can actually see
  1639. 1:06:20in front of you and we will follow this
  1640. 1:06:23entire architecture so let me quickly
  1641. 1:06:25open my vs code and once I probably
  1642. 1:06:28start my VSS code I will be um I will
  1643. 1:06:31continue with respect to the same uh
  1644. 1:06:34thing that I have actually used right
  1645. 1:06:36all the projects that I've actually
  1646. 1:06:37created as I said that all the things
  1647. 1:06:39will be given in the description of this
  1648. 1:06:41particular video with respect to the
  1649. 1:06:42GitHub link okay now I've have created a
  1650. 1:06:45folder which is called as rag inside
  1651. 1:06:47this I will create one ipynb file okay
  1652. 1:06:50initially we'll go with ipnb file and
  1653. 1:06:52then later on we'll try to create an end
  1654. 1:06:54to end project okay so here I will say
  1655. 1:06:57uh simple rag.
  1656. 1:07:00iynb since we are doing it completely
  1657. 1:07:02from Basics it is always good that we
  1658. 1:07:05try to do it completely from basic
  1659. 1:07:06itself right so U this is the thing so
  1660. 1:07:10first of all I will go ahead and see
  1661. 1:07:12whether in my terminal whether I have
  1662. 1:07:14that I kernel installed or not okay so I
  1663. 1:07:18will go ahead and write pip
  1664. 1:07:20install iy kernel IPI kernel is
  1665. 1:07:23specifically used to install all the
  1666. 1:07:25jupyter notebook kernels itself right so
  1667. 1:07:28once I probably install this you'll be
  1668. 1:07:29able to see that this installation will
  1669. 1:07:31take place and I think it is already
  1670. 1:07:33satisfied so it is good enough we can
  1671. 1:07:35probably go ahead and start the coding
  1672. 1:07:37over here then I will go ahead and
  1673. 1:07:39select my kernel and it is nothing but
  1674. 1:07:423.1 1.0 right this is what is the
  1675. 1:07:45environment that I have created now if I
  1676. 1:07:47go ahead and execute something so it is
  1677. 1:07:49giving me some kind of error okay so
  1678. 1:07:51perfect now what I'm actually going to
  1679. 1:07:53do uh I can see that there is some kind
  1680. 1:07:56of message over here I will just try to
  1681. 1:07:58uh disable this I've already uninstalled
  1682. 1:08:00uh this extension so that it will not
  1683. 1:08:02give us any disturbance so let me do one
  1684. 1:08:05thing let me just open over here for you
  1685. 1:08:09and here I will open this particular
  1686. 1:08:11folder and then I will go ahead and
  1687. 1:08:14close this okay close window okay and
  1688. 1:08:17now let me quickly open the vs code
  1689. 1:08:20again and here is my entire project we
  1690. 1:08:24will just try to execute it once again
  1691. 1:08:26okay perfect so that so that I don't
  1692. 1:08:30have any disturbance with respect to
  1693. 1:08:31that okay now perfect now this is done
  1694. 1:08:34now let's go ahead and start our coding
  1695. 1:08:36initially I will try to show you
  1696. 1:08:39multiple data injection steps okay so
  1697. 1:08:41data injection basically means let's say
  1698. 1:08:43I want to read from a text file I want
  1699. 1:08:45to read from a PDF file I want to read
  1700. 1:08:48from a web web page how can I actually
  1701. 1:08:50do it okay so all those things we'll
  1702. 1:08:52start to discuss so first of all I will
  1703. 1:08:54go ahead and import from Lang chain unor
  1704. 1:08:58Community do document loaders now
  1705. 1:09:01document loaders has all the techniques
  1706. 1:09:04specifically if you want to load uh
  1707. 1:09:06let's say a PDF you want to load a Excel
  1708. 1:09:08file you want to load a txt file so over
  1709. 1:09:11here all the libraries will be present
  1710. 1:09:13so from linore community. doent loaders
  1711. 1:09:17until then I will just close this
  1712. 1:09:18terminal because I will not require over
  1713. 1:09:20here then the first one that I'm
  1714. 1:09:22actually going to discuss about text
  1715. 1:09:24loaded itself now over here what I'm
  1716. 1:09:26actually going to do I'm going to create
  1717. 1:09:27a loader is equal to text
  1718. 1:09:31loader and after creating this text
  1719. 1:09:33loader here I'm going to give a text
  1720. 1:09:36file okay speech. txt so we'll just go
  1721. 1:09:39ahead and see whether we have the
  1722. 1:09:40speech. txt file or not no I don't have
  1723. 1:09:43it so let me go ahead and create one
  1724. 1:09:45speech. txt file okay and uh with
  1725. 1:09:49respect to this particular file what I
  1726. 1:09:51am actually going to do I'm going to put
  1727. 1:09:52some content so I have already have that
  1728. 1:09:55content let me just quickly copy and
  1729. 1:09:57paste it this is one of the most famous
  1730. 1:10:00speech um that is available in some
  1731. 1:10:03history it has been taken over here so I
  1732. 1:10:05just Googled it and I bought this
  1733. 1:10:06particular speech over here and saved it
  1734. 1:10:08in speech. txt okay uh then what I will
  1735. 1:10:12do I will go over here and read the
  1736. 1:10:14speech. txt okay now just by using this
  1737. 1:10:17text loader what will happen is that
  1738. 1:10:19you'll be able to read the speech. txt
  1739. 1:10:21then I will use
  1740. 1:10:23loader do load load and here I'm going
  1741. 1:10:27to specifically convert this entire
  1742. 1:10:30thing into text
  1743. 1:10:32documents okay once I write loader. load
  1744. 1:10:36that basically means it is going to just
  1745. 1:10:38convert this into a text documents and
  1746. 1:10:40this finally you'll be able to see my
  1747. 1:10:42test
  1748. 1:10:44documents and I will go ahead and
  1749. 1:10:46execute it so here you'll be able to see
  1750. 1:10:48that once it is reading the specific
  1751. 1:10:51speech it has the entire text document
  1752. 1:10:54now it is becoming so easy
  1753. 1:10:55just to read the txt file okay now the
  1754. 1:10:58next thing that I'm going to
  1755. 1:10:59specifically do is that uh since I'm
  1756. 1:11:01also going to use open keys or um I'm
  1757. 1:11:05also going to use Ama embeddings or AMA
  1758. 1:11:07model so what I can do is that I will
  1759. 1:11:09just go ahead and import OS um the next
  1760. 1:11:13thing that I will go ahead and do is lo
  1761. 1:11:16load. EnV okay so load. EnV so for this
  1762. 1:11:22I'm also going to import from. EnV
  1763. 1:11:26uh import
  1764. 1:11:29load. EnV okay now why I'm doing this so
  1765. 1:11:32that I will be able to call all my
  1766. 1:11:34environment variables and in one of the
  1767. 1:11:36environment variables I also have my
  1768. 1:11:38open API key so now I will go ahead and
  1769. 1:11:40write OS dot environment and here I'm
  1770. 1:11:44going to use my
  1771. 1:11:46opencore a sorry open aior
  1772. 1:11:51API uncore key
  1773. 1:11:55and here I'm just going to use os.
  1774. 1:12:01getv and here again I'm going to use my
  1775. 1:12:03open API key so this is basically going
  1776. 1:12:05to call the open API key from the
  1777. 1:12:08environment variable now a very
  1778. 1:12:09important step Al together over here
  1779. 1:12:12guys now is the main term that we will
  1780. 1:12:14be starting to uh see some more data
  1781. 1:12:18injection techniques so one more data
  1782. 1:12:20injection technique is directly reading
  1783. 1:12:22from the web based web based
  1784. 1:12:25uh loader you can basically say okay and
  1785. 1:12:28for this again I will be importing
  1786. 1:12:30understand any document loader will be
  1787. 1:12:33available in this specific Library
  1788. 1:12:34itself and instead of writing text
  1789. 1:12:36loader we will be using webbased loader
  1790. 1:12:40okay now along with this I will also
  1791. 1:12:42import bs4 that is beautiful soup 4 so
  1792. 1:12:45for that also what I will do I will just
  1793. 1:12:47import over here in my requirement. txt
  1794. 1:12:50bs4 so that whenever I execute this it
  1795. 1:12:53should be able to run okay now in order
  1796. 1:12:57to do something like this load chunk and
  1797. 1:13:01index the content of the page HTML page
  1798. 1:13:07right or any web page so here I will
  1799. 1:13:09create a loader and this will be equal
  1800. 1:13:12to web based loader and here I'm going
  1801. 1:13:15to give two important parameters one is
  1802. 1:13:17the web path so webcore
  1803. 1:13:21paths okay is equal to and here I will
  1804. 1:13:24give the UR Ur l so let me just take one
  1805. 1:13:26URL from the GitHub IO page that is also
  1806. 1:13:29available in the documentation of langin
  1807. 1:13:32so this is what is the page over here um
  1808. 1:13:35what I will do is that quickly I will
  1809. 1:13:37open a browser and show it to you how
  1810. 1:13:39this page looks like okay so if I
  1811. 1:13:42execute this over here you'll be able to
  1812. 1:13:45see that just a second okay perfect so
  1813. 1:13:49here you you are able to see that uh
  1814. 1:13:52just a second this see is this the same
  1815. 1:13:54page yes it is the same page and I will
  1816. 1:13:58be opening this okay perfect so this is
  1817. 1:14:01the page that you will be able to see
  1818. 1:14:03over here and I want to probably read
  1819. 1:14:05this entire page and uh use it as a rag
  1820. 1:14:09system itself right so in order to read
  1821. 1:14:11this entire page I can just take this
  1822. 1:14:13URL and use this web loader Library so
  1823. 1:14:17here if you see I'm using this web based
  1824. 1:14:19loader library and I'm giving the first
  1825. 1:14:22parameter that is the web path okay the
  1826. 1:14:25second parameter that we can
  1827. 1:14:26specifically give is our arguments right
  1828. 1:14:29so here I will wrate BS doore KW a r GS
  1829. 1:14:34okay so this is the second parameter I'm
  1830. 1:14:36just seeing the documentation and we
  1831. 1:14:38will give the next argument in the form
  1832. 1:14:39of dictionaries the first is parscore
  1833. 1:14:43only okay and then here I'm basically
  1834. 1:14:47going to use my bs4 that is a beautiful
  1835. 1:14:49Soup For Soup trainer okay soup
  1836. 1:14:55strainer soup strainer okay yeah soup
  1837. 1:14:59strainer so this is the first uh
  1838. 1:15:02parameter that I will be specifically
  1839. 1:15:03giving and understand why this is
  1840. 1:15:06required because here the soup strainer
  1841. 1:15:08and since we are using beautiful soup
  1842. 1:15:11over here we really need to give the
  1843. 1:15:13classes that it read it needs to read
  1844. 1:15:16from that particular page okay and here
  1845. 1:15:19what all classes are there let's go
  1846. 1:15:21ahead and see this okay so if I probably
  1847. 1:15:23see over here and if I do just inspect
  1848. 1:15:26element okay so here you can see post
  1849. 1:15:29title is there then you have something
  1850. 1:15:32like post content where all the content
  1851. 1:15:34is basically available so let us take
  1852. 1:15:36this one as my first one okay so I will
  1853. 1:15:39just go ahead and execute this and here
  1854. 1:15:42you'll be able to see that uh this will
  1855. 1:15:45basically be my post title and here you
  1856. 1:15:48have the postore content and third one
  1857. 1:15:53that I also want to take is postore
  1858. 1:15:56header because header will also have
  1859. 1:15:57some information over here right so this
  1860. 1:16:00is done you'll be able to see that it
  1861. 1:16:02looks absolutely fine and here with
  1862. 1:16:04respect to this we have also created
  1863. 1:16:06this entire loader um and here I will
  1864. 1:16:09use a Comm up so that this is basically
  1865. 1:16:11my argument over here right so once we
  1866. 1:16:14do this uh then let's see whether it'll
  1867. 1:16:17execute or not uh bs4 is not found as I
  1868. 1:16:20said that bs4 is not there so let me do
  1869. 1:16:23one thing quickly let me open my command
  1870. 1:16:26prompt and do the PIP install
  1871. 1:16:27requirement. txt okay so here I will go
  1872. 1:16:31ahead and write pip install minus r
  1873. 1:16:34requirement. txt and execute it over
  1874. 1:16:36here you'll be able to see now bs4 will
  1875. 1:16:39also get installed and once it is
  1876. 1:16:40getting installed it is completed it is
  1877. 1:16:43good to go now if we go ahead and
  1878. 1:16:45execute it I think it should work
  1879. 1:16:46perfect now loader is there now what we
  1880. 1:16:49are going to do over here is that again
  1881. 1:16:51write loader. load and finally I will be
  1882. 1:16:53able to get in the form of text
  1883. 1:16:56documents textor documents okay
  1884. 1:17:00documents and here is my text document
  1885. 1:17:03so perhaps you meant uh this one let's
  1886. 1:17:07see um so guys there was one one error
  1887. 1:17:11we need to give this URL in the form of
  1888. 1:17:13duple so let this get closed and then I
  1889. 1:17:16will write comma over here now I think
  1890. 1:17:18it should be working let's see yes
  1891. 1:17:20perfectly it is working right now and if
  1892. 1:17:23you go ahead and see your text documents
  1893. 1:17:25again you will be able to get all the
  1894. 1:17:27information from that particular web
  1895. 1:17:29page in the form of URL okay or in the
  1896. 1:17:31form of documents so this is perfect uh
  1897. 1:17:33you able to get every information over
  1898. 1:17:36here and uh with respect to this you
  1899. 1:17:38will be able to see that yeah you have
  1900. 1:17:40all the information and you can also see
  1901. 1:17:42the page content and everything looks
  1902. 1:17:44fine so these are some of the ways how
  1903. 1:17:46you can specifically make sure that uh
  1904. 1:17:50you probably get all the content from a
  1905. 1:17:52page itself one more thing uh this is
  1906. 1:17:54not not underscore this is Dash so now I
  1907. 1:17:57think you'll be able to see more content
  1908. 1:17:58okay so let me just open this so here
  1909. 1:18:01you'll be able to see all the content
  1910. 1:18:03itself so uh this is one more way one
  1911. 1:18:06more way is directly to read from the
  1912. 1:18:07PDF itself so what I will do is that I
  1913. 1:18:09will quickly create a PDF okay so let me
  1914. 1:18:13do one thing and I will upload a PDF
  1915. 1:18:16over here okay so here I've created this
  1916. 1:18:18attention. PDF this is nothing but
  1917. 1:18:20attention is all you need uh now uh
  1918. 1:18:23using document loader you can also
  1919. 1:18:24directly read completely from the PDF
  1920. 1:18:26itself okay and how to do that see still
  1921. 1:18:29we are in the data injection phase and
  1922. 1:18:31how do we do this we'll also see that so
  1923. 1:18:33from uh the same library that we'll be
  1924. 1:18:35using again we have to focus on document
  1925. 1:18:38loader and here I will copy and paste it
  1926. 1:18:41okay um and this is basically my
  1927. 1:18:45PDF reader one more Library dependency
  1928. 1:18:48will be there okay so we will try to
  1929. 1:18:50install that also so here I'm going to
  1930. 1:18:52write Pi PDF all loader okay and again I
  1931. 1:18:57will be using loader is equal to Pi PDF
  1932. 1:19:00loader Pi PDF loader and I have to give
  1933. 1:19:03my PDF name right so PDF name over here
  1934. 1:19:06specifically is nothing but attention.
  1935. 1:19:08PDF so it is in the same F same folder
  1936. 1:19:11itself so here I will write attention.
  1937. 1:19:14PDF okay now I think I should be getting
  1938. 1:19:17an error if I don't get an error I will
  1939. 1:19:19definitely install yeah I'll install it
  1940. 1:19:21now see pip install P PDF so here I will
  1941. 1:19:24make make sure that I will write
  1942. 1:19:25requirement. txt and I will write Pi PDF
  1943. 1:19:29okay so all these things you really need
  1944. 1:19:30to take care of because they will
  1945. 1:19:32definitely be dependencies because and
  1946. 1:19:35understand rag is one very important
  1947. 1:19:37thing that really needs to get created
  1948. 1:19:38in the form of application so that is
  1949. 1:19:40the reason I'm creating this completely
  1950. 1:19:42from scratch so pip install minus r
  1951. 1:19:44requirement. txt so this is also done I
  1952. 1:19:47think and Pi PDF is also installed
  1953. 1:19:49perfect then the next step again I will
  1954. 1:19:52go ahead and execute this and but here
  1955. 1:19:54also the same step will be required
  1956. 1:19:55loader. loadad and this will basically
  1957. 1:19:58be my documents and I will execute this
  1958. 1:20:01and once I probably execute this this is
  1959. 1:20:03my docs okay perfect so here you'll be
  1960. 1:20:06able to see my entire PDF has been read
  1961. 1:20:08and it is in front of you now the next
  1962. 1:20:10step now see this load data source part
  1963. 1:20:12is basically done we know how to load it
  1964. 1:20:14okay now we will move towards this
  1965. 1:20:17transform okay then we will go ahead
  1966. 1:20:19towards embid okay so the first part of
  1967. 1:20:21load I've actually done with respect to
  1968. 1:20:23PDF web based with respect to text file
  1969. 1:20:27if you go ahead and check out the langin
  1970. 1:20:28documentation this there are still more
  1971. 1:20:31amazing ways to do for Excel file for
  1972. 1:20:33readme file different directories even
  1973. 1:20:36for directors let's say that you have
  1974. 1:20:38lot of files in the directory itself
  1975. 1:20:40many files and you can also load that so
  1976. 1:20:42we'll try to see in upcoming videos more
  1977. 1:20:44about different different examples but
  1978. 1:20:46here just to give an idea about load
  1979. 1:20:48data source and load is actually done
  1980. 1:20:51now let's go ahead and do this transform
  1981. 1:20:53now transform is very much important
  1982. 1:20:54important Now understand guys this is
  1983. 1:20:56your entire PDF documents right now you
  1984. 1:20:58need to convert this PDF documents into
  1985. 1:21:01chunks now how do you do that and again
  1986. 1:21:03they are multiple ways and this ways
  1987. 1:21:06entirely Falls inside the category of
  1988. 1:21:09text splitter inside Lang chain so here
  1989. 1:21:12we are going to write from Lang
  1990. 1:21:13chain from Lang chain dot text
  1991. 1:21:19splitter
  1992. 1:21:21import recursive
  1993. 1:21:25recursive character text splitter we'll
  1994. 1:21:26try to split it with the with the help
  1995. 1:21:28of uh text itself so here I'm going to
  1996. 1:21:31create my text splitter is equal to
  1997. 1:21:34recursive character text splitter and
  1998. 1:21:37here I'm going to specifically use my
  1999. 1:21:39chunk uncore size is equal to 1,000 uh I
  2000. 1:21:42want this specific size to be the chunk
  2001. 1:21:45and let's say the overlap chunk chunk
  2002. 1:21:49overlap okay chunk
  2003. 1:21:53overlap so here I will go ahead and
  2004. 1:21:55write chunk underscore overlap is equal
  2005. 1:21:58to 200 I'll keep this as 200 okay so
  2006. 1:22:01once I do this now this text splitter
  2007. 1:22:02will be uh
  2008. 1:22:04responsible textor splitter dot split
  2009. 1:22:08documents will be responsible in
  2010. 1:22:10splitting all the specific documents
  2011. 1:22:12that I give over here okay so this docs
  2012. 1:22:14will be there and this will be my
  2013. 1:22:17documents final documents that I will be
  2014. 1:22:19able to see okay let's display this
  2015. 1:22:22documents the top five documents still
  2016. 1:22:24here okay
  2017. 1:22:27uh and let's see this so here you'll be
  2018. 1:22:29able to see provided proper attrition is
  2019. 1:22:31Google by Grant permission best model
  2020. 1:22:33this this this this everything is there
  2021. 1:22:36attention. PDF right so all the
  2022. 1:22:38information is basically there um and
  2023. 1:22:41with respect to this if you really want
  2024. 1:22:43to see the more things more uh different
  2025. 1:22:45different uh all the documents in short
  2026. 1:22:48so you can also go ahead and see the
  2027. 1:22:50entire documents over here okay done so
  2028. 1:22:53these are all my documents over here
  2029. 1:22:55Transformers everything is available
  2030. 1:22:56over here now see this is my entire
  2031. 1:22:59documents it has been divided into
  2032. 1:23:01proper smaller chunks now we can take
  2033. 1:23:03this chunks and we can convert that into
  2034. 1:23:06vectors okay and that is what is giving
  2035. 1:23:08you an idea over here right like how we
  2036. 1:23:10have transformed We have basically taken
  2037. 1:23:12this entire PDF document and we have
  2038. 1:23:14divided that into chunks now it's a time
  2039. 1:23:17that we understand how to probably
  2040. 1:23:20convert this into vectors and for this
  2041. 1:23:22we will also be using some different
  2042. 1:23:24different Vector em uh Vector embedding
  2043. 1:23:26techniques right one of the vector
  2044. 1:23:28embedding techniques that I will be
  2045. 1:23:29showing you is with respect to open AI
  2046. 1:23:32so here now we will go ahead and
  2047. 1:23:35probably write about vector embeddings
  2048. 1:23:38and Vector store right Vector embeddings
  2049. 1:23:41is a technique wherein we convert a text
  2050. 1:23:44into vectors okay so how do we do that
  2051. 1:23:46again with the help of open AI so here
  2052. 1:23:48I'm going to write from Lang chain
  2053. 1:23:49uncope Community Dot
  2054. 1:23:53embeddings
  2055. 1:23:55import open
  2056. 1:23:56AI open AI embeddings you can also use
  2057. 1:23:59AMA embeddings it is up to you since if
  2058. 1:24:01you don't have open API you can use AMA
  2059. 1:24:03embeddings directly but the performance
  2060. 1:24:06of open AI embeddings is better far more
  2061. 1:24:08better than AMA embeddings okay so here
  2062. 1:24:10what I'm actually going to do next thing
  2063. 1:24:12is that uh first of all uh we need to
  2064. 1:24:16understand how to probably create
  2065. 1:24:17vectors again to create vectors we can
  2066. 1:24:19use open AI embeddings but after
  2067. 1:24:22creating the vectors we also need to
  2068. 1:24:24store in the vector store that is what
  2069. 1:24:26it is right this Vector store is like
  2070. 1:24:28kind of a database embeddings can be
  2071. 1:24:31embeddings is a technique where we
  2072. 1:24:32convert text into vectors but later
  2073. 1:24:34those text needs to be stored in some
  2074. 1:24:36kind of vector store right so for this
  2075. 1:24:38reason we will be using something called
  2076. 1:24:40as chroma DB so they are come there are
  2077. 1:24:43couple of uh there are couple of vector
  2078. 1:24:46databases that has been provided by Lin
  2079. 1:24:48itself one is chroma one is f um as we
  2080. 1:24:52go ahead you know how to create this
  2081. 1:24:53kind of vector database in the cloud
  2082. 1:24:55also I will show it to you so from Lang
  2083. 1:24:57chain Community I will be using Vector
  2084. 1:25:00stores and here I'm going to import one
  2085. 1:25:03is nothing but chroma uh so with respect
  2086. 1:25:06to this we will go ahead and create my
  2087. 1:25:07DB and here I'm going to write chroma do
  2088. 1:25:11from uncore documents okay from
  2089. 1:25:16documents and here I'm going to
  2090. 1:25:18basically give my entire document okay
  2091. 1:25:21entire documents and I'll not give the
  2092. 1:25:24entire documents let's just give the
  2093. 1:25:25first 20 documents itself because it'll
  2094. 1:25:28take more time to create the embeddings
  2095. 1:25:31right and here the embeddings that I'm
  2096. 1:25:32going to specifically use is nothing but
  2097. 1:25:34open AI embeddings once I execute this I
  2098. 1:25:36think I'm going to get an error saying
  2099. 1:25:38that chroma is not available I don't
  2100. 1:25:39know whether I've installed chroma or
  2101. 1:25:41not so here you can see pip install
  2102. 1:25:43chroma DB I really require chroma DB so
  2103. 1:25:45again I'll go back to my requirement.
  2104. 1:25:47txt the reason why I'm showing you all
  2105. 1:25:49this completely from scratch so that you
  2106. 1:25:51whatever error you face you should be
  2107. 1:25:53able to fix it set up okay so I'm going
  2108. 1:25:56to delete this and let's go ahead and
  2109. 1:25:58write pip install uh one more library
  2110. 1:26:01that I will be using is nothing but F
  2111. 1:26:04CPU okay F CPU because f is also one
  2112. 1:26:08type of chroma one type of vector
  2113. 1:26:10database okay so minus r requirement.
  2114. 1:26:13txt so let's install both the specific
  2115. 1:26:16libraries it'll take some amount of time
  2116. 1:26:17again it depends on your internet speed
  2117. 1:26:19and how fast your system is but yes I
  2118. 1:26:22think 5 CPU and chroma B is the kind of
  2119. 1:26:25uh Vector databases that we will be
  2120. 1:26:27using one assignment I'll give you try
  2121. 1:26:29to also use Lance Vector database from
  2122. 1:26:32again seeing the lanon documentation you
  2123. 1:26:34can actually do it
  2124. 1:26:36okay now this is done once uh this will
  2125. 1:26:38probably be done then we can go ahead
  2126. 1:26:40and check by executing it whether it is
  2127. 1:26:42working now or not but at the end of the
  2128. 1:26:44day here what we are actually doing we
  2129. 1:26:47have imported open iddings the vector
  2130. 1:26:49database that we are going to use is
  2131. 1:26:51chroma then chroma from document I'm
  2132. 1:26:54giving the entire document and using
  2133. 1:26:55this embeddings it will be storing
  2134. 1:26:57inside this particular Vector store now
  2135. 1:26:59this DB we can store it in our local we
  2136. 1:27:02can store it in the cloud wherever you
  2137. 1:27:04specifically want okay so guys the
  2138. 1:27:06installation has been completed now
  2139. 1:27:08let's go ahead and execute this chroma
  2140. 1:27:10part now here you'll be able to see that
  2141. 1:27:12entire embedding will basically happen
  2142. 1:27:14and again we are going to use the open a
  2143. 1:27:16embedding for this and now this DB is
  2144. 1:27:19nothing but our Vector database okay so
  2145. 1:27:21if I probably consider Vector database
  2146. 1:27:23and now all I have to do is that I can
  2147. 1:27:25query anything with respect to this
  2148. 1:27:27particular Vector database to retrieve
  2149. 1:27:30any kind of result that I really want so
  2150. 1:27:32I will create a query first of all so
  2151. 1:27:34here let me go ahead and write my query
  2152. 1:27:35so query is like I will go ahead and
  2153. 1:27:37write who are the
  2154. 1:27:39authors who are the authors of attention
  2155. 1:27:44is all you need research paper okay so
  2156. 1:27:48this is my query that I'm going to
  2157. 1:27:50specifically ask let's see whether it'll
  2158. 1:27:53be able to understand this or and it'll
  2159. 1:27:55be able to give us the result so here I
  2160. 1:27:57will go ahead and write DB
  2161. 1:27:59do similarity search now there are
  2162. 1:28:02multiple option similarity search
  2163. 1:28:04similarity search by Vector if you want
  2164. 1:28:06you can also convert your data into
  2165. 1:28:08vectors by using again the openi imings
  2166. 1:28:10and you can query it from here but we
  2167. 1:28:11are just going to use the similarity
  2168. 1:28:13search since we are just going to use
  2169. 1:28:14the query over here right so if I write
  2170. 1:28:17db. similarity search of query so this
  2171. 1:28:20will basically be my result okay now
  2172. 1:28:23let's go ahead and see my result okay
  2173. 1:28:26and let's execute this so here you'll be
  2174. 1:28:29able to see that I'm able to see
  2175. 1:28:30multiple information like four documents
  2176. 1:28:32has been over here so let's take the
  2177. 1:28:35first document and let's see how the
  2178. 1:28:37result is so here I'm going to basically
  2179. 1:28:39take zero and inside that the field name
  2180. 1:28:42is nothing but page content so I'm going
  2181. 1:28:44to basically write my page content now
  2182. 1:28:47here you'll be able to see Pro provided
  2183. 1:28:48proper attribution is provided Google
  2184. 1:28:50here by Grand permission and here you'll
  2185. 1:28:53be able to see go gole brain all the
  2186. 1:28:55email IDs all the researchers names are
  2187. 1:28:58actually available so that basically
  2188. 1:29:00means it is able to resear uh it is able
  2189. 1:29:02to retrieve the results of the all the
  2190. 1:29:05scientists who are involved all the
  2191. 1:29:06researchers who are involved in creating
  2192. 1:29:07this particular paper um I can also do
  2193. 1:29:10one more thing I can go ahead and write
  2194. 1:29:12what is
  2195. 1:29:14attention uh is all you need okay
  2196. 1:29:18attention is all you need Okay so let's
  2197. 1:29:22see what kind of results I will be able
  2198. 1:29:24to get and understand this is entirely
  2199. 1:29:26rag pipeline which is being able to come
  2200. 1:29:28from the entire documentation and here
  2201. 1:29:30you'll be able to see that result is
  2202. 1:29:31also coming uh let me do uh write
  2203. 1:29:35something which is available in the
  2204. 1:29:36research paper so let me open my
  2205. 1:29:39research paper over here and let me ask
  2206. 1:29:41some question directly okay from here
  2207. 1:29:43you'll be able to see see when I'm
  2208. 1:29:45searching attention is all you need it
  2209. 1:29:47is coming from here itself right so let
  2210. 1:29:49me use something over here m
  2211. 1:29:55uh let me just write over here encoder
  2212. 1:29:58is uh what is an attention function let
  2213. 1:30:01me just go and search this okay let's
  2214. 1:30:03see attention is something something
  2215. 1:30:05some text is there over here so if I go
  2216. 1:30:08ahead and execute
  2217. 1:30:09it and here you'll be instead of
  2218. 1:30:11performing a single attention function
  2219. 1:30:13with the model Dimension values keys and
  2220. 1:30:15all the information is basically coming
  2221. 1:30:17up right and here is a very good result
  2222. 1:30:19and this is directly coming from the
  2223. 1:30:20vector database that is the most amazing
  2224. 1:30:22thing over here right now you may be
  2225. 1:30:24also thinking chish can we also use the
  2226. 1:30:26F database fire deped database that we
  2227. 1:30:29have used right so let me just show you
  2228. 1:30:30with respect to that also F and here I'm
  2229. 1:30:34going to use the fire Vector database
  2230. 1:30:36and this will also give you an idea how
  2231. 1:30:38you can actually store that embeddings
  2232. 1:30:39into F database itself and we'll also do
  2233. 1:30:43that so here I'm going to write from
  2234. 1:30:44Lang
  2235. 1:30:45chain Lang chain
  2236. 1:30:48uncope
  2237. 1:30:49Community do Vector stores I'm going to
  2238. 1:30:54import my FIS F and then I'm going to
  2239. 1:30:59also use TB is equal to FIS Dot from
  2240. 1:31:04documents the same thing right so from
  2241. 1:31:06underscore documents and here I'm going
  2242. 1:31:09to use my documents okay and let's say I
  2243. 1:31:14go ahead and do the embedding for the
  2244. 1:31:16first 20 documents and then here also
  2245. 1:31:18I'm going to use my open biddings and I
  2246. 1:31:21think this is also my another DB so I
  2247. 1:31:23will write it it at DB1 which is my f
  2248. 1:31:26database okay uh from documents okay no
  2249. 1:31:29worries uh so here the spelling mistake
  2250. 1:31:31was there and I think this will also
  2251. 1:31:33work now DB1 is also ready and what I
  2252. 1:31:35can do I can use the same thing and
  2253. 1:31:37paste it over here okay and just write
  2254. 1:31:40DB1 do similarity search and here you
  2255. 1:31:43can see instead of performing a single
  2256. 1:31:44attention everything is probably coming
  2257. 1:31:46up so I've just shown you the example of
  2258. 1:31:49both F and uh chroma database chroma
  2259. 1:31:53Vector database as I said one assignment
  2260. 1:31:56will be given to you is regarding Lance
  2261. 1:31:59Vector database you can go and search it
  2262. 1:32:01for that in the in the in the langin
  2263. 1:32:03documentation we are going to continue
  2264. 1:32:05the langin series and now we will be
  2265. 1:32:07developing Advanced rag pipeline using
  2266. 1:32:10Retriever and chain Concepts that are
  2267. 1:32:11available in Lang chain now before I go
  2268. 1:32:14ahead I really want to talk about a
  2269. 1:32:15funny incident that really happened uh
  2270. 1:32:18recently just today itself so what I did
  2271. 1:32:21what I do is that every day morning I
  2272. 1:32:22usually go and play some badminton you
  2273. 1:32:24know I play for one hours one and a half
  2274. 1:32:26hour and usually a lot of my friends and
  2275. 1:32:28neighbors usually come and play you know
  2276. 1:32:30so today what happened after playing I
  2277. 1:32:32went today in this look okay I played
  2278. 1:32:34around three to four games and then one
  2279. 1:32:36of my neighbors said hey Krish you're
  2280. 1:32:39Kish right you just got identified right
  2281. 1:32:41now just by seeing your should I
  2282. 1:32:43identified you but your look has
  2283. 1:32:44completely changed so let me know if
  2284. 1:32:46this is true in the comment section of
  2285. 1:32:47this particular video but I am liking
  2286. 1:32:49this look uh you know it's like so much
  2287. 1:32:53of less maintenance you don't have to
  2288. 1:32:54maintain your beard your mustac or your
  2289. 1:32:57hair also right it looks super cool now
  2290. 1:33:00let's go ahead and uh work towards this
  2291. 1:33:03specific project in our previous
  2292. 1:33:05tutorial what we had actually done is
  2293. 1:33:07that we had created this simple rack
  2294. 1:33:09pipeline okay we had a data data source
  2295. 1:33:13like we took PDF we took website then we
  2296. 1:33:17uh load that particular data set using
  2297. 1:33:19different different data injection
  2298. 1:33:20techniques that were available in Lang
  2299. 1:33:22chain then we did transformation wherein
  2300. 1:33:25we broke down our bigger PDFs into
  2301. 1:33:28chunks and then we converted all this
  2302. 1:33:31particular chunks into vectors and
  2303. 1:33:33stored it in a vector store and then
  2304. 1:33:35with the help of query we are able to
  2305. 1:33:38probably retrieve some of the data that
  2306. 1:33:40is available in the vector store now
  2307. 1:33:42this is one step now the further step
  2308. 1:33:44after this particular query Vector Now
  2309. 1:33:46understand query Vector are not that
  2310. 1:33:48efficient you know when in terms of
  2311. 1:33:50retrieving the entire results here we
  2312. 1:33:53will also specifically used llm models
  2313. 1:33:56okay so now what we will try to do is
  2314. 1:33:58that using some prompts okay and we will
  2315. 1:34:03take this specific prompts we will take
  2316. 1:34:05this particular data using the concept
  2317. 1:34:07of chain and retriever okay and
  2318. 1:34:11understand this topic is very important
  2319. 1:34:14because this is where your Advanced rack
  2320. 1:34:17pipeline implementation will start using
  2321. 1:34:19chain and retriever we will also use and
  2322. 1:34:22in this chain and retriever what we do
  2323. 1:34:24is that we specifically use llm models
  2324. 1:34:26it can be open source it can be paid
  2325. 1:34:29whatever model you want so we will
  2326. 1:34:31specifically use this llm model and
  2327. 1:34:33based on this prompt we will try to get
  2328. 1:34:35the response on what we are specifically
  2329. 1:34:38looking right so there will be a lot of
  2330. 1:34:40customization that will be added once we
  2331. 1:34:43implement this specific part in the
  2332. 1:34:44first part we discussed about this and
  2333. 1:34:47this is the second part that we are
  2334. 1:34:48going to discuss okay how we can use
  2335. 1:34:51chain how we can use retriever what
  2336. 1:34:53exactly is chain how you can integrate
  2337. 1:34:55in this particular llm model there is a
  2338. 1:34:57concept of something called as stuff
  2339. 1:34:59document chain what exactly it is so we
  2340. 1:35:01will discuss everything all about it and
  2341. 1:35:04here we also going to do a practical
  2342. 1:35:06implementation so please make sure that
  2343. 1:35:08you watch this video till the end and we
  2344. 1:35:10are going to learn a lot of things okay
  2345. 1:35:12so here the first step what we had done
  2346. 1:35:14on already uh we have implemented this
  2347. 1:35:17in our previous tutorial also so here
  2348. 1:35:19you'll be able to see that I'm trying to
  2349. 1:35:21read attention. PDF which is Pres
  2350. 1:35:23present in a folder and then we just
  2351. 1:35:25write loader. load and we get the
  2352. 1:35:27documents okay so these are all the
  2353. 1:35:29documents that will be available in this
  2354. 1:35:31specific PDF okay then what we are
  2355. 1:35:34specifically doing next step is that
  2356. 1:35:35from lin. text plat we will be using
  2357. 1:35:38recursive character text plater wherein
  2358. 1:35:40we convert the entire document into
  2359. 1:35:41chunks right and then we are probably
  2360. 1:35:44using this text splitter and we are
  2361. 1:35:47using a chunk size of th000 overlap of
  2362. 1:35:4920 so this everything is implemented in
  2363. 1:35:51my previous videos right so we are going
  2364. 1:35:53going to split this entire document and
  2365. 1:35:55save it in this particular documents in
  2366. 1:35:57the previous tutorial we have
  2367. 1:35:58implemented all these things now here
  2368. 1:36:00what we are going to take do now we'll
  2369. 1:36:02take all these documents and then we
  2370. 1:36:04will convert it into a vector store
  2371. 1:36:06right so Vector store for that we are
  2372. 1:36:08using this F okay so here we are going
  2373. 1:36:11we can use AMA embedding or open AI
  2374. 1:36:13embedding right as I said you open AI
  2375. 1:36:15embedding is very much Advanced and it
  2376. 1:36:17will perform better than AMA embedding
  2377. 1:36:20if you don't have opening a API key use
  2378. 1:36:22Ama eming emding instead of open AI
  2379. 1:36:25embedding over here you can just write
  2380. 1:36:26AMA embedding right so from here I'll be
  2381. 1:36:29using F which is again a kind of vector
  2382. 1:36:31store and it has been developed by meta
  2383. 1:36:34so fest. from documents document of 20
  2384. 1:36:36so I'm just taking the first 20
  2385. 1:36:38documents and I'm just writing open a
  2386. 1:36:40biddings let's make it to 30 so that it
  2387. 1:36:42will have some amount of data right now
  2388. 1:36:45we are specifically using open AI
  2389. 1:36:47bidding and this DB that you
  2390. 1:36:48specifically see is a my Vector store
  2391. 1:36:51okay so here you can see vector store f
  2392. 1:36:54f of type okay perfect
  2393. 1:36:57now any question that I ask attention
  2394. 1:37:00function can be described as a mapping
  2395. 1:37:02query and then we can take this Vector
  2396. 1:37:03store and just write do similarity
  2397. 1:37:05search on this query and we will get the
  2398. 1:37:07result over here okay so this all things
  2399. 1:37:10we have actually done in our previous
  2400. 1:37:12video now is the most important thing
  2401. 1:37:14how I can combine prompt along with
  2402. 1:37:17chains and Retriever and then probably
  2403. 1:37:20get a response based on the prompt okay
  2404. 1:37:22so say since many people have the use of
  2405. 1:37:25only open source uh they have the access
  2406. 1:37:27of Open Source model llm model so I'm
  2407. 1:37:30going to use AMA from lin. community.
  2408. 1:37:32llms import olama then I'm going to use
  2409. 1:37:35AMA over here model will be Lama 2 if
  2410. 1:37:38you don't have Lama 2 just to go to
  2411. 1:37:40command prompt after downloading AMA I
  2412. 1:37:42hope everybody knows how to download it
  2413. 1:37:44if you're seeing my series of videos
  2414. 1:37:46here you can just write AMA run Lama 2
  2415. 1:37:49right so once you write like this then
  2416. 1:37:51the model will get downloaded right if
  2417. 1:37:53it is already downloaded it will be
  2418. 1:37:54coming something like this okay so this
  2419. 1:37:57is the first step that you really need
  2420. 1:37:58to do then I have written from lin.
  2421. 1:38:00community. LM AMA load AMA so whatever
  2422. 1:38:04AMA model we are specifically using that
  2423. 1:38:06is Lama 2 so this is my open source
  2424. 1:38:08model so if you see Lama llm it is
  2425. 1:38:10nothing but AMA now is the time we will
  2426. 1:38:13start designing our prompt template now
  2427. 1:38:16in order to design the chat prompt
  2428. 1:38:17template I will be using CH linore core.
  2429. 1:38:21prompts import chat prompt template okay
  2430. 1:38:23and then from chat pron template from
  2431. 1:38:25template I'm just writing like this so
  2432. 1:38:27I'm saying answer the following question
  2433. 1:38:30based only on the provided context now
  2434. 1:38:33see we are trying to develop a Q&A Q&A
  2435. 1:38:36chatboard based on the context it should
  2436. 1:38:38provide me the response
  2437. 1:38:40previously what we are doing using
  2438. 1:38:42Vector store we used to if you see the
  2439. 1:38:46code over here we used to query the
  2440. 1:38:48vector score right Vector store by using
  2441. 1:38:50similarity search algorithm but here
  2442. 1:38:52what we are doing here we are defining
  2443. 1:38:54our own prompt and we saying hey answer
  2444. 1:38:57the following question based on the
  2445. 1:38:58provided context right I will and simply
  2446. 1:39:01I'm writing away I'll tip you $1,000 if
  2447. 1:39:04you find the answer helpful okay if the
  2448. 1:39:06user find the answer helpful okay just
  2449. 1:39:09at least by seeing money the AI May
  2450. 1:39:11perform well and then we are giving our
  2451. 1:39:13context and then question will be input
  2452. 1:39:15okay how why I'm writing in this
  2453. 1:39:18specific way because this chain and
  2454. 1:39:19retriever right you'll be understanding
  2455. 1:39:21this context will be autofilled and this
  2456. 1:39:23input will also get autofilled okay how
  2457. 1:39:25it will get autofilled I'll let you know
  2458. 1:39:27so now what I will do I will execute
  2459. 1:39:29this now I will go ahead and Implement
  2460. 1:39:31about chain uh it is always a good idea
  2461. 1:39:36okay to probably go to your browser and
  2462. 1:39:39check about each and every topic that
  2463. 1:39:41I'm explaining so what does chain refer
  2464. 1:39:43to chain referred to a sequence of calls
  2465. 1:39:46whether to an llm tool or data
  2466. 1:39:49pre-processing step the primary
  2467. 1:39:51supported way to do this is lcf okay now
  2468. 1:39:54if you talk about chain over here there
  2469. 1:39:57are multiple functions with respect to
  2470. 1:39:59chain one of the function that I'm am
  2471. 1:40:01going to use is create stuff document
  2472. 1:40:03chain now what this exactly does this
  2473. 1:40:06chain takes a list of documents and
  2474. 1:40:08formats them into all into a prompt then
  2475. 1:40:12passes that prompt to an
  2476. 1:40:14llm see this this chains take a list of
  2477. 1:40:17documents and formats them based on the
  2478. 1:40:19prompt formats them into a prompt sorry
  2479. 1:40:22not based on the prompt into the the
  2480. 1:40:23problem that basically means over here
  2481. 1:40:26if I go ahead and open my
  2482. 1:40:29browser here in the context I definitely
  2483. 1:40:32require my document sour self right
  2484. 1:40:35based on that context and based on this
  2485. 1:40:37input I will be able to give the answer
  2486. 1:40:39right so based on this context and based
  2487. 1:40:40on the input right context basically
  2488. 1:40:42means all the documents that are there
  2489. 1:40:44available in the vector store right
  2490. 1:40:47inputs are what question I'm asking
  2491. 1:40:49right so with the help of this create
  2492. 1:40:52stuff document chain what is basically
  2493. 1:40:54happening this chain takes a list of
  2494. 1:40:56documents and formats them all into a
  2495. 1:40:58prompt then passes that prompt to an llm
  2496. 1:41:01it passes all the documents so that you
  2497. 1:41:02should make sure that it fits within the
  2498. 1:41:04context window the llm you are using so
  2499. 1:41:07what it is exactly doing it will take up
  2500. 1:41:08all the documents from the vector store
  2501. 1:41:10it will put that put inside that
  2502. 1:41:11particular prom template and then it
  2503. 1:41:13will send the to the llm and then we
  2504. 1:41:15finally get the response okay and that
  2505. 1:41:17is what we'll be using similarly there
  2506. 1:41:19are different different uh things also
  2507. 1:41:21over here like create stuff document
  2508. 1:41:23change is there create SQL query chain
  2509. 1:41:25if you're working with respect to SQL
  2510. 1:41:26database for natural language and this
  2511. 1:41:28is one of the very important project
  2512. 1:41:30that I'll also do in the future one or
  2513. 1:41:32the other way I'll try to use one or the
  2514. 1:41:35other functionalities to just make you
  2515. 1:41:37understand how we can use all this
  2516. 1:41:39functionalities itself right but it is
  2517. 1:41:41always good that we have a specific use
  2518. 1:41:44case okay now if I open this okay let's
  2519. 1:41:48go ahead and create my chain how do I
  2520. 1:41:50create my chain over here again it's
  2521. 1:41:52very simple so so I will write from Lang
  2522. 1:41:55chain Lang chain _ community so it is
  2523. 1:41:58present inside Community itself or not
  2524. 1:42:00Community sorry chains Lang chore chains
  2525. 1:42:04dot combine
  2526. 1:42:08documents
  2527. 1:42:09import create Stu document chain now how
  2528. 1:42:13do I know this okay I did not create
  2529. 1:42:15this I have already seen the
  2530. 1:42:17documentation okay that is the reason
  2531. 1:42:18I'm writing then I will go ahead and
  2532. 1:42:20create my document chain now inside this
  2533. 1:42:24document chain as I said I'll be using
  2534. 1:42:26create stuff document chain okay that we
  2535. 1:42:29have already seen now inside this chain
  2536. 1:42:31two things are basically required one is
  2537. 1:42:34the llm model and the second one is the
  2538. 1:42:37prompt that I have created because
  2539. 1:42:40inside this prompt itself the list of
  2540. 1:42:42documents will be added right whatever
  2541. 1:42:44documents is basically coming from here
  2542. 1:42:46right from my Vector store that will be
  2543. 1:42:48added over here okay so once I create
  2544. 1:42:51this so This basically becomes my
  2545. 1:42:53document chain okay very much simple now
  2546. 1:42:57after this we also have to learn about
  2547. 1:42:59one very important thing which is called
  2548. 1:43:01as
  2549. 1:43:03retrievers okay so I will go ahead and
  2550. 1:43:05write something called as
  2551. 1:43:09retriever retriever Lang chain okay now
  2552. 1:43:12what exactly retriever Lang chain is it
  2553. 1:43:15is an interface that recur document
  2554. 1:43:17given an unstructured query it is more
  2555. 1:43:20General than a vector store right a
  2556. 1:43:23retriever does not need to be able to
  2557. 1:43:25store the documents only to return or
  2558. 1:43:27retrieve them Vector store can be based
  2559. 1:43:29as the backbone of the retriever now see
  2560. 1:43:32there is a vector store which is having
  2561. 1:43:34some information some Vector stored in
  2562. 1:43:36it right if I want to take out any data
  2563. 1:43:39from there right I can actually do a
  2564. 1:43:41similarity search which we have already
  2565. 1:43:42seen okay but langen what it did is that
  2566. 1:43:46since we usually do a lot of programming
  2567. 1:43:48in a way right where in classes are used
  2568. 1:43:51interfaces are used so it created a
  2569. 1:43:53separate interface which is called as
  2570. 1:43:55Retriever and that interface has a
  2571. 1:43:58backend source to that particular Vector
  2572. 1:44:00store to retrieve any information right
  2573. 1:44:04whenever a query is given right that
  2574. 1:44:06entire Vector store will be passing the
  2575. 1:44:09information through this retriever okay
  2576. 1:44:11so what we will do is that here I will
  2577. 1:44:15quickly open this I have also written
  2578. 1:44:17some amount of description so that it
  2579. 1:44:19will be helpful for you whenever you
  2580. 1:44:22probably go go ahead and check it this
  2581. 1:44:24entire materials okay so now what I will
  2582. 1:44:26do I will just go ahead and write DB
  2583. 1:44:30dot DB dot as retriever now once I do
  2584. 1:44:35like this DB do as retriever this
  2585. 1:44:37basically has become my retriever right
  2586. 1:44:41so what we have done DB is our Vector
  2587. 1:44:43store already it is there we have
  2588. 1:44:45connected to an interface which is
  2589. 1:44:47basically this particular variable now
  2590. 1:44:49okay so if you go ahead and ex uh
  2591. 1:44:53probably display this what is retrieval
  2592. 1:44:55it is nothing but it is a vector store
  2593. 1:44:56retrieval internally you'll be also able
  2594. 1:44:59to see that what all it is implemented F
  2595. 1:45:01and open AI Mings and all all the
  2596. 1:45:03information are there now retriever is
  2597. 1:45:05done chain is also done okay now is the
  2598. 1:45:08time that what I will do I will try to
  2599. 1:45:11use this Retriever and document chain
  2600. 1:45:14both together to probably see when we
  2601. 1:45:17combine both of them then only we'll be
  2602. 1:45:19able to get the response right so with
  2603. 1:45:23respect to this now let's go ahead and
  2604. 1:45:25create my retriever chain okay so the
  2605. 1:45:29next step is what since I need to
  2606. 1:45:31combine both of them one is Retriever
  2607. 1:45:34and one is the document chain right this
  2608. 1:45:37document chain is responsible for
  2609. 1:45:38putting the information in the context
  2610. 1:45:40when we combine both of them then it
  2611. 1:45:42becomes a retriever chain now what is
  2612. 1:45:43the definition this chain takes an input
  2613. 1:45:46as a user inquiry which is then passed
  2614. 1:45:49to the retriever to fetch the relevant
  2615. 1:45:51documents so it passes through the
  2616. 1:45:53retriever it is connected to the vector
  2617. 1:45:54store then those documents are then
  2618. 1:45:57passed to an llm to generate the
  2619. 1:45:58response and this llm that we are
  2620. 1:46:01basically getting it it is basically
  2621. 1:46:02coming from what this document chain
  2622. 1:46:05understand the flow okay so let me just
  2623. 1:46:07go ahead and mention this flow again so
  2624. 1:46:10that it becomes very much easy for you
  2625. 1:46:12so whenever the
  2626. 1:46:14users this is my user okay whenever the
  2627. 1:46:18user asks for any
  2628. 1:46:20inquiry okay any inquiry so first what
  2629. 1:46:24it is going it is going to this
  2630. 1:46:26retriever okay very much important okay
  2631. 1:46:29so this is my retriever this retriever
  2632. 1:46:32is an interface to what Vector store
  2633. 1:46:36which has all the information right so
  2634. 1:46:38once we basically get the retriever then
  2635. 1:46:40the next step what it happens it goes to
  2636. 1:46:43what it goes to my llm model with some
  2637. 1:46:47prompt right there will be some prompt
  2638. 1:46:50involved to this and how this is
  2639. 1:46:52basically happening
  2640. 1:46:54with the help of stuff document
  2641. 1:46:57chain so this stuff document chain has
  2642. 1:47:00already both these things combined llm
  2643. 1:47:03and prompt right and then finally we get
  2644. 1:47:06our
  2645. 1:47:08response I hope you're able to
  2646. 1:47:10understand this right and this is what
  2647. 1:47:11we have basically implemented over here
  2648. 1:47:13now how to basically create a retriever
  2649. 1:47:15chain so first for for all of this again
  2650. 1:47:19I will be using a library um with
  2651. 1:47:21respect to chains okay okay so form Lang
  2652. 1:47:26chain Lang
  2653. 1:47:28chain dot
  2654. 1:47:30chains
  2655. 1:47:32import create retrieval chain right and
  2656. 1:47:36there are lot of things create QA with
  2657. 1:47:38Source chain retrieval chain this chain
  2658. 1:47:41that chain I will try to explain you all
  2659. 1:47:43of things don't worry okay I will cast
  2660. 1:47:45the right kind of use case and I will be
  2661. 1:47:49showcasing you all these things don't
  2662. 1:47:51worry about that okay then what I will
  2663. 1:47:53do I will I will take this entire create
  2664. 1:47:55retrieval chain and then I will create
  2665. 1:47:58my uh retrieval chain so here I will
  2666. 1:48:01write
  2667. 1:48:03retrieval chain is equal
  2668. 1:48:06to create retrieval chain and here I'm
  2669. 1:48:09going to use first parameter that I'm
  2670. 1:48:11going to use is retriever then the
  2671. 1:48:13second parameter is nothing but document
  2672. 1:48:15chain so once I have this chain right
  2673. 1:48:18now I will be able to invoke any queries
  2674. 1:48:21so I will go ahead and write retrieval
  2675. 1:48:23chain dot invoke okay and now what are
  2676. 1:48:28the parameters that I have to give
  2677. 1:48:30nothing I have to give my input so the
  2678. 1:48:33input will be given over here colon and
  2679. 1:48:36whatever input that I can give let's say
  2680. 1:48:39from the PDF I have put some input over
  2681. 1:48:42here let me just copy and paste it okay
  2682. 1:48:45so this is one of the text that is
  2683. 1:48:46available in the PDF that is attention.
  2684. 1:48:48PDF and now if I invoke this you'll be
  2685. 1:48:51able to see that I will be able to get
  2686. 1:48:53the entire response okay so retrieval do
  2687. 1:48:56chain. invoke and again we are using
  2688. 1:48:58open source llm model that is Lama 2
  2689. 1:49:01okay yeah I've used open EMB bidding so
  2690. 1:49:03here you can see this is my input this
  2691. 1:49:05was the context right all the context
  2692. 1:49:08information is there and finally I get
  2693. 1:49:09the answer and this answer I will just
  2694. 1:49:12try to save it over here something like
  2695. 1:49:17response uh res
  2696. 1:49:20response okay and then I will execute
  2697. 1:49:26response response of answer so this
  2698. 1:49:29finally becomes the my output that is
  2699. 1:49:32probably coming over here okay so this
  2700. 1:49:33if I execute it the answer to the
  2701. 1:49:35question is right and all the
  2702. 1:49:38information you can see the answer to
  2703. 1:49:40the question and it is retrieving all
  2704. 1:49:42the details right so here you'll be able
  2705. 1:49:45to see that how beautifully with the
  2706. 1:49:47help of llm we have constructed this
  2707. 1:49:49entire thing and we have used this
  2708. 1:49:52chains Retriever and this is the first
  2709. 1:49:54step towards developing your Advanced
  2710. 1:49:56rack pipeline right so whatever question
  2711. 1:49:59you ask let me just open this and
  2712. 1:50:01probably show you some more examples
  2713. 1:50:04okay so what I will do I will just open
  2714. 1:50:07my download
  2715. 1:50:09page let's see my download page I'll ask
  2716. 1:50:13for any statement okay just a second um
  2717. 1:50:18attention Okay so this is my
  2718. 1:50:21thing uh let me just go ahead and search
  2719. 1:50:24for
  2720. 1:50:25anything the decoder is the this and
  2721. 1:50:28this okay so I'll be searching from here
  2722. 1:50:30to here okay now let me go ahead and
  2723. 1:50:34change my
  2724. 1:50:36input and search for it so chain. invoke
  2725. 1:50:40I've done and here I've got the response
  2726. 1:50:44now let me just go and I uh the answer
  2727. 1:50:46to this question is
  2728. 1:50:48six um the decoder is also composed of
  2729. 1:50:51stack of n6 oh it has basically taken
  2730. 1:50:53this no worries okay let's take some
  2731. 1:50:55more
  2732. 1:50:58thing I'll write scaled do product
  2733. 1:51:02attention some more
  2734. 1:51:08examples oops uh
  2735. 1:51:12error okay just a second now I think it
  2736. 1:51:17should not
  2737. 1:51:20be okay it is taking that question and
  2738. 1:51:23it is trying to form some answers out of
  2739. 1:51:25it
  2740. 1:51:25okay got it got it it is not a mistake I
  2741. 1:51:29thought it was a mistake out there scale
  2742. 1:51:31is a type of this this this see I'm
  2743. 1:51:33getting all the answers over here uh we
  2744. 1:51:35are going to continue the Lang chain
  2745. 1:51:37series and in this video we are going to
  2746. 1:51:39probably develop an amazing multi-search
  2747. 1:51:41agent rag application um what exactly is
  2748. 1:51:44the project all about what all new
  2749. 1:51:46things we are going to specifically
  2750. 1:51:48learn and probably I think this is the
  2751. 1:51:50most amazing thing that has been
  2752. 1:51:52inserted in the Lang chain Library
  2753. 1:51:54itself some of the amazing modules that
  2754. 1:51:56are there which will actually help you
  2755. 1:51:58to make your entire conversational
  2756. 1:51:59chatbot quite amazing itself right so
  2757. 1:52:02let me go ahead and discuss about this
  2758. 1:52:04what what exactly we are going to do
  2759. 1:52:05what kind of projects we are going to
  2760. 1:52:06implement here so let's consider that I
  2761. 1:52:09want to generate a gen AI powered llm
  2762. 1:52:12application so this is my llm
  2763. 1:52:13application that I really want to
  2764. 1:52:15generate and this let's consider that it
  2765. 1:52:17has dependencies on some of the other
  2766. 1:52:20open source platforms or other websites
  2767. 1:52:22all the data sources itself right like
  2768. 1:52:24like RVE R if you don't know like all of
  2769. 1:52:27the research papers that are available
  2770. 1:52:28will be available over here if I
  2771. 1:52:30probably consider with respect to
  2772. 1:52:31Wikipedia right Wikipedia also has a
  2773. 1:52:33huge amount of content similarly I may
  2774. 1:52:35also have let's say my own company's PDF
  2775. 1:52:38you know from where I also need to
  2776. 1:52:39probably develop our Q&A applications
  2777. 1:52:42right so all these things we will
  2778. 1:52:43probably try to implement it now the
  2779. 1:52:46main thing is that here you have
  2780. 1:52:47multiple data sources and you really
  2781. 1:52:49want to integrate all them as a rapper
  2782. 1:52:52so that you'll be able to implement this
  2783. 1:52:54entire Q&A solution right over here so
  2784. 1:52:57here you're also going to learn about
  2785. 1:52:58some new terms and right now it is
  2786. 1:53:00becoming very popular like tools right
  2787. 1:53:03tools what are tools in Lang chain what
  2788. 1:53:05are agents in Lan chain what are
  2789. 1:53:07toolkits we'll also be learning about
  2790. 1:53:09toolkits right and how do you probably
  2791. 1:53:12create a wrapper on top of this
  2792. 1:53:13particular toolkits but if I just want
  2793. 1:53:16to give a small brief introduction about
  2794. 1:53:18tools you can see that here I have
  2795. 1:53:20dependency on this platform on this plat
  2796. 1:53:22I can probably use all these platforms
  2797. 1:53:25as a separate tool so that I'll be able
  2798. 1:53:27to ask any questions from this
  2799. 1:53:29particular platform itself along with
  2800. 1:53:31that I may also have my own customized
  2801. 1:53:33PDF own custom data which will also be
  2802. 1:53:35in the form of vector embeding so what I
  2803. 1:53:38will do is that I will try to wrap this
  2804. 1:53:39up in the form of toolkit and then with
  2805. 1:53:42the help of Agents I will be able to
  2806. 1:53:44execute any Q&A search that I really
  2807. 1:53:46want to do it yes I have probably told a
  2808. 1:53:49lot of terms and topics over here but
  2809. 1:53:51let's go ahead and let's see how we can
  2810. 1:53:52can actually implement it and all this
  2811. 1:53:54implementation that you will probably be
  2812. 1:53:56seeing will be quite amazing lot of
  2813. 1:53:58learnings will be specifically there and
  2814. 1:54:00you will definitely be able to learn
  2815. 1:54:02many things out of it okay so let me
  2816. 1:54:04quickly go ahead and open my uh code
  2817. 1:54:08file and I will continue the same code
  2818. 1:54:09file that I had actually implemented
  2819. 1:54:11earlier itself right uh one more very
  2820. 1:54:14important thing that I really want to
  2821. 1:54:15talk about is that uh if you remember I
  2822. 1:54:17have uploaded five videos till now and
  2823. 1:54:20all those videos are with respect to
  2824. 1:54:21some different different applications
  2825. 1:54:23right and that is how we should
  2826. 1:54:25definitely learn all these topics so
  2827. 1:54:27that we can actually get an efficient
  2828. 1:54:28way of how things are basically getting
  2829. 1:54:30used okay so as usual what I'm actually
  2830. 1:54:33going to do is that let me go ahead and
  2831. 1:54:35search for Lang chain tools okay so here
  2832. 1:54:38you you if you able to see here you have
  2833. 1:54:41something called as Lang chain tools so
  2834. 1:54:43tools are interfaces that an agent chain
  2835. 1:54:46or llm can interact with the world right
  2836. 1:54:48so if I really want data from some other
  2837. 1:54:50data sources uh some other queries that
  2838. 1:54:53I have you can also include Google
  2839. 1:54:54search API over here and lot of tools
  2840. 1:54:56are specifically given by uh lanin
  2841. 1:54:58itself you know we have to really create
  2842. 1:55:00a rapper and then we will be able to
  2843. 1:55:02have a conversation with them so some of
  2844. 1:55:04the examples with respect to the tool
  2845. 1:55:05like what all tools are specifically
  2846. 1:55:07provided you'll be able to see in langin
  2847. 1:55:10these are all the built-in tools that
  2848. 1:55:11you have Alpha Vantage fi R sa AWS
  2849. 1:55:15Lambda Bing search Brave search Chat GPD
  2850. 1:55:19plugins you know D image generator you
  2851. 1:55:21can also able to generate images then
  2852. 1:55:23you have Eden AI file system golden
  2853. 1:55:25query Google Finance Google jobs Google
  2854. 1:55:28Lens Google Places Google scholer Google
  2855. 1:55:31search Google serer so you can probably
  2856. 1:55:33use any of these particular tools to
  2857. 1:55:35extract some of the data that you want
  2858. 1:55:37let's say that I am planning to create a
  2859. 1:55:40chatbot which will be research more
  2860. 1:55:42oriented and I will probably ask
  2861. 1:55:43questions that will be related to
  2862. 1:55:45different topics research and all other
  2863. 1:55:47than that I will also try to create a
  2864. 1:55:49rapper on top of Wikipedia and along
  2865. 1:55:51with that my under the customized uh PDF
  2866. 1:55:54files okay so I will try to include all
  2867. 1:55:56those thing and you can use any of this
  2868. 1:55:58that you want based on your use cases
  2869. 1:56:00but I will try to show you an
  2870. 1:56:02application how I will go ahead with
  2871. 1:56:04okay so let me quickly open a new folder
  2872. 1:56:06over here so I will go ahead and create
  2873. 1:56:08a folder and let me go ahead and write
  2874. 1:56:10agents over here as my folder name and I
  2875. 1:56:13am going to create a file which is
  2876. 1:56:15called as agents. iynb file okay now
  2877. 1:56:19inside this particular file I will go
  2878. 1:56:21ahead and select my step by step I will
  2879. 1:56:23try to show it to you how things will be
  2880. 1:56:25working in this and how I'm going to
  2881. 1:56:27build this entire thing okay so the
  2882. 1:56:29first thing as usual uh as I said that I
  2883. 1:56:31will be requiring uh RF so you have to
  2884. 1:56:34probably go ahead and install this so I
  2885. 1:56:37will go ahead and write pip install RF
  2886. 1:56:39so okay dou S no worries so I will go
  2887. 1:56:42ahead and install it it'll go it'll get
  2888. 1:56:44installed in my V EnV environment once
  2889. 1:56:47this is basically getting installed what
  2890. 1:56:48I'm going to do is that I'm going to use
  2891. 1:56:50Wikipedia I'm going to use also and I'll
  2892. 1:56:53create as a rapper okay so first of all
  2893. 1:56:55let's go ahead and create a rapper on
  2894. 1:56:57top of Wikipedia so for that what I will
  2895. 1:56:59do I will go ahead and write from Lang
  2896. 1:57:01chain uh Lang chain undor community so
  2897. 1:57:05it will be present inside this community
  2898. 1:57:07itself all the tools that are available
  2899. 1:57:09uh within the Lang chain itself then I'm
  2900. 1:57:12going to import
  2901. 1:57:14Wikipedia
  2902. 1:57:16Wikipedia query run okay so I'm going to
  2903. 1:57:20just write Wikipedia query run I hope
  2904. 1:57:22this works let's see whether this works
  2905. 1:57:24or not okay this is my Lang chore
  2906. 1:57:27Community but I think it should be
  2907. 1:57:29working now um from lin. community.
  2908. 1:57:31tools import Wikipedia or query run
  2909. 1:57:35along with this what I'm going to write
  2910. 1:57:36from langin I'm also going to create a
  2911. 1:57:39use some rapper class on top of it do
  2912. 1:57:43utilities utilities
  2913. 1:57:46import
  2914. 1:57:48Wikipedia API rapper okay so I'm going
  2915. 1:57:51to specific Al use this two things over
  2916. 1:57:53here one is the Wikipedia query run and
  2917. 1:57:55Wikipedia API rapper okay for Wikipedia
  2918. 1:57:58you don't require a separate API itself
  2919. 1:58:00already Lang chain is taking care of
  2920. 1:58:02that so if I go ahead and write uh and
  2921. 1:58:04probably execute this Wikipedia API
  2922. 1:58:07wrapper I will say hey provide me the
  2923. 1:58:09top K results right so how many results
  2924. 1:58:11I want let's say I want one so I'll go
  2925. 1:58:14ahead and write document uh content Car
  2926. 1:58:16Max Max to Max I will probably require
  2927. 1:58:19200 characters okay from whatever search
  2928. 1:58:21I actually do from Wikipedia you can
  2929. 1:58:23increase it so this will basically be my
  2930. 1:58:25wrapper itself API wrapper okay so this
  2931. 1:58:28in short is interacting with the
  2932. 1:58:30Wikipedia to find out the so many number
  2933. 1:58:32of results so this is basically giving
  2934. 1:58:33some configuration details over here the
  2935. 1:58:36next will be my tool as I said I will be
  2936. 1:58:38using my Wikipedia query run tool okay
  2937. 1:58:42and then this will be initialized and
  2938. 1:58:43here I'm going to initialize my API
  2939. 1:58:45wrapper with the API rapper that I've
  2940. 1:58:48defined over here okay so this is what
  2941. 1:58:50is my tool over here so I'm getting some
  2942. 1:58:53error could not import Wikipedia python
  2943. 1:58:55package please install it with Pip
  2944. 1:58:57install Wikipedia so I will go over here
  2945. 1:59:00and requirement. txt I will go ahead and
  2946. 1:59:03write Wikipedia okay I will be requiring
  2947. 1:59:05this Library along with this as I said
  2948. 1:59:08I'm going to import also RF okay so let
  2949. 1:59:11me quickly go ahead and open my terminal
  2950. 1:59:13and I will start the installation over
  2951. 1:59:15here okay so let me go ahead and write P
  2952. 1:59:18install minus r requirement. txt so both
  2953. 1:59:22these libraries will get installed that
  2954. 1:59:23I specifically want initially you
  2955. 1:59:25actually require it whatever is there
  2956. 1:59:28the packages are available and Lang
  2957. 1:59:29chist trying to integrate with that and
  2958. 1:59:31that is the most amazing thing over here
  2959. 1:59:33okay so now I don't think so we should
  2960. 1:59:34be getting an error so now it looks good
  2961. 1:59:37now if you go and write tools over here
  2962. 1:59:39or tool tool name over here so here you
  2963. 1:59:42can see Wikipedia query run if I go
  2964. 1:59:44ahead and write tool. name you'll be
  2965. 1:59:46able to see Wikipedia is my uh tool name
  2966. 1:59:48okay now this is one of the tool
  2967. 1:59:51similarly what I I will uh probably do
  2968. 1:59:53is that I will also uh take a website or
  2969. 1:59:57a PDF whatever it is right I will read
  2970. 2:00:01all those kind of PDF okay so that I
  2971. 2:00:03will also consider that as a data source
  2972. 2:00:05so let me do one thing let me I will
  2973. 2:00:08probably create another tool over here
  2974. 2:00:09okay so let's see over here I will go
  2975. 2:00:12ahead and go to this website okay so let
  2976. 2:00:16me just see this website uh I've just
  2977. 2:00:19copied this okay so this website this
  2978. 2:00:23website okay so this is the website that
  2979. 2:00:26I will also be using and I'll try to
  2980. 2:00:27retrieve the content from here also so
  2981. 2:00:30in order to read this content from this
  2982. 2:00:32particular website I will be using
  2983. 2:00:33web-based loader as you all know we have
  2984. 2:00:36also discussed about that because that
  2985. 2:00:37is also one of the data injection thing
  2986. 2:00:39right so I will write from Lang chain
  2987. 2:00:43community. document loaders and here I'm
  2988. 2:00:46going to specifically import web based
  2989. 2:00:49webbased loader okay along with this uh
  2990. 2:00:52as you all know since I'm reading the
  2991. 2:00:53content I will be using F I'll be using
  2992. 2:00:55open AI Bings and all so let me copy it
  2993. 2:00:58from here and let me paste it over here
  2994. 2:01:00okay so I'll be using F I'll be using
  2995. 2:01:02open a Bings I'll be using recursive uh
  2996. 2:01:05character text splitter so that I'll be
  2997. 2:01:07able to divide all those into chunks
  2998. 2:01:09also so everything will be used over
  2999. 2:01:11here in this particular case and one
  3000. 2:01:13thing that you really need to understand
  3001. 2:01:15why we are doing this because this is my
  3002. 2:01:17own custom data let's consider this as
  3003. 2:01:19my own custom data I need to probably
  3004. 2:01:21convert this into a vectors so here I
  3005. 2:01:23will go ahead and load my loader and
  3006. 2:01:26here I will be using webbased loader and
  3007. 2:01:28I will give my URL the URL that I had
  3008. 2:01:30actually got from here so this URL will
  3009. 2:01:34be basically reading the entire page
  3010. 2:01:36okay once I probably get the loader.
  3011. 2:01:39load okay uh loader. load it will load
  3012. 2:01:43the entire content from that particular
  3013. 2:01:44website so this will be my docs okay
  3014. 2:01:48after getting the docs the next thing
  3015. 2:01:50that I will do is my recursive character
  3016. 2:01:52split okay and here I'm going to
  3017. 2:01:55specifically use some Chun size so this
  3018. 2:01:58will basically be my chunk underscore
  3019. 2:02:01chunk uncore size is equal to
  3020. 2:02:05th000 uh and then I will also be writing
  3021. 2:02:08chunk uncore overlap which will be
  3022. 2:02:10nothing but 200 okay so this is some
  3023. 2:02:12default configuration I have actually
  3024. 2:02:14taken in this um and then uh I will also
  3025. 2:02:18write do splitcore documents I will
  3026. 2:02:21split all all these documents that are
  3027. 2:02:22available inside this docs okay and I
  3028. 2:02:26will finally get my documents itself
  3029. 2:02:29okay and this we have already done it
  3030. 2:02:31many number of times I think in my
  3031. 2:02:32previous tutorial also then I will go
  3032. 2:02:34ahead and create my DB my Vector DB so I
  3033. 2:02:37will go ahead and write Vector DB Vector
  3034. 2:02:40DB and here I'm going to specifically
  3035. 2:02:43write
  3036. 2:02:44F FES do from
  3037. 2:02:48documents from documents and and here
  3038. 2:02:52I'm going to give my
  3039. 2:02:54documents comma my openings that I'm
  3040. 2:02:58specifically going to use for this
  3041. 2:02:59purpose right and later on if I really
  3042. 2:03:01want to convert this Vector database
  3043. 2:03:03into retriever all I have to write is
  3044. 2:03:05Vector DB do as
  3045. 2:03:09retriever as retriever if you don't know
  3046. 2:03:13what is retriever it is an interface
  3047. 2:03:15which will be able to retrieve the
  3048. 2:03:17result from this particular Vector
  3049. 2:03:18database right so here will be my
  3050. 2:03:21retriever right so this is my second
  3051. 2:03:23important thing so let me go ahead and
  3052. 2:03:25write
  3053. 2:03:28retriever retriever okay so I've done
  3054. 2:03:31I've created one tool I've created one
  3055. 2:03:33retriever tool is for Wikipedia but
  3056. 2:03:36still I have I also installed RV right
  3057. 2:03:38so I'm also going to use RV for the same
  3058. 2:03:40purpose first let's uh all this
  3059. 2:03:43particular thing happen now you have
  3060. 2:03:44that Victor um the vector store
  3061. 2:03:47retriever completely over here okay now
  3062. 2:03:50uh the next thing uh that I am probably
  3063. 2:03:53going to do over here is that I will
  3064. 2:03:55take this Retriever and use create
  3065. 2:03:56retriever tool so that I can actually
  3066. 2:03:59make it as a uh as a as a in short like
  3067. 2:04:02if I really want to ask any question I
  3068. 2:04:04really need to make this retriever as a
  3069. 2:04:06create retriever tool okay so if you go
  3070. 2:04:09ahead and search for Lang
  3071. 2:04:11chain for Lang chain create
  3072. 2:04:15retrieval create retriever tool okay so
  3073. 2:04:20here you'll be able to see that this is
  3074. 2:04:22what we are going to specifically use
  3075. 2:04:24and create retriever tool you can see
  3076. 2:04:26create a tool to do retrieval of all the
  3077. 2:04:28documents so we are going to
  3078. 2:04:29specifically use this other than this if
  3079. 2:04:31you can definitely check out all the
  3080. 2:04:34agents that are probably available over
  3081. 2:04:35here for that purpose right and by that
  3082. 2:04:38you will be able to implement things so
  3083. 2:04:40here what I'm going to do I'm going to
  3084. 2:04:41create my retriever uh tool itself so I
  3085. 2:04:44will write from Lang
  3086. 2:04:47chain dot tools Dot
  3087. 2:04:53retriever
  3088. 2:04:55import create retriever tool I will
  3089. 2:04:57initialize this create retriever tool
  3090. 2:05:00and here I'm going to
  3091. 2:05:01use retriever is equal to or whatever
  3092. 2:05:05retriever name I have and then this will
  3093. 2:05:07basically be my lsmith search right so
  3094. 2:05:11because that is with respect to the
  3095. 2:05:12lsmith page okay L smithore search okay
  3096. 2:05:17so that it'll be able to get
  3097. 2:05:20identified okay like which which tool
  3098. 2:05:23I'm basically hitting or which tool I'm
  3099. 2:05:25basically searching okay and here I will
  3100. 2:05:27give my third parameter and I will say
  3101. 2:05:29hey search for information about
  3102. 2:05:33lsmith I'll just copy and paste it I've
  3103. 2:05:35already done this in one of my project
  3104. 2:05:38so so here you can see the third
  3105. 2:05:40parameter that I'm giving in the create
  3106. 2:05:41retrieval tool is just like a prompt
  3107. 2:05:43like what I really want this tool to do
  3108. 2:05:46search for Information Gain about lsmith
  3109. 2:05:48for any question about lsmith you must
  3110. 2:05:49use this tool so in short when I do this
  3111. 2:05:52Creator retrieval tool right it is
  3112. 2:05:54basically creating a tool uh to do the
  3113. 2:05:57search for that particular page right so
  3114. 2:06:00here I'm going to write retrieval uncore
  3115. 2:06:03tool okay and this will get initialized
  3116. 2:06:05right so I have got one tool over here
  3117. 2:06:08one tool is Wikipedia and the other tool
  3118. 2:06:11if you go and see this retriever tool.
  3119. 2:06:14name this is nothing but lsmith search
  3120. 2:06:16now the third retrieval tool that I'm
  3121. 2:06:18actually going to create uh is
  3122. 2:06:20specifically my my own uh RI platform
  3123. 2:06:24that I have actually developed so for
  3124. 2:06:25this also I will be having one rapper
  3125. 2:06:28and one query Run Okay so this will
  3126. 2:06:30basically be for my Rift Rift basically
  3127. 2:06:32means the website where all the research
  3128. 2:06:34papers have been uploaded okay so let's
  3129. 2:06:38create one more tool so this is for this
  3130. 2:06:39particular tool okay and again the same
  3131. 2:06:42thing that we will try to do is that we
  3132. 2:06:44have to create a rapper API rapper Rift
  3133. 2:06:47rapper where again my document Max
  3134. 2:06:49search will be 200 and this will be B
  3135. 2:06:51basically my for my query run and here
  3136. 2:06:53I'm actually going to get my ri. name
  3137. 2:06:56and here you'll be able to see that this
  3138. 2:06:58is my tool right so this is inbuilt tool
  3139. 2:07:04that is also provided by Lang chain
  3140. 2:07:06Wikipedia and R is provided by Lang
  3141. 2:07:09chain if you really want to create your
  3142. 2:07:10own custom tool then you can also create
  3143. 2:07:12like this but like I have actually shown
  3144. 2:07:14you right at the end of the day you
  3145. 2:07:16combine all these particular tools so
  3146. 2:07:17let me go ahead and combine it so I will
  3147. 2:07:19write uh tools is equal to and let's go
  3148. 2:07:23ahead and combine this so the first tool
  3149. 2:07:25that I have I think it is name is tool
  3150. 2:07:28only okay so I at written tool so let me
  3151. 2:07:31go ahead and write wiki wiki over here
  3152. 2:07:33Wiki okay wiki wiki okay so here I'm
  3153. 2:07:36going to combine all these things so
  3154. 2:07:38first one is Wiki the second one is my
  3155. 2:07:41ARF and the third one is my lsmith okay
  3156. 2:07:46so Lang Smith uh this is nothing but it
  3157. 2:07:49is a retrieval tool name right so I'm
  3158. 2:07:51going to basically combine all this
  3159. 2:07:53tools so finally I got my entire tools
  3160. 2:07:56over here so this tools is nothing but
  3161. 2:07:57it is a list of all the tools that you
  3162. 2:08:00can see over here with respect to this
  3163. 2:08:02now my next aim is basically to query
  3164. 2:08:07from this specific tools right so for
  3165. 2:08:09this I can do it in multiple ways uh and
  3166. 2:08:12that is where we will be specifically
  3167. 2:08:14using agents okay so let me just go
  3168. 2:08:18ahead and tell you what is the main
  3169. 2:08:20purpose of agent agents agents will be
  3170. 2:08:23responsible in probably see if I go
  3171. 2:08:26ahead and show you the documentation
  3172. 2:08:28also let me go ahead and show you the
  3173. 2:08:32documentation agents the core idea of
  3174. 2:08:34the agent is use to Lang is to use a
  3175. 2:08:37language model to choose a sequence of
  3176. 2:08:39action to take in change the sequence of
  3177. 2:08:41action is hardcoded in code in agent a
  3178. 2:08:43language model is used as a reasoning
  3179. 2:08:45engineering to determine uh which
  3180. 2:08:47actions should take place in which order
  3181. 2:08:49right now here you can see that I have
  3182. 2:08:51have given one two three tool in that
  3183. 2:08:53specific order so what my agent will
  3184. 2:08:56basically do is that it will whenever I
  3185. 2:08:58perform any request right whenever I
  3186. 2:09:00give any input to my llm model it is
  3187. 2:09:02first of all going to first search in
  3188. 2:09:04Wiki if it is not able to get in from
  3189. 2:09:06this particular tool it is going to go
  3190. 2:09:07to Rift then it is going to go to
  3191. 2:09:08retrieval tool right so from these three
  3192. 2:09:11tools it is going to get the query and
  3193. 2:09:12it is going to provide you the response
  3194. 2:09:14okay so let me quickly go ahead and
  3195. 2:09:16write from Lang
  3196. 2:09:18chain. agents I'm going to import
  3197. 2:09:22create create open AI tool agent and
  3198. 2:09:25here I'm going to Define my agent name
  3199. 2:09:27and let me go ahead and write create
  3200. 2:09:29open AI tools agent name and here I'm
  3201. 2:09:31going to give my
  3202. 2:09:33llm my tools that I've actually created
  3203. 2:09:36and one will be my prompt okay so the
  3204. 2:09:38prompt and Tool have not yet defined so
  3205. 2:09:41uh what I will do here I will show you
  3206. 2:09:43an example like how you can probably
  3207. 2:09:46call your prompts also that is already
  3208. 2:09:49available in langen Hub but before that
  3209. 2:09:51let me go ahead and call my open AI API
  3210. 2:09:53so quickly I will go ahead and call it
  3211. 2:09:56and then this is what I'm initializing
  3212. 2:09:58my llm models as okay so I have actually
  3213. 2:10:01created chat open API so this is what
  3214. 2:10:03I'm actually going to use okay now let
  3215. 2:10:05me go uh so this is my llm model the
  3216. 2:10:07next thing is that how can I probably
  3217. 2:10:09create a prompt one way that I've
  3218. 2:10:12already showed you of creating a prompt
  3219. 2:10:14is just by using chat promp template but
  3220. 2:10:17in langin there is a module called as
  3221. 2:10:19Hub there people have already created or
  3222. 2:10:21L chain has already created some amazing
  3223. 2:10:23prompts generic prompts and they have
  3224. 2:10:24uploaded over there so in order to call
  3225. 2:10:26from there so I will write from Lang
  3226. 2:10:28chain uh from Lang chain import Hub okay
  3227. 2:10:35and then we are going to Prem uh give
  3228. 2:10:37the prompt we are going to get the
  3229. 2:10:38prompt and the prompt will be of this
  3230. 2:10:40name okay so we'll also see see get the
  3231. 2:10:42prompt to use and you can modify this so
  3232. 2:10:44there is a something called as open a
  3233. 2:10:46function agents uh and this is the
  3234. 2:10:49username that is present in langen hub
  3235. 2:10:51if I go ahead and see what is the prompt
  3236. 2:10:52over here so I'm getting an error let's
  3237. 2:10:54see please install lanin Hub okay so we
  3238. 2:10:57also require lanin Hub uh in order to
  3239. 2:11:00use this see the reason why I'm showing
  3240. 2:11:02you all this things because so many
  3241. 2:11:04different options are there lanch Hub
  3242. 2:11:07okay so let me quickly go ahead and run
  3243. 2:11:11in the terminal pip install requirement.
  3244. 2:11:15txt Okay so this I will probably Lang
  3245. 2:11:18chain Lang chenore Hub let me see the
  3246. 2:11:20error
  3247. 2:11:22what was the error over
  3248. 2:11:24there okay it should be something like
  3249. 2:11:28this okay so I will go ahead and write
  3250. 2:11:32or see in the requirement. txt the name
  3251. 2:11:35is different now let me quickly go ahead
  3252. 2:11:37and write it down over and install
  3253. 2:11:40it right so here you can probably see
  3254. 2:11:45yes the installation is done my agents
  3255. 2:11:47is ready now let me go ahead and execute
  3256. 2:11:49this now I think you should be able to
  3257. 2:11:50see the m
  3258. 2:11:51messages okay now you'll be able to see
  3259. 2:11:54the messages over here now see by
  3260. 2:11:56default whatever prompt is available in
  3261. 2:11:58open aai function agents you'll be able
  3262. 2:12:00to see I have system message prompt
  3263. 2:12:02template there's prompt variable the
  3264. 2:12:04input variable is there in template you
  3265. 2:12:06are a helpful assistant so what we used
  3266. 2:12:07to do manually everything is available
  3267. 2:12:09over here the same thing it will have
  3268. 2:12:11one human message one system message
  3269. 2:12:14prompt template one human message prompt
  3270. 2:12:15template right now uh you have the
  3271. 2:12:17prompt you have everything now we can go
  3272. 2:12:19ahead and create my AI tool agents once
  3273. 2:12:22I probably create my open a tool agents
  3274. 2:12:25now you can probably use this agent and
  3275. 2:12:28execute to Pro get any kind of response
  3276. 2:12:30now in order to use this particular
  3277. 2:12:32agents we have to use something called
  3278. 2:12:34as agent
  3279. 2:12:35executor okay agent executor please
  3280. 2:12:40understand the flow the flow is
  3281. 2:12:41important and that is how you'll be able
  3282. 2:12:44to understand this so from Lang
  3283. 2:12:47chain. agents import
  3284. 2:12:53agent executor okay so agent executor is
  3285. 2:12:58my next I that I'm going to specifically
  3286. 2:13:01use and I'll use this agent executor
  3287. 2:13:04here I'm going to use my agent is equal
  3288. 2:13:05to agent along with that I will use my
  3289. 2:13:08tools is equal to tools okay whatever
  3290. 2:13:11tools I've given and then this verbos
  3291. 2:13:13will be true so that I'll be able to see
  3292. 2:13:15all the details whenever I get any
  3293. 2:13:16response and this will basically be my
  3294. 2:13:19agent executor so this is basically
  3295. 2:13:22responsible in executing anything right
  3296. 2:13:25so now if I go and see my agent executor
  3297. 2:13:28so here you can see all the things and
  3298. 2:13:30it has also added runnable binding
  3299. 2:13:33arguments over here right now in order
  3300. 2:13:36to execute anything see if I write agent
  3301. 2:13:39executor dot
  3302. 2:13:42invoke so once I write invoke and I give
  3303. 2:13:45my
  3304. 2:13:47input and let me give the message tell
  3305. 2:13:50me me
  3306. 2:13:52about
  3307. 2:13:56lsmith now you should just think that
  3308. 2:13:58from where should this input come
  3309. 2:14:00already in our tools we have R platform
  3310. 2:14:03we have lsmith search right and we have
  3311. 2:14:06Wikipedia so obviously this this agent
  3312. 2:14:09will execute and it will interact from
  3313. 2:14:12the tool that is related to lsmith so
  3314. 2:14:15once I execute this here you'll be able
  3315. 2:14:17to see what kind of response I usually
  3316. 2:14:19get Okay so so here you can see tell me
  3317. 2:14:22about lsmith lsmith is a platform for
  3318. 2:14:24building production G application uh llm
  3319. 2:14:27application and here and this is
  3320. 2:14:29probably coming from the tool itself
  3321. 2:14:30right now here uh mostly uh the thing
  3322. 2:14:33that you could not see right you could
  3323. 2:14:35not see over here what exactly the thing
  3324. 2:14:38was the reason was very simple I did not
  3325. 2:14:40write the verbos parameter properly now
  3326. 2:14:42you'll be able to see what details
  3327. 2:14:44you'll be getting see once you write
  3328. 2:14:45verbos equal to true now you'll get all
  3329. 2:14:47the details what it has hit now see
  3330. 2:14:50invoking Langs Smith search right it is
  3331. 2:14:53basically searching the langmi Search
  3332. 2:14:55tool right whatever tool was there right
  3333. 2:14:57let me go ahead and execute once again
  3334. 2:14:59with respect to some different query
  3335. 2:15:01right and here let me write tell me
  3336. 2:15:04about machine learning now I don't know
  3337. 2:15:07from where it will go ahead and execute
  3338. 2:15:08it but let's see whether it'll go with
  3339. 2:15:10Wikipedia or RF okay so agent executor
  3340. 2:15:14enters invoking Wikipedia with machine
  3341. 2:15:16learning see and automatically Wikipedia
  3342. 2:15:19it is probably giving you the entire
  3343. 2:15:20result okay let me also try with
  3344. 2:15:22something like RV uh uh platform so uh I
  3345. 2:15:26have one question with some research
  3346. 2:15:28paper Okay research paper name so let me
  3347. 2:15:31just go ahead and execute what's the
  3348. 2:15:32paper all about the paper number is
  3349. 2:15:35there and in RC will'll be able to find
  3350. 2:15:37out this see now it is invoking the RF
  3351. 2:15:40with query uh this particular tool and
  3352. 2:15:43here you'll be able to get the response
  3353. 2:15:45and that is the reason why I say this
  3354. 2:15:47agent executor tools are probably the
  3355. 2:15:49most important thing whenever you
  3356. 2:15:51probably develop a rag application guys
  3357. 2:15:53we are going to continue the Lang chain
  3358. 2:15:55series and in this video we are going to
  3359. 2:15:57create an amazing endtoend rag project
  3360. 2:16:01uh with the help of Open Source llm
  3361. 2:16:03models and grock inferencing engine an
  3362. 2:16:06amazing project Al together over here
  3363. 2:16:08I'm going to show you many more things
  3364. 2:16:10and the best part is that many of you
  3365. 2:16:12were specifically requesting only for
  3366. 2:16:14open source llm models so here I will
  3367. 2:16:16try to show you from embedding to using
  3368. 2:16:18all the open source llm models along
  3369. 2:16:20with with that what exactly is Gro
  3370. 2:16:22inferencing engine we'll also discuss
  3371. 2:16:24about it so here is the gro inferencing
  3372. 2:16:26engine if you don't know about Gro it is
  3373. 2:16:28on a mission to St the standard for Gen
  3374. 2:16:29AI inferencing speed right and it
  3375. 2:16:33specifically uses something called as
  3376. 2:16:34lpu language processing unit okay it is
  3377. 2:16:38a new type of end to-end processing unit
  3378. 2:16:40system that provides the fastest
  3379. 2:16:42inference for computationally intensive
  3380. 2:16:44application with is with a sequential
  3381. 2:16:46component to them why it is so much
  3382. 2:16:48faster than GPU because it solves two
  3383. 2:16:49llm bottleneck one is compute density
  3384. 2:16:52and memory bandwidth I've already
  3385. 2:16:54created a detailed video before and
  3386. 2:16:56spoken more about what exactly is LP
  3387. 2:16:59inferencing engine but now it's time
  3388. 2:17:01that we go ahead and Implement some
  3389. 2:17:02amazing Solutions out here right so let
  3390. 2:17:04me go ahead and let me implement this
  3391. 2:17:07end to end project and this project uh
  3392. 2:17:09here I'm going to probably use streamlet
  3393. 2:17:12over here so that you can actually see
  3394. 2:17:13it in the form of uh web application so
  3395. 2:17:16first of all as usual what I will do is
  3396. 2:17:18that I will go ahead and uh see in the
  3397. 2:17:20requirement. txt here you can see grock
  3398. 2:17:22is also available and along with that
  3399. 2:17:24we'll also be using langin grock so both
  3400. 2:17:27this is the most important part along
  3401. 2:17:29with that bs4 beautiful sou for so that
  3402. 2:17:31we'll be also able to scrap from a
  3403. 2:17:33website so that is what I'm actually
  3404. 2:17:35going to do in my project so here you
  3405. 2:17:36can see in grock I will create one
  3406. 2:17:38folder that is called as or one file
  3407. 2:17:40that is called as app.py Now quickly let
  3408. 2:17:43me go ahead and start the coding over
  3409. 2:17:44here first thing first uh I will first
  3410. 2:17:47of all go ahead and import all the
  3411. 2:17:48important libraries like import
  3412. 2:17:50streamlink
  3413. 2:17:51as St along with that along with
  3414. 2:17:53streamlet I'm also going to go ahead and
  3415. 2:17:55import OS okay now uh the first thing
  3416. 2:17:58that you actually require is the API
  3417. 2:18:00access so click on the API access of Gro
  3418. 2:18:03and you will be able to access it
  3419. 2:18:04completely for free so once you go to
  3420. 2:18:07this API access page you'll be able to
  3421. 2:18:09see that there is a something called as
  3422. 2:18:10uh Self Serve through playground on
  3423. 2:18:12grock so Gro Cloud also gives you a
  3424. 2:18:14playground along with this if you really
  3425. 2:18:16want to use it for a commercial purpose
  3426. 2:18:18then you can see currently uh Lama 270b
  3427. 2:18:21that is 70 billion parameter gives you
  3428. 2:18:234096 context length and uh the response
  3429. 2:18:27that you'll be probably getting is 300
  3430. 2:18:28tokens per second this is quite fast
  3431. 2:18:30when compared to open AI CH GPT
  3432. 2:18:33specifically uh and the price per 1
  3433. 2:18:36million toker is somewhere around
  3434. 2:18:391.7.8 uh similarly Lama 27b you can see
  3435. 2:18:42750 tokens per second then Mistral is
  3436. 2:18:44there 480 tokens per second gamma 7B
  3437. 2:18:47which is basically having 8K Contex L
  3438. 2:18:49and this is somewhere around 32 get
  3439. 2:18:51context L right 820 tokens per second
  3440. 2:18:53and the price is also very much minimal
  3441. 2:18:55so uh as usual see you can see doc has
  3442. 2:18:58also demonstrated 15 times faster llm
  3443. 2:19:00influencing performance on an artificial
  3444. 2:19:02intelligence. leaderboard compared to
  3445. 2:19:04the top cloud-based providers so this is
  3446. 2:19:06awesome and you should definitely know
  3447. 2:19:08this so in order to create the API I
  3448. 2:19:10will go ahead and click on the
  3449. 2:19:11playground on Gro uh once you go over
  3450. 2:19:14here you here you'll be able to see the
  3451. 2:19:15button of apis so just go ahead and
  3452. 2:19:17click on create API give the API name
  3453. 2:19:19and just click on sub submit once you do
  3454. 2:19:21that you'll be getting an API name
  3455. 2:19:23itself right and this API this secret
  3456. 2:19:25key only I will be specifically using in
  3457. 2:19:27my environment variable so uh I'll show
  3458. 2:19:29you step by step already I have created
  3459. 2:19:31those kind of API key so please make
  3460. 2:19:34sure that you also update your
  3461. 2:19:35environment variable I'll tell you with
  3462. 2:19:37what name you really need to update
  3463. 2:19:38right now here we have done this now
  3464. 2:19:40since we are going to use this grock
  3465. 2:19:42with Chad grock itself and that is
  3466. 2:19:44already present in Lang chin right so
  3467. 2:19:46here what I'm actually going to do I'm
  3468. 2:19:48going to write it from Lang chin
  3469. 2:19:51underscore sorry underscore
  3470. 2:19:54grock import chat grock okay chat grock
  3471. 2:19:59so this is the uh chat oh here I have
  3472. 2:20:02made a spelling mistake Lang chain Lang
  3473. 2:20:06chain Gro okay import Chad Gro so Chad
  3474. 2:20:09grock is like how we use Chad API
  3475. 2:20:11similarly Chad Gro is also there for
  3476. 2:20:13this purpose as you all know that I'm
  3477. 2:20:15going to probably take a website and
  3478. 2:20:17read all my content from that specific
  3479. 2:20:18website itself right so here what I'm
  3480. 2:20:20going to do is then again from Lang
  3481. 2:20:22chenore Community I'm going to use
  3482. 2:20:25webbased loader again uh from Lang
  3483. 2:20:27chenore Community uh then I'm going to
  3484. 2:20:29use document loaders as you know this is
  3485. 2:20:31the First Data injection technique that
  3486. 2:20:33we can actually use import we web
  3487. 2:20:38base web
  3488. 2:20:40Bas documentor loaders webbase
  3489. 2:20:44loader web base load okay so I will
  3490. 2:20:48specifically use this particular langore
  3491. 2:20:50community do documentor loader is import
  3492. 2:20:52webbased loader along with this what I'm
  3493. 2:20:55actually going to do as I said I'm going
  3494. 2:20:56to only use open source models so first
  3495. 2:20:58of all uh let's uh go ahead and do this
  3496. 2:21:01and I'm going to use Lang chain and one
  3497. 2:21:04of the embedding technique that I'm
  3498. 2:21:05specifically going to use uh is AMA
  3499. 2:21:08embedding because it is completely for
  3500. 2:21:09free it is an open source itself so
  3501. 2:21:11langore community. embeddings uh import
  3502. 2:21:16AMA embedding so here you don't even
  3503. 2:21:18have to worry about anything about open
  3504. 2:21:20AIS right so embeddings I'm going to use
  3505. 2:21:23it over here um uh along with this what
  3506. 2:21:26we can do is that since we are going to
  3507. 2:21:27read the entire document and convert
  3508. 2:21:29that into smaller chunks so for that I
  3509. 2:21:31will be using recursive character
  3510. 2:21:32splitter so again from L chain under
  3511. 2:21:37dot L chin dot again I'm seeing the
  3512. 2:21:40documentation guys so I need to know
  3513. 2:21:42where this library is actually present
  3514. 2:21:44uh the recursive character text spitter
  3515. 2:21:46so from Lang chain um I will be using
  3516. 2:21:49dot text splitters
  3517. 2:21:51tox text plater and here I'm going to
  3518. 2:21:53import recursive character text plater
  3519. 2:21:56okay so this is another library that I'm
  3520. 2:21:58going to specifically use for this
  3521. 2:21:59purpose and as you know that I've
  3522. 2:22:01already shown you how to use create
  3523. 2:22:03stuff document chain so for that also I
  3524. 2:22:05will be using from Lang
  3525. 2:22:08chain from Lang
  3526. 2:22:11chain. chains. combine documents import
  3527. 2:22:17create stuff document chain okay so this
  3528. 2:22:19is the another library that I'm going we
  3529. 2:22:20going to use um along with this I'll
  3530. 2:22:23create my own custom chat prompt
  3531. 2:22:25template so again from Lang chain dot oh
  3532. 2:22:29sorry underscore code.
  3533. 2:22:32prompts I'm going to
  3534. 2:22:34import okay line
  3535. 2:22:38chain uhor code. UT chat promp template
  3536. 2:22:41okay so chat prompt template I'm going
  3537. 2:22:43to use along with this and as you know
  3538. 2:22:45after creating the document chain I also
  3539. 2:22:46have to create the retrieval chain so
  3540. 2:22:48from L chain
  3541. 2:22:51do
  3542. 2:22:52chains come on here from Lang chain.
  3543. 2:22:57chains okay sometimes all the time when
  3544. 2:23:00I'm writing Lang chin there is a
  3545. 2:23:02spelling mistake come on okay
  3546. 2:23:05import
  3547. 2:23:06create uh create create create create
  3548. 2:23:09retrieval underscore
  3549. 2:23:12r r r i
  3550. 2:23:15Vore chain okay so uh yes one more
  3551. 2:23:20Library with respect to this I'm going
  3552. 2:23:21to use all the specific things for my
  3553. 2:23:24purpose uh and as you all know that I'm
  3554. 2:23:26also going to use one more thing so that
  3555. 2:23:28I'll be able to load all the environment
  3556. 2:23:29variables so from dot EnV import load.
  3557. 2:23:37EnV I'm also going to import OS I I've
  3558. 2:23:40imported OS so load. EnV I'll just load
  3559. 2:23:44this so that all my environment
  3560. 2:23:45variables will loaded and one of the
  3561. 2:23:47environment variable that I'm going to
  3562. 2:23:48specifically use is grock API okay so
  3563. 2:23:51let me load the grock API key okay so
  3564. 2:23:56that whatever I'm specifically running
  3565. 2:23:57I'll be able to use the open source llm
  3566. 2:23:59model from this specific inferencing
  3567. 2:24:01engine so here let me go ahead and write
  3568. 2:24:03grock _ API _ key is equal to os.
  3569. 2:24:08envirn okay and here I'm going to use
  3570. 2:24:12crore API key that basically means
  3571. 2:24:16whatever Gro API key I've have taken I
  3572. 2:24:17have written in my environment variable
  3573. 2:24:19with this key is is equal to whatever my
  3574. 2:24:21API key I've got from that particular
  3575. 2:24:23website okay so you also have to really
  3576. 2:24:25do the same thing okay so whatever key
  3577. 2:24:27you actually get you have to take this
  3578. 2:24:28in the name and you have to probably go
  3579. 2:24:30into environment variable so environment
  3580. 2:24:32variable is somewhere here and just
  3581. 2:24:34assign this with that whatever key name
  3582. 2:24:35because I have created a lot of key over
  3583. 2:24:37there and since we are continuing the
  3584. 2:24:39Lin series I'm going to probably do in
  3585. 2:24:40this specific project itself okay so
  3586. 2:24:43once uh this is done uh here one more
  3587. 2:24:45thing I'm going to specifically use uh
  3588. 2:24:47in streamlit I'm going to use something
  3589. 2:24:49called a session state so all those
  3590. 2:24:50things I'll also be doing with respect
  3591. 2:24:52to this okay and that will also help you
  3592. 2:24:53to understand so here I'm going to write
  3593. 2:24:55if
  3594. 2:24:57Vector not in okay st. session state I'm
  3595. 2:25:03going to create some session States so
  3596. 2:25:05that you'll be able to understand so
  3597. 2:25:06first thing that I'll be creating with
  3598. 2:25:08the session state is nothing but my AMA
  3599. 2:25:10embedding and probably you'll also get
  3600. 2:25:12an idea in this video about many things
  3601. 2:25:14session States and Streamlight and all
  3602. 2:25:16okay so first of all I'm going to create
  3603. 2:25:18my embeddings this embeddings I'm going
  3604. 2:25:20to assigned to my all my embeddings okay
  3605. 2:25:22so this is the first parameter that I'll
  3606. 2:25:23be using then I'll be using session
  3607. 2:25:26loader so session uncore State okay uh
  3608. 2:25:31and along with this do loader so I will
  3609. 2:25:33load some information from my website
  3610. 2:25:36now what website I'm actually going to
  3611. 2:25:38consider let's see uh initially I've
  3612. 2:25:40used some kind of websites over here
  3613. 2:25:42here at least somewhere I've used some
  3614. 2:25:44websites let's pick up any of the
  3615. 2:25:47website over there okay I'll probably
  3616. 2:25:49take previous
  3617. 2:25:50examples um this is done agents is the
  3618. 2:25:53agent let's see what example I've
  3619. 2:25:55actually taken okay let's pick up this
  3620. 2:25:57website okay so I'm going to use
  3621. 2:25:59webbased loader along with this website
  3622. 2:26:01okay so here I'm going to write webbased
  3623. 2:26:03loader and here will be basically my
  3624. 2:26:05website link okay so I'm actually
  3625. 2:26:07reading the content from this website
  3626. 2:26:10okay so let me quickly open it over here
  3627. 2:26:12for you so that you'll be also able to
  3628. 2:26:14see it okay so it's uh doc dos Smith
  3629. 2:26:17chain L Lang chain some information I
  3630. 2:26:20want from here so I will try to pick it
  3631. 2:26:21up from here itself okay so this becomes
  3632. 2:26:23my loader now you know after getting the
  3633. 2:26:25loader what we really need to do is that
  3634. 2:26:27we need to uh uh from this particular
  3635. 2:26:30website we need to get the entire
  3636. 2:26:31documents so I will create another
  3637. 2:26:34session States session uncore State okay
  3638. 2:26:38dot docs and I will say loader dot oops
  3639. 2:26:43not loader it should be this one st.
  3640. 2:26:45session state.
  3641. 2:26:47loader
  3642. 2:26:49do load okay so once I load it uh again
  3643. 2:26:53the same thing whatever we have
  3644. 2:26:54specifically done now after getting the
  3645. 2:26:56docs what we have to do is that we have
  3646. 2:26:57to probably use this st. session State
  3647. 2:27:02now you know what we specifically do
  3648. 2:27:04after that you know we get the final
  3649. 2:27:05documents or chunk documents right so
  3650. 2:27:07I'll write chunk um documents because I
  3651. 2:27:11need to do over here as recursive
  3652. 2:27:13character splitter right so here I'm
  3653. 2:27:15going to use recursive character
  3654. 2:27:16splitter and here inside this recursive
  3655. 2:27:18character splitter I have to probably
  3656. 2:27:20consider this as my docs
  3657. 2:27:23okay oh sorry over here I will probably
  3658. 2:27:26be assigning my or instead of writing
  3659. 2:27:29this chunk underscore documents I will
  3660. 2:27:31write text spitter so this will
  3661. 2:27:32basically be my text spitter here uh I
  3662. 2:27:35will be using chunk chunk uh underscore
  3663. 2:27:39size is equal to 10,000 or th000 th000
  3664. 2:27:43I'll go ah and right chunk undor overlap
  3665. 2:27:46will be somewhere around 200 right so
  3666. 2:27:48this is done uh good we have we have our
  3667. 2:27:52text splitter again that is also saved
  3668. 2:27:55in the session itself now I'm going to
  3669. 2:27:57basically go ahead and write st. session
  3670. 2:28:00uh session uncore State and here I'm
  3671. 2:28:03going to create my final documents final
  3672. 2:28:06documents okay and this final documents
  3673. 2:28:09will be used along with this st. session
  3674. 2:28:13state. textor splitter and here we are
  3675. 2:28:16going to basically uh use do splitcore
  3676. 2:28:19documents
  3677. 2:28:20okay and we are going to probably take
  3678. 2:28:22the documents over here documents is
  3679. 2:28:24nothing but all the documents that is
  3680. 2:28:26available over here along with this we
  3681. 2:28:28going to use the embedding that is
  3682. 2:28:31nothing but uh St do session state do
  3683. 2:28:36embeddings right
  3684. 2:28:38um embeddings I think it should be
  3685. 2:28:42coming up right I think it is the same
  3686. 2:28:45thing St do state. embeddings right so
  3687. 2:28:48this basically becomes your final
  3688. 2:28:50document okay so final documents and
  3689. 2:28:53here you can probably see all the things
  3690. 2:28:54are available right with respect to all
  3691. 2:28:57the uh State session states that are
  3692. 2:28:59basically getting created now the next
  3693. 2:29:01thing uh that I also need to do after
  3694. 2:29:02probably getting the form all the
  3695. 2:29:04documents form then I have to really
  3696. 2:29:06convert that into vectors also and store
  3697. 2:29:08it in a vector store so from Lang chain
  3698. 2:29:11uncore
  3699. 2:29:12community on inside this community I'm
  3700. 2:29:14going to specifically use my Vector
  3701. 2:29:18stores okay so Lang Lang Lang Lang Lang
  3702. 2:29:23Lang all the time c will be coming
  3703. 2:29:25before G so how many of you are also
  3704. 2:29:27doing the same mistake like me okay so
  3705. 2:29:29from this one I'm going to
  3706. 2:29:31import
  3707. 2:29:32F okay now this F uh that I have
  3708. 2:29:36actually initialized again I'm going to
  3709. 2:29:38store it inside my session session unor
  3710. 2:29:41state DOT name it as vectors is equal to
  3711. 2:29:45I'll be using
  3712. 2:29:47F F.T from
  3713. 2:29:51documents and inside this as you know
  3714. 2:29:54that since we are going to use this
  3715. 2:29:55functionality of from documents two
  3716. 2:29:57important things I have to really give
  3717. 2:29:58one is all my documents all my final
  3718. 2:30:00documents so here uh I will give my
  3719. 2:30:03first parameter as final documents over
  3720. 2:30:05here okay and the second uh one that I'm
  3721. 2:30:08specifically going to give is nothing
  3722. 2:30:09but my embeddings right so this will
  3723. 2:30:12specifically be my embeddings
  3724. 2:30:16right done so this is perfect uh here
  3725. 2:30:19you'll be able to see that I'm able to
  3726. 2:30:21see all the documents everything as such
  3727. 2:30:24and uh this is all in short my uh these
  3728. 2:30:27vectors will get created now I can
  3729. 2:30:29probably ask any questions from this
  3730. 2:30:30particular vectors okay but since I
  3731. 2:30:32really need to create this as an end to
  3732. 2:30:33end project so I'm going to use multiple
  3733. 2:30:36things one is st. title okay and here
  3734. 2:30:39I'm going to basically use uh uh
  3735. 2:30:43chat grock chat
  3736. 2:30:47grock demo
  3737. 2:30:50okay chat grock demo now let me go ahead
  3738. 2:30:53and create my llm my llm is nothing but
  3739. 2:30:55chat grock and inside this I'm going to
  3740. 2:30:58specifically take my groor API key which
  3741. 2:31:01will be initialized to my groor API key
  3742. 2:31:04right so whatever grock uncore API key
  3743. 2:31:06I'm actually getting it okay um along
  3744. 2:31:09with this uh the model that I'm going to
  3745. 2:31:10specifically use there multiple models
  3746. 2:31:12as already said over here so let me
  3747. 2:31:15check out what all models are there so
  3748. 2:31:18you have this gamma 7B it right or you
  3749. 2:31:22have this Mistral 87b 32768 so I will
  3750. 2:31:26use gamma 7B it so let me quickly go
  3751. 2:31:29ahead and over here and I'll let me
  3752. 2:31:31write in my name model _ name is equal
  3753. 2:31:34to so gamma I think it is capital letter
  3754. 2:31:37gamma
  3755. 2:31:407B so this will
  3756. 2:31:43be
  3757. 2:31:45gamma
  3758. 2:31:467B it I think I spelling is right right
  3759. 2:31:51uh it's Capital it t is it capital it or
  3760. 2:31:561T okay if it does not work I'll change
  3761. 2:31:58the model name no worries I have three
  3762. 2:32:00other options Capital it okay I think it
  3763. 2:32:03should it should be Capital it okay so
  3764. 2:32:05once this is done uh my Gro my model
  3765. 2:32:07name everything is basically created uh
  3766. 2:32:10then uh this is my llm models now what I
  3767. 2:32:12will do is that I will also go ahead and
  3768. 2:32:15create my prompts so let me go ahead and
  3769. 2:32:17write prompt chat prompt template do
  3770. 2:32:20fromom template so they are also some
  3771. 2:32:22templates that is defined you can also
  3772. 2:32:23create uh chat prom template from
  3773. 2:32:25scratch okay so I will say answer the
  3774. 2:32:34question or so here I'm going to
  3775. 2:32:37basically use some context also
  3776. 2:32:40answer
  3777. 2:32:42the answer the
  3778. 2:32:46questions based on the
  3779. 2:32:50provided
  3780. 2:32:52context context only okay
  3781. 2:32:59um so here I'll write please
  3782. 2:33:03provide provide the most accurate
  3783. 2:33:09response based on
  3784. 2:33:11the based on the context okay so this
  3785. 2:33:14will basically be my thing and uh uh one
  3786. 2:33:18very important thing is that uh I can
  3787. 2:33:20also specify based on
  3788. 2:33:23the based on the question okay now let
  3789. 2:33:26me go ahead and Define my context so
  3790. 2:33:28here I will basically Define my context
  3791. 2:33:30and this will uh this will be ending
  3792. 2:33:33over here so let me go ahead and write
  3793. 2:33:36it so this will basically be my context
  3794. 2:33:38and here I can give my context like this
  3795. 2:33:42now the next thing that I usually give
  3796. 2:33:44is nothing but my question which will be
  3797. 2:33:46my input parameter over here right so
  3798. 2:33:48this will basically be my input okay so
  3799. 2:33:51this becomes my chat prompt template uh
  3800. 2:33:52this is very good now as you know what
  3801. 2:33:55are the next step we have to probably
  3802. 2:33:56use document chain so I will go ahead
  3803. 2:33:58and use document chain over here then I
  3804. 2:34:01will specifically use all the vectors in
  3805. 2:34:03the form of as retrieval right so that
  3806. 2:34:05this is just like an interface to
  3807. 2:34:07probably read all the data context that
  3808. 2:34:09I specifically get from these particular
  3809. 2:34:11vectors now since uh we are using all
  3810. 2:34:13these things right like we are using
  3811. 2:34:15this chart promp template we are using
  3812. 2:34:16some context based information then
  3813. 2:34:18document chain retriever and create
  3814. 2:34:20retrieval chain will also come into
  3815. 2:34:21existence now create retrieval chain
  3816. 2:34:23already I have explained in my previous
  3817. 2:34:25video here I'm going to combine my
  3818. 2:34:26document chain and the retriever so both
  3819. 2:34:29of them will be specifically combined
  3820. 2:34:30and now I will go ahead and probably
  3821. 2:34:33write my prompt prompt will be STD do
  3822. 2:34:37textor input and here I'm going to
  3823. 2:34:39Define
  3824. 2:34:41my input
  3825. 2:34:44your prompt here so guys now next step
  3826. 2:34:48what I can actually do is that uh llm is
  3827. 2:34:50ready my prompt is ready my retrieval
  3828. 2:34:52chain is ready everything is ready now
  3829. 2:34:54uh all I have to do is that I will write
  3830. 2:34:56if prompt okay if the prompt is there uh
  3831. 2:35:00I will go ahead and write my response
  3832. 2:35:02okay and with respect to response I will
  3833. 2:35:04be using this retrieval chain so let me
  3834. 2:35:06go ahead and write retrieval chain do
  3835. 2:35:09invoke okay and whatever input I'm
  3836. 2:35:12specifically giving right with respect
  3837. 2:35:14to this particular input and that should
  3838. 2:35:16be in the form of
  3839. 2:35:18dictionaries okay and here I'm going to
  3840. 2:35:20write
  3841. 2:35:21input
  3842. 2:35:23colon prompt right so done so this is
  3843. 2:35:26also done perfect I'll be able to get
  3844. 2:35:29the response over here now uh it's
  3845. 2:35:31always the best way that uh if I really
  3846. 2:35:34want to get the response right uh I go
  3847. 2:35:36ahead and probably use uh some timer out
  3848. 2:35:39there right so that you'll be able to
  3849. 2:35:41see it like how much time it is probably
  3850. 2:35:43taking so import time I have imported
  3851. 2:35:45time over here now in as soon as
  3852. 2:35:48probably I go ahead and H hit uh The
  3853. 2:35:50Prompt itself right as soon as I press
  3854. 2:35:53enter you know the timer should probably
  3855. 2:35:54start over here so I'll write starter
  3856. 2:35:57time dot uh process time okay so this
  3857. 2:36:01will basically be my process time over
  3858. 2:36:03here and then I will go ahead and write
  3859. 2:36:05print okay or I don't have to print also
  3860. 2:36:09over here nothing okay what time it will
  3861. 2:36:11start and all we can probably do it but
  3862. 2:36:13again I can go ahead and write print
  3863. 2:36:17uh response time time colon okay and
  3864. 2:36:21whatever is the response time I can
  3865. 2:36:23specifically uh do the subtraction over
  3866. 2:36:26here itself right and here uh I can just
  3867. 2:36:29write something like this uh the current
  3868. 2:36:31time that is time do process time okay
  3869. 2:36:35process time minus start or whatever is
  3870. 2:36:39the start time right so I can
  3871. 2:36:41specifically get this and I'll be
  3872. 2:36:42getting the response itself and once I
  3873. 2:36:44get the response I will go ahead and
  3874. 2:36:45write st. write and this will basically
  3875. 2:36:48be my response of answer
  3876. 2:36:52okay whatever answer I'm specifically
  3877. 2:36:54getting okay so yes almost done each and
  3878. 2:36:57everything over here um and I think uh
  3879. 2:37:00we'll be able to get all the things uh
  3880. 2:37:02with respect to this but again it is a
  3881. 2:37:04good idea that uh you know you also try
  3882. 2:37:06to create an expander where you probably
  3883. 2:37:08get all the context also what it is
  3884. 2:37:10basically getting retri so a small four
  3885. 2:37:12to five lines of code that I will be
  3886. 2:37:14adding it over here right with a Strate
  3887. 2:37:17expander you can see I'm taking up all
  3888. 2:37:19the context from that context I'm taking
  3889. 2:37:22the page content and displaying it over
  3890. 2:37:24here right now let's go ahead and run
  3891. 2:37:26this I think it should be working
  3892. 2:37:27absolutely fine uh amazing end project
  3893. 2:37:31where we definitely learn a lot of thing
  3894. 2:37:33and here finally you'll be able to see
  3895. 2:37:35streamlet run
  3896. 2:37:38agents uh sorry app.py right but I think
  3897. 2:37:42it should be running and we'll see the
  3898. 2:37:43speed because the speed will be the most
  3899. 2:37:46important thing so let me go ahead and
  3900. 2:37:47CD CD grock and now same thing I will go
  3901. 2:37:50ahead and write now I feel now the main
  3902. 2:37:53the most excited thing that I will
  3903. 2:37:55probably be excited about this
  3904. 2:37:57application is how quickly I'm able to
  3905. 2:37:58get it so text pl. split documents St
  3906. 2:38:01two position number three were given
  3907. 2:38:02let's
  3908. 2:38:03see this kind of Errors usually comes
  3909. 2:38:06but it's okay recursive
  3910. 2:38:08cator
  3911. 2:38:10uh is it regarding recursive text
  3912. 2:38:14Splitter Splitter
  3913. 2:38:17documents okay where did I give
  3914. 2:38:20three uh splitter documents let me see
  3915. 2:38:23in the documentation uh but again this
  3916. 2:38:26kind of Errors will definitely be coming
  3917. 2:38:28up okay here I don't require embeddings
  3918. 2:38:30okay so one is only required I just saw
  3919. 2:38:33the uh document so that's it okay
  3920. 2:38:36sometime it happens but it's
  3921. 2:38:37okay now probably whatever question I
  3922. 2:38:40asked from here okay let's see I will go
  3923. 2:38:43ahead and ask
  3924. 2:38:45this now I think it should be running
  3925. 2:38:51let's see let's see let's see let's see
  3926. 2:38:53it's stopping b a
  3927. 2:38:55second but there are lot of content from
  3928. 2:38:58here so that is the reason I think it is
  3929. 2:38:59taking so much of time I think for the
  3930. 2:39:01first time for the indexing purpose it
  3931. 2:39:03is probably taking a lot of time let me
  3932. 2:39:05delete this once again um terminal and
  3933. 2:39:08let me do one thing okay let me to just
  3934. 2:39:10improve the performance right I will
  3935. 2:39:13just not take all the documents over
  3936. 2:39:14here I will just take some documents
  3937. 2:39:16okay uh let's probably take the initial
  3938. 2:39:2050 documents that is how I'm going to
  3939. 2:39:22probably do it okay uh initial 50
  3940. 2:39:25documents if we are able to do that much
  3941. 2:39:27I think uh it'll work out um I don't
  3942. 2:39:31want the maximum number of files that
  3943. 2:39:34will probably create me a problem over
  3944. 2:39:36here okay command prompt let's see open
  3945. 2:39:40CD grock okay uh stream late I think
  3946. 2:39:45it'll take some time because I'm saying
  3947. 2:39:48that as soon as the pages get getting
  3948. 2:39:49loaded this needs to be embedded or
  3949. 2:39:51indexed okay so stream late run app.py
  3950. 2:39:55let's see if this works faster uh I will
  3951. 2:39:58not show you the other one then probably
  3952. 2:40:00it'll take some time you know because
  3953. 2:40:01the entire website is basically getting
  3954. 2:40:04indexed and uh let's see how much time
  3955. 2:40:06that vectors will probably get created
  3956. 2:40:08that is how things are basically
  3957. 2:40:09happening over here um because we are
  3958. 2:40:11taking the first 50 documents but I
  3959. 2:40:13hardly see that 100 to 200 documents
  3960. 2:40:15because it's a big website that this
  3961. 2:40:17document. smith. blank chain right so
  3962. 2:40:20you can see this is a big big page and
  3963. 2:40:23there are so many things that is already
  3964. 2:40:24available over here okay let's see how
  3965. 2:40:27things goes ahead and okay uh st.
  3966. 2:40:31session has no attribute Vector did you
  3967. 2:40:32forget to initialize it okay one more
  3968. 2:40:34error one more error error error error
  3969. 2:40:37error okay let me see St vectors Vector
  3970. 2:40:42vectors okay vectors is used over here
  3971. 2:40:44let me see okay
  3972. 2:40:47vectors I understood the error
  3973. 2:40:49it's okay we can understand that
  3974. 2:40:53okay okay now I have again reloaded it
  3975. 2:40:56it is going to take some time hardly I
  3976. 2:40:58think hardly 10 to 15 seconds because it
  3977. 2:41:00is going to Index this entire page and
  3978. 2:41:03for the first time indexing it is it is
  3979. 2:41:05going to take that much time so guys uh
  3980. 2:41:07whenever I'm probably searching things
  3981. 2:41:09right and it is giving me some of the
  3982. 2:41:10document similarity search but uh with
  3983. 2:41:12respect to the summarization from the
  3984. 2:41:13Lang chain it is not coming up I find
  3985. 2:41:16out that one of the reason is that uh
  3986. 2:41:18GMA 7B model you know it has a very less
  3987. 2:41:21context length you know so if I probably
  3988. 2:41:23consider over here uh and probably see
  3989. 2:41:25in the API accs right uh there are
  3990. 2:41:27multiple models that we have
  3991. 2:41:28specifically used right one is uh mr8
  3992. 2:41:31into 7B gamma 7B only 8K context L 32k
  3993. 2:41:34context L let's do one thing let's try
  3994. 2:41:36some other model over here okay the
  3995. 2:41:39mistol model and see whether it will be
  3996. 2:41:41improving the performance or not or
  3997. 2:41:43whether it'll be improving the accuracy
  3998. 2:41:44or not so you should be knowing all
  3999. 2:41:46these things I'm not going to edit any
  4000. 2:41:48part of the video over here so that you
  4001. 2:41:50know you get an idea like how things
  4002. 2:41:52works and here now let me go ahead and
  4003. 2:41:55run this and reload it completely and
  4004. 2:41:59now we will try to see it okay uh how
  4005. 2:42:01the accuracy is but again we going to
  4006. 2:42:03focus over here and see that how things
  4007. 2:42:05are with respect to this right but at
  4008. 2:42:07the end of the day uh it is being able
  4009. 2:42:09to provide this context you know
  4010. 2:42:10whenever I ask any specific question
  4011. 2:42:12based on that context so uh I can just
  4012. 2:42:15ask how to install lsmith how to create
  4013. 2:42:17an API key uh um set how to set up an
  4014. 2:42:20environment something like that okay so
  4015. 2:42:23here how to set up an environment so
  4016. 2:42:27let's go ahead and work it
  4017. 2:42:29out I think it should
  4018. 2:42:32be there okay it should be able to
  4019. 2:42:35probably give me some kind of response
  4020. 2:42:37at least now and again let's see this
  4021. 2:42:39part
  4022. 2:42:42also okay it's working but I think uh
  4023. 2:42:46the document similarity search and
  4024. 2:42:47everything we will be able to see it
  4025. 2:42:50okay and along with that you'll also be
  4026. 2:42:52seeing uh uh many more things right so
  4027. 2:42:55many things that you can probably search
  4028. 2:42:57out of it so let's
  4029. 2:42:59see I think for the indexing purpose
  4030. 2:43:01only it is probably taking time so the
  4031. 2:43:03response time is less see to set up an
  4032. 2:43:06environment this this this all the
  4033. 2:43:08information are specifically over here
  4034. 2:43:10so this looks absolutely amazing
  4035. 2:43:12absolutely good you know and that is how
  4036. 2:43:14you can actually do it and just you can
  4037. 2:43:16imagine like what happens if you
  4038. 2:43:17probably take an open source l m models
  4039. 2:43:19with a higher context length right so
  4040. 2:43:21definitely try it out from your end uh
  4041. 2:43:24again you can ask any questions as such
  4042. 2:43:26uh let's ask one more question uh over
  4043. 2:43:29here um how to create an API key okay
  4044. 2:43:33how to create an API
  4045. 2:43:36key create an API key and if I execute
  4046. 2:43:40it so here you can actually see the
  4047. 2:43:42response is there and to create an API
  4048. 2:43:44in lsmith you can follow the following
  4049. 2:43:46steps all the content that is present in
  4050. 2:43:48the website is shown here you can
  4051. 2:43:49probably see the entire document
  4052. 2:43:50similarity search so guys uh I hope you
  4053. 2:43:54are loving the entire Lang chain series
  4054. 2:43:56we have almost completed almost each and
  4055. 2:43:59every module specifically to langin that
  4056. 2:44:01is actually required to create end to-
  4057. 2:44:03endend projects and we have also
  4058. 2:44:05developed multiple projects over here uh
  4059. 2:44:07we have used both paid and open source
  4060. 2:44:09llm models now one of the most requested
  4061. 2:44:12video was that chish how can we work uh
  4062. 2:44:15considering Lang chin along with hugging
  4063. 2:44:17face libraries and making sure that you
  4064. 2:44:19use only open source llm models and try
  4065. 2:44:22to create some amazing end to end
  4066. 2:44:23project so in this video I'm going to
  4067. 2:44:25use Lang chain having face and open
  4068. 2:44:27source llm models like Mistral that is
  4069. 2:44:28specifically hosted in hugging face and
  4070. 2:44:30then we'll try to develop a Q&A rag
  4071. 2:44:33complete rag app and uh I hope you will
  4072. 2:44:36be liking this particular video please
  4073. 2:44:38make sure that you watch this video till
  4074. 2:44:39the end because there will be a lot of
  4075. 2:44:41learnings that you'll be able to find
  4076. 2:44:43from this particular video too so let me
  4077. 2:44:45quickly go ahead and share my screen so
  4078. 2:44:47here you can actually see I've created a
  4079. 2:44:49fer called as hugging face and there are
  4080. 2:44:51some us sensus data which I probably
  4081. 2:44:53downloaded from the internet in the form
  4082. 2:44:54of PDF and I have uploaded in this
  4083. 2:44:56specific folder right so we will go
  4084. 2:44:59ahead and probably read this again we we
  4085. 2:45:02are going to use completely open source
  4086. 2:45:03llm models like mistol using hugging
  4087. 2:45:05face itself and then we are going to
  4088. 2:45:07create the entire Q&A application so
  4089. 2:45:09let's quickly go ahead and do this and
  4090. 2:45:11initially as you know that initially we
  4091. 2:45:13need to load all the data injection step
  4092. 2:45:15that is loading all the libraries all
  4093. 2:45:18all the PD itself so for that I will be
  4094. 2:45:20importing from Lang
  4095. 2:45:22chain undor Community okay do document
  4096. 2:45:28loaders
  4097. 2:45:31import Pi PDF loader okay so this is one
  4098. 2:45:35of the uh things that I'll be requiring
  4099. 2:45:37then from Lang chain undor Community do
  4100. 2:45:41doent loaders I'm also going to make
  4101. 2:45:43sure that I use a PDF directory also for
  4102. 2:45:45that so here I'm going to import Pi PDF
  4103. 2:45:49directory loader okay and then from
  4104. 2:45:52since I after reading it I need to do
  4105. 2:45:54the character splittings uh divide that
  4106. 2:45:57documents into chunks so for that I'm
  4107. 2:45:59going to use recursive character
  4108. 2:46:00splitter along with this again as we
  4109. 2:46:03know that we'll also use some kind of
  4110. 2:46:05vector store over here so I'm going to
  4111. 2:46:06use the vector store called as F and uh
  4112. 2:46:09as you all know we are also going to use
  4113. 2:46:10hugging face so for hugging face as I
  4114. 2:46:13said all the embedding techniques also
  4115. 2:46:14I'm going to use from hugging face
  4116. 2:46:16itself so for that in Lang chin also you
  4117. 2:46:18have this embedding techniques where you
  4118. 2:46:20have hugging face uh BG embedding which
  4119. 2:46:22is completely an open source and which
  4120. 2:46:24is good enough right so we also going to
  4121. 2:46:26use it um along with this I'm also going
  4122. 2:46:28to import numpy as NP if I specifically
  4123. 2:46:31require numpy I don't think so I will be
  4124. 2:46:33requiring but I'm going to just use this
  4125. 2:46:36okay um two more amazing libraries that
  4126. 2:46:38I'm going to use from L chain since I
  4127. 2:46:41also have to make sure that I create a
  4128. 2:46:42template so from Lang chain. prompts I'm
  4129. 2:46:47going to import
  4130. 2:46:49prompt template okay so this is also
  4131. 2:46:51what is specifically required and one
  4132. 2:46:53more right one more uh chains I will
  4133. 2:46:56specifically require again from Lang
  4134. 2:46:58chain dot
  4135. 2:47:01chains import retrieval QA right so
  4136. 2:47:05retrieval QA chain we will specifically
  4137. 2:47:08be requiring so all these libraries we
  4138. 2:47:09are basically imported uh and we are
  4139. 2:47:11going to use this for this particular
  4140. 2:47:13purpose now let's go read the PDFs
  4141. 2:47:20from the folder okay now here you have
  4142. 2:47:24loader is equal to Pi PDF directory
  4143. 2:47:28loader and here I'm going to give my
  4144. 2:47:30sensus folder right so here I will go
  4145. 2:47:32ahead and write dot start usor sensus
  4146. 2:47:37okay so this sensus folder I'm going to
  4147. 2:47:38specifically read and then I'm going to
  4148. 2:47:40use this loader do load and I'm going to
  4149. 2:47:44split uh I'm going to basically get my
  4150. 2:47:46documents okay so once I probably get
  4151. 2:47:49the documents then what I will do I will
  4152. 2:47:51create my text
  4153. 2:47:53spitter and for this I'm going to use my
  4154. 2:47:55recursive character text spitter and for
  4155. 2:47:58this uh the chunk size chunk undor size
  4156. 2:48:01I will be taking th000 okay and
  4157. 2:48:04chunk chunk uncore overlap will be
  4158. 2:48:08somewhere around 200 okay so all these
  4159. 2:48:11things as you all know I've written this
  4160. 2:48:13kind of code a lot uh and then finally
  4161. 2:48:16my final documents
  4162. 2:48:19okay will be nothing but I will be using
  4163. 2:48:21this text splitter and then I will split
  4164. 2:48:24all the documents so I will write split
  4165. 2:48:26all the
  4166. 2:48:27documents uh with considering all my
  4167. 2:48:30documents over here and let's go ahead
  4168. 2:48:32and see my final documents first final
  4169. 2:48:35document I'll just try to see I don't
  4170. 2:48:37have to display the entire thing so uh
  4171. 2:48:39this will probably read all the PDF file
  4172. 2:48:42inside that particular us sensus folder
  4173. 2:48:44which is present over here all the four
  4174. 2:48:45PDF files and then it will probably give
  4175. 2:48:47me a thing so here you can see one p
  4176. 2:48:50error is there so here let me go ahead
  4177. 2:48:52and write it chunk size now I think it
  4178. 2:48:54should be working fine and all the PDF
  4179. 2:48:56all the materials will be available in
  4180. 2:48:57the description of this particular video
  4181. 2:48:59guys for you all of you right so here
  4182. 2:49:01you can see and the total number of
  4183. 2:49:03length of final documents you can
  4184. 2:49:05probably see is somewhere around 316 so
  4185. 2:49:08here you can see page content H
  4186. 2:49:09insurance cover status everything is
  4187. 2:49:11available over here and this is the
  4188. 2:49:13total number of documents that I'm
  4189. 2:49:14actually able to get it okay now uh the
  4190. 2:49:17next thing that I will will be
  4191. 2:49:18specifically requiring is the embedding
  4192. 2:49:20technique what embedding technique I'm
  4193. 2:49:21going to use as I said I'll be creating
  4194. 2:49:24hugging or let me just go ahead and
  4195. 2:49:26write see you can use AMA embedding
  4196. 2:49:28anything but since I am planning to do
  4197. 2:49:30it with uh embedding using hugging face
  4198. 2:49:32so I will be using all the hugging face
  4199. 2:49:34components and these all are also very
  4200. 2:49:36good completely open source and
  4201. 2:49:38available for you from hugging face so
  4202. 2:49:40here I'm going to basically write
  4203. 2:49:42hugging face and biddings and uh the
  4204. 2:49:45next thing that I will specifically
  4205. 2:49:46require is my model underscore name this
  4206. 2:49:50is the first parameter that I will be
  4207. 2:49:51giving and then model number underscore
  4208. 2:49:53name will be nothing but I have explored
  4209. 2:49:57some of the model over
  4210. 2:49:58here that is this one right bu this one
  4211. 2:50:02is also there okay so one aming
  4212. 2:50:03technique is this one I can also use uh
  4213. 2:50:06sentence Transformers okay so let me
  4214. 2:50:08just show you instead of using this I
  4215. 2:50:10can also use this so I'll write down a
  4216. 2:50:13comment over
  4217. 2:50:14here oops just a second I'll just write
  4218. 2:50:16down the comment over here
  4219. 2:50:21okay so this also you can specifically
  4220. 2:50:23use let's go ahead and use sentence
  4221. 2:50:24Transformers if you want okay and uh if
  4222. 2:50:28you don't want you can also use this no
  4223. 2:50:30worries it is up to you okay both any of
  4224. 2:50:33them can be specifically used it is up
  4225. 2:50:35to you okay and these are some of the
  4226. 2:50:36free available embedding techniques that
  4227. 2:50:38is basically available okay so now I
  4228. 2:50:43have actually created this I will go
  4229. 2:50:44ahead and write my next one so before
  4230. 2:50:47that let me do one thing
  4231. 2:50:49okay and okay so the model name is
  4232. 2:50:51driven then I will be using model KW R
  4233. 2:50:54GS and I know I don't have to even use
  4234. 2:50:57GPU right because with the help of GPU
  4235. 2:50:59with the help of CPU this is possible
  4236. 2:51:01because I have very less documents so
  4237. 2:51:03I'll be using device device colon CPU
  4238. 2:51:08okay so this will basically be my device
  4239. 2:51:10with respect to this model arguments col
  4240. 2:51:13okay the next parameter that I'm going
  4241. 2:51:14to specifically use encode KW R GS and
  4242. 2:51:19incode _ KW RGS will
  4243. 2:51:21be here I'm going to use a parameter
  4244. 2:51:23which is called as normalize so you may
  4245. 2:51:26be thinking Krish from where are you
  4246. 2:51:28probably considering this I'm just
  4247. 2:51:31checking the documentation from the
  4248. 2:51:32hugging phase itself right so if you go
  4249. 2:51:34ahead and search for this right and
  4250. 2:51:36you'll be also able to see some of the
  4251. 2:51:37examples right so here you can see this
  4252. 2:51:40okay so here you just click on this and
  4253. 2:51:42here you'll be able to get all the
  4254. 2:51:44information there will be some code
  4255. 2:51:45files also which you'll be able to see
  4256. 2:51:47sentence Transformer is also there see
  4257. 2:51:48everything is over here right all mini
  4258. 2:51:51this one only I told right so similarly
  4259. 2:51:52you can probably go and check for many
  4260. 2:51:54of if you want okay now the next thing
  4261. 2:51:57that you really need to do is that you
  4262. 2:51:58have to set your access token of hugging
  4263. 2:52:00face unless and in order to access all
  4264. 2:52:02these models hugging face token needs to
  4265. 2:52:05be there so I will go and click on
  4266. 2:52:06settings in my hugging face account
  4267. 2:52:08there'll be something called an an
  4268. 2:52:09excess token okay and just make sure
  4269. 2:52:11that you create this particular new
  4270. 2:52:12token so once you probably create it
  4271. 2:52:14you'll be able to see it okay uh and
  4272. 2:52:16then you can copy it and you can
  4273. 2:52:17specifically use it but anyhow I will
  4274. 2:52:19show you where we'll be specifically
  4275. 2:52:21using now if I go ahead and execute it
  4276. 2:52:24so here could not import sent
  4277. 2:52:27Transformer install sentence
  4278. 2:52:28Transformers okay I need to install
  4279. 2:52:30sentence Transformers so let me quickly
  4280. 2:52:32go ahead and update my requirement. txt
  4281. 2:52:35file see whenever error comes some type
  4282. 2:52:39of things is always going to happen but
  4283. 2:52:41it's okay we should not be afraid of
  4284. 2:52:43Errors you know errors will probably
  4285. 2:52:46help us to do anything that we you want
  4286. 2:52:48okay P install minus r requirement. txt
  4287. 2:52:53so here you can see now the sentence
  4288. 2:52:55Transformers will also get installed and
  4289. 2:52:58finally you'll be able to see that okay
  4290. 2:53:00everything is getting installed itself
  4291. 2:53:02okay perfect perfect perfect perfect
  4292. 2:53:04sentence Transformers is coming over
  4293. 2:53:06here and now it'll be able you'll be
  4294. 2:53:09able to see that okay on once it is
  4295. 2:53:11installed then I think then you'll be
  4296. 2:53:13able to execute this okay so we'll wait
  4297. 2:53:16till this installation basically happens
  4298. 2:53:18so if if you have not subscribed and
  4299. 2:53:19please make sure that you write
  4300. 2:53:20something in the comment section how are
  4301. 2:53:22all these videos for you all are you
  4302. 2:53:24able to understand I hope many many
  4303. 2:53:26people I see whatever feedback that I'm
  4304. 2:53:28getting from people with respect to the
  4305. 2:53:30transition I feel that yes the videos
  4306. 2:53:32are doing something in your life at
  4307. 2:53:34least some amazing things in your life
  4308. 2:53:36and I hope to do as long as I can okay
  4309. 2:53:39but again my main aim is to teach you in
  4310. 2:53:41such a ways that you learn learn learn
  4311. 2:53:44learn things in a way that always it
  4312. 2:53:46matters in your life right and that is
  4313. 2:53:47what I'm actually looking at it okay so
  4314. 2:53:50let's wait uh sometime sometime sometime
  4315. 2:53:54some amount of time usually takes for
  4316. 2:53:56this particular installation but I think
  4317. 2:53:57once this installation takes place we
  4318. 2:54:00good to go okay and I'll also show you
  4319. 2:54:02how you can actually set up the hugging
  4320. 2:54:05face you have actually created the
  4321. 2:54:06hugging face tokens right but uh how to
  4322. 2:54:10set it up as an environment variable
  4323. 2:54:12still it is saying that it is not
  4324. 2:54:14installed yes installation is taking
  4325. 2:54:15some amount of time so let me pause the
  4326. 2:54:17video till then I think it is going to
  4327. 2:54:19take some time and then we will continue
  4328. 2:54:21so guys the installation is taken place
  4329. 2:54:23now you can go ahead and execute it and
  4330. 2:54:25I think it should not give me an error
  4331. 2:54:27now and your embeding hugging fish
  4332. 2:54:29should be imported over here okay so
  4333. 2:54:32perfect uh let's see uh it is going to
  4334. 2:54:34take some amount of time again it's
  4335. 2:54:36going to take somewhere around at least
  4336. 2:54:371 minute because this particular
  4337. 2:54:38embedding is quite big oh 13.1 seconds
  4338. 2:54:41this is absolutely amazing and this is
  4339. 2:54:43really good now after you have this
  4340. 2:54:45hugging face embeddings we will try to
  4341. 2:54:47use this hugging face embedding and try
  4342. 2:54:49to just check on one of the file okay so
  4343. 2:54:51I'll just go ahead and write embed
  4344. 2:54:53uncore just to check whether it is
  4345. 2:54:55working fine or not emid query and here
  4346. 2:54:58I'm going to basically take my final
  4347. 2:55:00underscore documents of zero okay so
  4348. 2:55:04I'll just take the first one okay first
  4349. 2:55:07one um and uh probably I will just go
  4350. 2:55:11ahead and use the page uncore content
  4351. 2:55:13because it'll be available over here uh
  4352. 2:55:16now what I'm actually going to do if I'm
  4353. 2:55:17specifically using these hugging face
  4354. 2:55:19emings okay I will also go ahead and
  4355. 2:55:21import numpy let's see import
  4356. 2:55:24numi as NP and let me convert this into
  4357. 2:55:28an array np. array
  4358. 2:55:31okay I think so it should not be giving
  4359. 2:55:34an error so we are just trying to see
  4360. 2:55:37okay perfect so whatever was available
  4361. 2:55:40in the first document of page content
  4362. 2:55:41this is how the embedding is basically
  4363. 2:55:43shown for the entire words okay whatever
  4364. 2:55:46the words are specifically present in
  4365. 2:55:47that particular embedding and uh if you
  4366. 2:55:50probably go ahead and see this what is
  4367. 2:55:52the shape of this particular array okay
  4368. 2:55:55I will also print that specific shape
  4369. 2:55:57okay let's go ahead and print this
  4370. 2:56:01first print this first okay and then we
  4371. 2:56:05will print
  4372. 2:56:07it I will paste this do shape okay I
  4373. 2:56:12think you'll be able to see the shape
  4374. 2:56:14384 okay and it is also getting printed
  4375. 2:56:16so perfect now what we going to do uh if
  4376. 2:56:19this embedding technique is working fine
  4377. 2:56:21then what we'll do we'll convert for uh
  4378. 2:56:24the words into vectors by using this
  4379. 2:56:26embedding technique and store it in a
  4380. 2:56:27vector store so for that I already have
  4381. 2:56:30imported FS so I'm going to probably
  4382. 2:56:32create my Vector store and I'm going to
  4383. 2:56:34write my f Dot and then I'm going to say
  4384. 2:56:37from documents uh did I import F yeah it
  4385. 2:56:43is imported from
  4386. 2:56:44documents and from the documents what
  4387. 2:56:47I'm actually going to do is is that I'm
  4388. 2:56:48going to give my final
  4389. 2:56:51documents my final documents till let's
  4390. 2:56:54say I
  4391. 2:56:55give 120 records okay there are
  4392. 2:56:58somewhere on 310 records uh I'm not
  4393. 2:57:01putting all because it is going to take
  4394. 2:57:03time okay just to show it to you but
  4395. 2:57:05later on once once you have time you can
  4396. 2:57:07go ahead and increase this number and
  4397. 2:57:09here I'm going to basically use hugging
  4398. 2:57:11face embeddings okay so Vector store
  4399. 2:57:13will basically get created so if I go
  4400. 2:57:15ahead and execute this again it is going
  4401. 2:57:17to take some amount of time at least 30
  4402. 2:57:19to 40 seconds because there are so many
  4403. 2:57:21documents over here and all this will be
  4404. 2:57:23embedding right it'll get embedded into
  4405. 2:57:26words and as you can understand every
  4406. 2:57:28document will be getting converted into
  4407. 2:57:30384 based on the chunks that we have
  4408. 2:57:33specifically 384 vectors okay so this
  4409. 2:57:35will basically be
  4410. 2:57:38my this will be my Vector store creation
  4411. 2:57:41okay and this is what is the step that
  4412. 2:57:43we have specifically done in every step
  4413. 2:57:46right Vector store creation perfect so
  4414. 2:57:49let's wait for some time and I think it
  4415. 2:57:51is 30 seconds it has crossed since uh
  4416. 2:57:54120 before when I tried to do it it took
  4417. 2:57:57me around 30 seconds because they were
  4418. 2:57:59only 100 documents okay so 43.4 seconds
  4419. 2:58:03perfect now we will try to use this
  4420. 2:58:06Vector store and perform query using
  4421. 2:58:09similarity search okay so similarity
  4422. 2:58:13search will be basically done over
  4423. 2:58:16here similarity search search will be
  4424. 2:58:18done okay and once we specifically do
  4425. 2:58:20the similarity search we will be able to
  4426. 2:58:22see or we'll be able to get some kind of
  4427. 2:58:24response over here okay so how to do the
  4428. 2:58:26similarity search first of all I will go
  4429. 2:58:28ahead and write my query uh with respect
  4430. 2:58:31to the query you'll be able to see I
  4431. 2:58:33will just write a question what is the
  4432. 2:58:36health
  4433. 2:58:37insurance okay now see this question
  4434. 2:58:40that you'll be saying I did not just
  4435. 2:58:42write it by purposely or somewhere uh uh
  4436. 2:58:45here uh what I will be doing with what
  4437. 2:58:48is the health
  4438. 2:58:50insurance
  4439. 2:58:52insurance coverage okay I what I did is
  4440. 2:58:55that I just went to this folder
  4441. 2:58:59okay and uh when I probably go ahead and
  4442. 2:59:02see this folder I will just open my
  4443. 2:59:04first file okay and this is where I show
  4444. 2:59:07this question what is health insurance
  4445. 2:59:09coverage so I will take up this question
  4446. 2:59:11itself okay and I'll will paste it over
  4447. 2:59:13here okay now once I paste it so this is
  4448. 2:59:16the query that I'm actually searching
  4449. 2:59:18I will go ahead and write relevant
  4450. 2:59:20uncore documents since I need to
  4451. 2:59:22probably retrieve that result that is
  4452. 2:59:25present over there so what I will do I
  4453. 2:59:27will use Vector
  4454. 2:59:29store Vector store dot
  4455. 2:59:34similarity
  4456. 2:59:36similarity _ search okay and whatever
  4457. 2:59:40query I have specifically
  4458. 2:59:42written okay whatever query I have
  4459. 2:59:45written and let's go ahead and print all
  4460. 2:59:47the relevant
  4461. 2:59:52documents let's go ahead and print all
  4462. 2:59:54the relevant documents so once I print
  4463. 2:59:57it I think I should be able to oh
  4464. 3:00:00relevant relevant relevant
  4465. 3:00:04relevant is this not the same
  4466. 3:00:06thing okay so here you can see page two
  4467. 3:00:10what is health insurance and here you'll
  4468. 3:00:12be able to see the answer this brief
  4469. 3:00:14prevents uh stage level everything uh
  4470. 3:00:17you are able to see this right
  4471. 3:00:18completely right and in order to get
  4472. 3:00:21this what I will do to exactly get the
  4473. 3:00:24page content so I will write underscore
  4474. 3:00:26page content so whatever question I'm
  4475. 3:00:28specifically asking you'll be able to
  4476. 3:00:30see this is the brief present state
  4477. 3:00:32level estimates of health insurance
  4478. 3:00:34cover is it same or not so this brief
  4479. 3:00:39presents state level estimates of health
  4480. 3:00:41insurance coverage using data from
  4481. 3:00:42American Community s server survey
  4482. 3:00:45American Community survey so here you
  4483. 3:00:47can see the US sensors and all
  4484. 3:00:49everything is working absolutely fine
  4485. 3:00:51okay uh sometime you also may be
  4486. 3:00:54requiring uh you know more results right
  4487. 3:00:57more let's say right now I'm just
  4488. 3:00:59getting one result let's say I want two
  4489. 3:01:01to three results now two to three
  4490. 3:01:03similar kind of results now what I can
  4491. 3:01:04actually do is that um or uh according
  4492. 3:01:07to that particular text or query that
  4493. 3:01:09I've asked the most relevant document I
  4494. 3:01:11specifically want so what I can do I can
  4495. 3:01:13basically write this Vector store okay
  4496. 3:01:16vector
  4497. 3:01:18store and I will specifically call as
  4498. 3:01:22retriever function I hope everybody
  4499. 3:01:24knows what is as retriever because we
  4500. 3:01:26have discussed more different thing
  4501. 3:01:28about it completely as retriever is just
  4502. 3:01:30a kind of interface that gets connected
  4503. 3:01:33to a vector store so that you'll be able
  4504. 3:01:34to get more results more amazing results
  4505. 3:01:37based on the similarity search and here
  4506. 3:01:39I will say search type similarity but my
  4507. 3:01:43search underscore
  4508. 3:01:45arguments okay will be nothing but my
  4509. 3:01:49search underscore arguments will be
  4510. 3:01:51nothing but K is equal to
  4511. 3:01:523 K colon 3 okay so this is what I will
  4512. 3:01:57be probably getting the vector store
  4513. 3:01:59okay and uh you can probably consider
  4514. 3:02:02this as my retriever itself right so I
  4515. 3:02:04will save this
  4516. 3:02:06as retriever okay and then let's
  4517. 3:02:14print retriever okay so here you can see
  4518. 3:02:18F hugging face embeddings all the things
  4519. 3:02:21and the number of search arguments like
  4520. 3:02:23most relevant documents I require is
  4521. 3:02:24three okay and now I can also use this
  4522. 3:02:27particular retriever to invoke anything
  4523. 3:02:29that I specifically want but before I
  4524. 3:02:32invoke understand I also require an llm
  4525. 3:02:35model now for those llm model as I said
  4526. 3:02:37I'm going to use hugging face llm model
  4527. 3:02:39now that is the reason the excess token
  4528. 3:02:41that are actually created right I'm
  4529. 3:02:43going to set up that excess token with
  4530. 3:02:45my hugging face so I will write os.
  4531. 3:02:47Environ
  4532. 3:02:48okay and here first let me go ahead and
  4533. 3:02:50import
  4534. 3:02:52OS import OS os. environment my hugging
  4535. 3:02:56face Hub API token so I'm going to set
  4536. 3:02:59this up as my API token because from
  4537. 3:03:02here hugging face Hub only will be
  4538. 3:03:04downloading the model we'll be using the
  4539. 3:03:05model and here we are going to
  4540. 3:03:07specifically use my token key right I'm
  4541. 3:03:10hardcoding the token over here because
  4542. 3:03:12I've have copied it from there itself
  4543. 3:03:14but don't use this because I'm going to
  4544. 3:03:15regenerate that particular token okay it
  4545. 3:03:17will be of no use okay now let's go
  4546. 3:03:21ahead and if if you don't know about
  4547. 3:03:23hugging face Hub guys what exactly is a
  4548. 3:03:25hugging face and all uh I'll be writing
  4549. 3:03:28some description over here for you all
  4550. 3:03:30right so hugging face is a platform with
  4551. 3:03:32over 350k models 75k data sets and 150k
  4552. 3:03:36demo apps all in spaces all open source
  4553. 3:03:38and publicly available in an online
  4554. 3:03:40platform where people can easily
  4555. 3:03:41collaborate and build ml together so I'm
  4556. 3:03:44also going to use this uh uh same
  4557. 3:03:47hugging face Hub and then I'm going to
  4558. 3:03:49write from
  4559. 3:03:51langin do
  4560. 3:03:55community Lang chain uncore
  4561. 3:03:59Community dot llms
  4562. 3:04:04import hugging hugging face Hub right so
  4563. 3:04:07I'm going to specifically use hugging
  4564. 3:04:09face Hub I will create HF is nothing but
  4565. 3:04:12hugging face
  4566. 3:04:13Hub and now I will show you how you can
  4567. 3:04:16call your models right the main
  4568. 3:04:18parameter over here is nothing but you
  4569. 3:04:20have to give your repore ID okay now
  4570. 3:04:23here one repo ID since you are going to
  4571. 3:04:25use the open source model is nothing but
  4572. 3:04:26mistol right so this is basically a
  4573. 3:04:29skeleton for you you can go ahead and
  4574. 3:04:31replace the model whatever you want
  4575. 3:04:33right so we going to use mistol 7B okay
  4576. 3:04:36again it is up to you whatever model you
  4577. 3:04:38specifically want to use only you have
  4578. 3:04:39to give your repo ID along with this one
  4579. 3:04:41more parameter that you really want to
  4580. 3:04:43give is model arguments okay so in the
  4581. 3:04:46model arguments here we will
  4582. 3:04:48specifically give temperature parameter
  4583. 3:04:50okay so temperature will be nothing but
  4584. 3:04:52it will be 0.1 and the next parameter
  4585. 3:04:55that you specifically going to give is
  4586. 3:04:56nothing but Max underscore length Okay
  4587. 3:05:00and this Max underscore length will be
  4588. 3:05:02nothing but 500 okay so these are the
  4589. 3:05:05two parameters that you really need to
  4590. 3:05:06create uh so that you will be able to
  4591. 3:05:09use this particular open source model
  4592. 3:05:11understand one thing this will be
  4593. 3:05:12directly using from the U hugging face
  4594. 3:05:15Hub itself okay you don't need to
  4595. 3:05:16download it locally for downloading if
  4596. 3:05:18you want to download it locally and
  4597. 3:05:20probably want to check it out so I will
  4598. 3:05:21also give you the code for that you can
  4599. 3:05:23which you can try it out okay now let me
  4600. 3:05:25go ahead and write the same query so I
  4601. 3:05:27will say query is equal to um what is
  4602. 3:05:31the
  4603. 3:05:33health same query
  4604. 3:05:37insurance coverage okay so this is the
  4605. 3:05:39query that I have now in order to invoke
  4606. 3:05:42it I will use the same H HF do invoke
  4607. 3:05:46okay and then I'm going to basically
  4608. 3:05:48give my query so here you can see now I
  4609. 3:05:51will be able to get my response and this
  4610. 3:05:53is the most generic response right what
  4611. 3:05:55is the health insurance cover I have
  4612. 3:05:57just asked this is the most generic
  4613. 3:05:58response which mral knows but my main
  4614. 3:06:01aim is to probably create a Q&A app
  4615. 3:06:04right Q&A app specifically for rag
  4616. 3:06:06application so still it is not
  4617. 3:06:08communicating communicating with my data
  4618. 3:06:10that is available in my PDF okay so
  4619. 3:06:12right now this is just given me a
  4620. 3:06:13general uh General output okay General
  4621. 3:06:16output what is available with respect to
  4622. 3:06:18the knowledge of the internet now the
  4623. 3:06:20next step what we are specifically going
  4624. 3:06:22to do see understand if you want to make
  4625. 3:06:24sure that we interact with our PDFs this
  4626. 3:06:26hugging face uh llm models we have to
  4627. 3:06:28probably create our own promp template
  4628. 3:06:30one more thing that I really wanted to
  4629. 3:06:31show is that um if you want to download
  4630. 3:06:35locally right hugging face models can be
  4631. 3:06:37run locally through hugging face
  4632. 3:06:38pipeline so here is the uh new code
  4633. 3:06:41before we used to use hugging face Hub
  4634. 3:06:43here you have hugging face pipeline same
  4635. 3:06:45code for TAS generation everything you
  4636. 3:06:47can probably execute this and this will
  4637. 3:06:49basically be uh able to generate it okay
  4638. 3:06:52but I'm not going to use this since I've
  4639. 3:06:53already trying to use from this right so
  4640. 3:06:55it is going to take some amount of time
  4641. 3:06:57with respect to execution perfect now
  4642. 3:07:00this is done now as I know I need to use
  4643. 3:07:03this llm model to interact with my PDF
  4644. 3:07:05so for that I will try to create my
  4645. 3:07:06prompt
  4646. 3:07:08template okay now the prompt template
  4647. 3:07:10will be nothing but
  4648. 3:07:12I'll I'll be
  4649. 3:07:22use
  4650. 3:07:23the
  4651. 3:07:25following piece of
  4652. 3:07:27context okay to answer the
  4653. 3:07:32question the question asked
  4654. 3:07:36okay so uh here is the simple prompt
  4655. 3:07:40that I have used use the following piece
  4656. 3:07:42of
  4657. 3:07:43context uh piece of context to answer
  4658. 3:07:46the use the following piece of to answer
  4659. 3:07:48the question
  4660. 3:07:52asked
  4661. 3:07:54please try to
  4662. 3:07:56provide the
  4663. 3:07:58answers only based on the context okay
  4664. 3:08:01so I'm just giving a simple prompt okay
  4665. 3:08:04pretty simple prompt okay now my context
  4666. 3:08:07will be over here C and txt okay and
  4667. 3:08:10then my question will be nothing but
  4668. 3:08:12it'll be over here and I think we have
  4669. 3:08:13done this many number of times in my
  4670. 3:08:15previous video okay and and uh if I want
  4671. 3:08:19one more thing I can probably give I
  4672. 3:08:21will just write helpful answers okay and
  4673. 3:08:25I'll keep it blank okay so this is my
  4674. 3:08:27prompt template that I'm going to use
  4675. 3:08:29and then in order to make it as a this
  4676. 3:08:31I'm going to use my prompt template
  4677. 3:08:32prompt template uh my template will be
  4678. 3:08:35assigned to this same prompt same same
  4679. 3:08:38prompt uh I think this is assigned to
  4680. 3:08:40this prompt okay so this will basically
  4681. 3:08:43be my
  4682. 3:08:44prompt okay and then my input
  4683. 3:08:48variables will be having two things one
  4684. 3:08:52is context
  4685. 3:08:56okay context and the other one is
  4686. 3:08:59question
  4687. 3:09:01oops same question just a
  4688. 3:09:07second
  4689. 3:09:09question okay so context and question we
  4690. 3:09:12are setting it as an input variable and
  4691. 3:09:13this basically becomes my prompt itself
  4692. 3:09:16okay so I'm going to execute this okay
  4693. 3:09:19now understand if I want to combine okay
  4694. 3:09:23I if I want to combine my Lang chain
  4695. 3:09:27right my my sorry not Lang chain my my
  4696. 3:09:30template with the llm models obviously
  4697. 3:09:32what you really need to do so that we
  4698. 3:09:34also get the context in the question
  4699. 3:09:36it's create retrieval QA right so create
  4700. 3:09:38retrieval QA chain right so if you
  4701. 3:09:40remember that in my previous video one
  4702. 3:09:42more way that I can specifically do is
  4703. 3:09:44by using this retrieval QA right and in
  4704. 3:09:47order to use this retrieval QA here what
  4705. 3:09:50I will do I will just write from chain
  4706. 3:09:53type okay from chain type and here I'll
  4707. 3:09:56start giving my parameters that I
  4708. 3:09:58require first parameter is nothing but
  4709. 3:10:00llm llm will be nothing but HF whatever
  4710. 3:10:03the hugging face library that we have
  4711. 3:10:04created I will create my chain type as
  4712. 3:10:08stuff okay so chain type will be nothing
  4713. 3:10:11but
  4714. 3:10:13stuff the next parameter that we are
  4715. 3:10:15specifically going to do is my retriever
  4716. 3:10:18which will be assigned to my retriever
  4717. 3:10:19itself which is basically defined return
  4718. 3:10:22Source document you can keep it as true
  4719. 3:10:26or false so that you'll be able to
  4720. 3:10:28understand from where it is basically
  4721. 3:10:29coming up so return Source documents
  4722. 3:10:32which will be assigned to True okay and
  4723. 3:10:34the next parameter is nothing but it is
  4724. 3:10:36my chain type chain type KW RGS okay and
  4725. 3:10:42you can also check out this entire
  4726. 3:10:44documentation from the from the Lang
  4727. 3:10:48chain documentation so prompt will be
  4728. 3:10:49nothing but it will be assigned to this
  4729. 3:10:51particular prompt okay sorry this prompt
  4730. 3:10:54so this is done like most of the things
  4731. 3:10:56have been completed over here but
  4732. 3:10:58understand one thing in retrieval QA you
  4733. 3:11:00have to give your hugging face your
  4734. 3:11:02chain type stuff your retriever return
  4735. 3:11:05Source document so that you need to
  4736. 3:11:07understand from where it is coming and
  4737. 3:11:08CH time arguments is nothing but with
  4738. 3:11:10respect to the prompt so this prompt
  4739. 3:11:12will return some of the documents it
  4740. 3:11:13will be setting up in the context then
  4741. 3:11:15question will go over there and entire
  4742. 3:11:17this retrieval q and will work okay so
  4743. 3:11:19here I'm going to write it as
  4744. 3:11:23retrieval QA right so this will
  4745. 3:11:26basically be there let me quickly go
  4746. 3:11:28ahead and execute it okay now it's final
  4747. 3:11:31that you just need to run it in order to
  4748. 3:11:33run it here is the question right so now
  4749. 3:11:37finally we can use this retrieval QA
  4750. 3:11:39that we have actually created and we
  4751. 3:11:40invoking with respect to the query that
  4752. 3:11:42we have already WR what is the health
  4753. 3:11:44coverage and finally let's go ahead and
  4754. 3:11:46check our result so here you can see
  4755. 3:11:48what is health and insurance covers the
  4756. 3:11:50brief presents the state level estimates
  4757. 3:11:52of this American Community survey the US
  4758. 3:11:55cons US Census Bureau conducts ACS
  4759. 3:11:57throughout the year the service asks
  4760. 3:11:59responds to report the coverage at a
  4761. 3:12:01time so every information is
  4762. 3:12:02specifically given now you can go ahead
  4763. 3:12:04and ask some other questions also if you
  4764. 3:12:07want um let me go ahead and ask this
  4765. 3:12:11differences in the uninsured rate by
  4766. 3:12:14state okay so I'll go ahead and ask this
  4767. 3:12:17let me go ahead and write my new query
  4768. 3:12:19so query is equal
  4769. 3:12:29to let me just go ahead and close this
  4770. 3:12:34in okay so here is my query so let me go
  4771. 3:12:38ahead and execute it now if I go ahead
  4772. 3:12:40and see this it should be able to give
  4773. 3:12:42me the response so here is a comparison
  4774. 3:12:44of ASM measure of health insurance so
  4775. 3:12:46everything is probably matching over
  4776. 3:12:48here see unsur rates of this this this
  4777. 3:12:50is coming up okay so all the information
  4778. 3:12:53are specifically coming up from here
  4779. 3:12:55this is perfect uh now we have I've also
  4780. 3:12:58shown you how you can probably work with
  4781. 3:13:00Lang chain and hugging face so let me go
  4782. 3:13:02ahead and update uh this also if you
  4783. 3:13:05want okay um insert sell CH sale to
  4784. 3:13:10insert okay so perfect this is it uh I
  4785. 3:13:16hope you like this this particular video
  4786. 3:13:18uh at the end of the day uh the one
  4787. 3:13:20thing that I really want to say is that
  4788. 3:13:22more you practice things more you see
  4789. 3:13:24things definitely you'll be able to
  4790. 3:13:25achieve multiple things over here so yes
  4791. 3:13:28I hope you like this particular video
  4792. 3:13:29this was it from my side I'll see you in
  4793. 3:13:31the next video have a great day ahead
  4794. 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.