Building RAG based model using Langchain | rag langchain tutorial | rag langchain huggingface

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we are going to do two things one we are going to understand what is this Rag and what are the fundamentals of rag and second we are going to build our rag application using Lang chain in Python okay so let's get started guys so guys we are going to understand what is basically Rag and why it is needed in the world of language models okay then we are going to understand the architecture of rag and what are the important components to build the rag based systems then we are going to build a rag in Python using Lang chain as I said and I'm going to also discuss what will be the next topics after this okay so uh one thing to start with the discussion of rag is incomplete without discussing the shortcomings of a large language model or language models okay so first of all let's try understanding what are some of the problems with language models okay let me go to the chat GPT prompt and let me ask something which is very very relevant for example um Virat kohle is not playing the England series due to some uh personal issues something so what I'm asking to chat gbt is is vat Ki playing next test match okay and see what what jgpt says I don't have real time information about specific Sports event uh beyond my last update in January 2022 okay which means that normally your language models the plain vanilla language models I'm talking about normally your language models are not up to date okay so first problem let's note here language models I'm talking about are normally not not up to date up to date okay because Virat kohi playing or not playing is already in the news but CH GP is not able to tell me that okay now if I go and ask chat GPT a very uh very generic thing right for example if I say what was TCS Revenue okay TCS Revenue in 2022 2023 okay so let's see what chat jpt says as of my last update again it is giving me some January 2022 update but all of you know that TCS revenue is nothing like a uh secret thing it's a public document right so TCS is a public listed company if you just go to Google and search uh TCS uh results in 2022 2023 this information is already available okay but it says I don't have access to special financial data for TCS which is not correct I mean um this information is already there on the internet but still it is not able to find me that information okay so what you can show here what you you can see here is very generic okay so one problem is not up to date other problem is very generic responses okay very generic response now now uh try to understand this if I want to use chat GPT or if I want to use any language model for my own work right what what is that I would want to do just think for a moment what is that I want to do I don't want an information which is not up to date this is not useful for me okay and I don't want information which is very very generic this is also not useful for me what I want to normally do do is or what I would normally want to do is let's say there is a PDF file okay in this PDF file there is some report so what I want to do what I want I should be capable of doing is I should be uploading this somewhere and then chat GPT I can ask questions to chat GPT or any language model about this PDF okay imagine there is a CSV data okay in this CSV data there is a sales report of unfold data science just an example I'm giving unfold data science sales report okay this is in CSV file okay what I what I should be able to do is I should be able to get the you know aggregation or group by or these kind of information from the language models by using this CSV file okay or suppose I have a text file here I have a text file this text file is let's say speech of Sachin tandul retirement day okay so if I want something very specific to know about sain tendulkar's retirement day that speech language model should be able to tell me the very very specifics of that okay so what I want to say here is my language model is useful only when it can give me specific information that I need and up to-date information that I need okay so these two problems we have to somehow overcome of the language models now that is where your rag comes into picture so what does rag stands for G stands for generation and R and A stands for different things so let me write here so it stands for retrieval okay uh retrieval augmented augumented generation okay generation so what is the meaning of retrieval augmented generation basically so generation is something that is normal your language model generation so I had created a video on what is basically generative AI so generative a is basically generating content right so generation is what is already there okay but these two things are new retrieval augmented generation so what is the meaning of retrieval augumented generation let's try to understand how rack architecture is different from uh normal language models so user will come okay this is the normal language models user will come user will put the query okay this is your llm okay this is your llm and llm will give you the response okay this is very simple just like I was talking to chat GPT now user query response this is your normal okay uh language models normal language I'll say Lang models okay but if I make here a diagram of rag based systems okay rag based systems so how it will happen is just try to understand this basic difference guys user will come user will put a query okay this query does not not go to the language model first it goes to something known as retriever okay so I'm writing here retriever okay retriever what the job of retriever is it will go and find the relevant information in a database so in a database means let's say there is a database which is manually uploaded by the user so what I'm wanting to do is I'm wanting to get specific information I want my language model to be capable of giving me the specific information up to- date information so obviously I need to train my model or I need to aument my model with that information right so that information I'm storing in this database for example okay so what the job of retriever is it will take my query it will hit this database and it will get some response okay it will get some response once this happens right then what this retriever will do is it will take your query that is original query okay original query plus the response it gets from the data database you can say data source you can say so let me write here data source okay query plus text to to keep it simple I will say text that it gets from the data source now these two things right these two things together together will go to your llm okay and then you get your response okay so from here you will generate your llm will generate your response this this what I'm drawing now is the response basically so how how rag systems are different from normal uh language models basically this Retriever and data source concept to keep it very simple when I asked the chat GPT here uh if is Virat kohi playing in the next test match imagine if I take a PDF file which has the latest news about the Virat kohle and if I give that PDF file to this model right then this model will never say I don't have upto-date information this model will simply say that I have a latest information vat K is not playing this match okay now this is exactly what is the meaning of Retriever and augmentation now there are various parts of this guys if you remember I created two two different videos on Vector databases okay and there is a reason for why I created this you see this data source here right now this data source we are talking about keeping uh text all this is language right so you can think of keeping text here okay now if you keep a text here right then it has to be kept in a vectorized format and it will be mostly a vector based database Okay so what will be the different components of a rag based system let's try to understand okay so you will need a retriever okay basically user and query already you have you will need a retriever okay you will need a retriever and you will need a database you will need a database where you will store your additional information so I'm talking about giving a PDF file about verat kohi right that you will store here in this database okay and what else you will need uh embedding why you will need embedding because you will store that embedded vectors in this database right so you will need embedding obviously you will need uh access to a language models Let's uh I mean simply let me say API key for your language models because you want to do that and then you want to bind all these things together right so for that you will need a framework such as Lang chain so let's say um chaining I I'm saying chaining okay chaining okay so important thing that we will need is retriever we will need a database we will need imputing methodology we will need access to a model that is API key and we will need a chaining okay so let's go ahead in Python and see how to implement a simple rag based model using Lang chin apologies for the interruption guys but I want to draw your attention towards the need of one of the unold data science family members so she's nandani and she messaged me in Linkin that she needs some financial support for um her father's condition so please go ahead and uh see the link is there in the description see whatever you can do that will be really helpful for nandini I have done my bit please try to do whatever you can okay it will help nandani and her family let's get back to the video so so let me go to chat GPT again and ask a question about one of the very famous book so this Atomic Habits by James CLA is a very very famous book um let me go to chat DPT and ask what are the chapters in the book Atomic habits okay so let me go here and ask what are the chapters in the book okay Atomic Habits by James Clear okay so let me see Atomic Habits by James Clear chapter 1 chapter 2 part three part four part five okay like this it is giving me up to if you note here it is telling me chapter 16 okay what I'm going to do as part of my rag is I'm going to augment my basic llm model with atomic habits Complete Book okay this Complete Book I'm going to put it in a database and I'm going to connect it with my uh normal uh augment my language model with this book and let's see if this normal response changes okay so let's come here guys so you will need some packages as I told you Lang chain right uh now if you want me to create a dedicated video on Lang chain I can do that but Lang chain is basically a framework that makes your life easy if you want to uh make applications of language model so it it gives you various things through which you can combine various functionalities of of um language models I mean various components of language models so what we are going to do is we are going to first of all from L chain you will need some packages okay I'll explain you whatever is important here okay so L CH I'm importing something known as P PDF loader why because I want to load this PDF Atomic habits book is in PDF format okay this book is in PDF format on my desktop uh on my download so I will take this and what I'm going to do is I will use this use this as the augumentation part for my model okay so I I'm keeping this in PDF pages okay then from Lang chain text splitter I'm using character text splitter which will which is simply a way of giving you tokens okay if you remember I told you we will need a vector database also so Lang chain Community gives you a vector store called as FS so see here I have opened the documentation Facebook AI similarity search is a library for similarity search and clustering of dense vectors okay so it says this notebook shows how to use functionality related to FIS Vector database so what to keep it very very simple we are using a database in the form of f FS where I will go and stored my embedded vectors okay so I'm importing this then I'm importing open AI normal embedding you will obviously need your API key as I told you uh open AI API key so if you see here I'm just loading PDF loader that I um this is my PDF book basically I'm putting in my document and I'm creating characters and then I'm putting in text and I'm creating some embeddings from open uh open AI embedding okay and here I'm saying using langen API function to interact with FIS so what I'm trying to do is I'm trying to just create the embedding and put it in this database so just pay attention here guys what I'm trying to do in this line I'm using open a as embedding I'm using the text which is nothing but my PDF book and I'm storing that in the form of Vector in DB okay DB is my database so if I if I see what is there in DB right you can see Lang and Community Vector store okay so that is that is my Vector database now what I'm going to do here I'm going to define a retriever if you remember I told we will need a retriever what is the job of retriever retriever will simply tell that okay so when I receive a query then I have to go and hit that DB and find the relevant information so I'm defining a retriever here and Lang chain makes your life easy if you want to Club all these things together so simply I'm saying from Lang chain toolkits import conversational retrieval agent now once this is done we will simply get an API here and through that API we can uh interact so if you see I'm giving your llm llm is nothing but chatbot API tools is nothing but this a simple tool that we created from here retriever tool okay and then from here we can interact with the model so this this looks pretty simple here because L chain makes your life easy when you want to work with a language model so basically I told you here right in the theory we are defining a rer we are defining a retriever okay we are creating embeddings and this embedding we are putting in this database okay we already have API key in the last step we are chaining all these things together using Lang chain so that we can call or we can make the requests okay so now I'm going to ask some question okay so I'm asking the first question here what are the surprising power of atomic habits if I ask the same question to Chad GPT here let me ask here this book is a very very famous book so I expect something T GPT should give me so let's see what response I get and you will see that response is very different from uh what I'm getting from the my model because my model is augumented with complete PDF okay so it is giving me some high level uh Four Points Compound Effect play two of this and three layers of behavorial change Etc which is not wrong but here it gives me a more detailed description of based on the books habits are the compound interest getting one % better Etc whatever it is okay now if you remember the first question I asked here is I give the author name and I give the book name what are the chapters in the book Atomic Habits by James clear right so it tells me part one part two part three part four part five so it goes till chapter 16 but if you see in my model right in my model it goes till chapter 26 okay chapter 26 the reason being this model is argumented with the PDF actual PDF actual book hence it has more information now if I go to this book right if you see chapter wise you will see only 16 chapters but there are things uh which are after after 16th chapter as well okay since I'm having more information through argumentation I'm able to classify that as 26 chapters okay so see 19 number is here okay the the gold uh gold rule how to stay motivated in life and work so this should match number 19 in my see the goldic rule how to stay motivated in life and work right but here in chat GPT you will see that 19 number is not there okay so what is happening is when you are argumenting it it is giving you more detailed information and more relevant information whereas the planed vanilla model does not give you more relevant and more detailed information okay so to summarize when you augment your model with some extra information you get up to-date information you get more relevant information you get your own chatbot okay so just to summarize what all we discussed guys we saw what are the common problems with large langu normally language models okay then how rack can solve those problems and how rag is used with a retriever with a data source with query and text it sends to LM and generates the simple architecture the important components and using Lang Lang chain how can we make it simply in the python okay please the like button guys if you like this video and if you want me to create a langen separate video I can do that just drop a comment on that see you all in the next video guys wherever you are stay safe and take care
Info
Channel: Unfold Data Science
Views: 3,332
Rating: undefined out of 5
Keywords: rag in langchain, rag in langchain pdf, rag langchain tutorial, rag langchain llama, rag langchain chromadb, rag langchain huggingface, rag langchain js, langchain rag, langchain rag tutorial, lanchain rag chromadb, lancghain rag, langchain rag agent, langchain rag llm, langchain rag aws, langchain rag js, langchain rag code, unfold data science, generative ai unfold data science
Id: U1JMy1LTSu8
Channel Id: undefined
Length: 20min 16sec (1216 seconds)
Published: Mon Feb 12 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.