Realtime Powerful RAG Pipeline using Neo4j(Knowledge Graph Db) and Langchain #rag

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey hi everyone welcome back to my YouTube channel my name is s Savita and in this video we're going to implement rag pipeline using neo4j yes guys so in this video we'll see how we can create a rag application using Knowledge Graph and for that I'm going to use this Neo 4J or a DB it's a Neo 4J only it's a cloud instance of the Neo 4J so uh we have mongodb so mongodb we can install in the local system and we have a Cloud instance of the mongodb like mongodb Atlas similar for the cassendra also so we can install the cassendra in the local system and if you want to access the cassendra so yes we have a cloud variant of the cassendra that is a Astra DB now similar to that if we want to access the new for so definitely we can install inside the local system as well as we have a cloud instense that is neoo or a DB guys uh I'm on the mission to uh like explore each and everything regarding this rag system so here whatever thing uh I can include in the inje in the retriever on in the generation I'm trying to include those thing here you can see you can check with my YouTube channel so if you will go through with my YouTube channel just go inside the video and see last three solution I created around to this estra DB before that I created a solution with respect to the mongod DB and before that I was talking about the multi model Rag and the complete rag Pipeline and all everything I covered over here on my YouTube channel with respect to the rag so soon basically I'll will be come to the uh like fine tuning as well in a similar way I will try to explore the fine tuning and here I will give you each and every flavor of the fine tuning also now uh guys uh here uh I will show you that how you can implement the rack using the Neo 4J so uh first of all uh what I have to do so here guys uh let let me open my collab and each and every uh thing I'm going to be write inside the collab itself because it is best for the notebook instance and here I can connect with the GPU also it's a free GPU so if you don't have GPU inside your system then definitely you can use this collab now I'm connecting with the GPU guys so each and everything I'll be showing you over here from scratch only so no need to go anywhere and yes be here just for 20 30 minute your each and every doubt is going to be clear and one more thing you will find find out inside the title powerful R system yes this is a very powerful R system and this is going to be a very very accurate also why I will let you know why it is powerful and the accurate okay so here what I did here I uh like connected with the GPU now I am going to be install couple of Library which is required for this project so the first library is Lenin the Len Community the Len open a and langen experimental now you'll find out the different different VAR of the Len Chen so first of all let me clarify this thing because many people were asking to me in the doubt in the like comment section and all so why you are installing the different different type of the Len chain so once you will go and check with the Len chain documentation itself so you'll find out there are different different variant of the L chain for the different different work okay so uh here I can write it down it and uh let me give you the uh like complete detail of it so see guys Lang chain core langen chain community and Lang chain so they have divided the Lenin into this three main variant so l in the Lin core actually you will find out this is the latest package okay you will find out all the latest thing uh with respect this Len expression uh lenen expression language okay and the other thing as well uh you can go and check and you can read like in a detailed way also then we have a Lenin community so in the Lenin Community you will find out they are providing you all the third party integration and all so whatever third party integration you can explore here inside the Lang chain Community then the main is len chain so this is the old package right this is the old package now whatever are like chains agent retal algorithm and all you have you will get over here itself inside the lench so the latest one is the Len chin community and Len Chen code now apart from this one you'll find out this L Chen open AI lch experimental and all so guys uh the Lang chain is going to be a very very popular and many people are contributing over here so that's why you will find out the different different variants of the leg G different different like module inside the single package got it now uh let me install this thing and until then what I can do I can explain you the architecture of this project now here guys you'll find out couple of parameter which I written so first is upgrade upgrade means the latest Library okay now latest version and here Qui means what quiet means silently I want to install it I don't want much detail about the installation over here there's a meaning of what that's a meaning of quite which I mentioned over here got it now see guys here what I did I have inst install the library now coming to the next Point here I like explain you the architecture so which architecture we are going to be Implement over here and what is the importance of this Neo 4J each and everything I'll be clarify if you are watching my video guys I'm covering everything from scratch so if I'm uploading video a little late so it doesn't mean that I'm not going to upload I'm going to be more research on top of it and I want to give you the refined content that's why sometime I takes time now uh here you will find out so let's say uh my user is asking any sort of a question now first of all you should have understanding of the rag architecture so that uh rag architecture I Define I like explain you many times if you will go and check with my previous videos you'll find out the complete and detailed introduction of the rag architecture so here I'm not going to be repeated you can go and check with my previous video so let's say guys uh what I have I have my data so guys let's say uh like this is what this is my data which I stored where so uh here guys what I did this uh data actually which I stored inside my or uh as of now this is what this is my data let's say this is what this is my user and user is asking a question right so this question actually uh like in a three way actually we are going to be perform the retrieve operation over here from the single database okay from the single database in three ways we are going to perform the retrieve operation first is based on the keyword the second is based on the vector s and the third is what based on the graph search yes so in a three ways we are going to be perform the retrieval operation and then we are going to be combine each and every context each and every retrieve information uh in the single document and that particular information we are passing to what we are passing to the llm so this is my complete information and this complete information I'm going to be I'm passing to my llm for generating the response okay so uh I hope this thing is clear what is a uh use of the Neo 4G over here I think you got to know about it now let me clarify more over here so let's say what is the meaning of the rag architecture so uh here U this is what this is my data now this data generally I convert into the embedding so let's say this is what this is my embedding and this embedding I'm going to be store inside the database so let's say this is embedding I have stored where I have stored inside the database okay now whenever user is asking any questions so what user will do let's say user is asking the question from here here this is what this is my user okay now based on this particular query we are going to perform the similarity search and here we are passing a we are getting a context right so here what we are getting we are getting a context and this context I'm passing to what I'm passing to my llm along with what along with the prompt and all and then finally I'm generating a response so this is my raw rag architecture okay this is representing to my data got it now here here guys you will find find out so this uh data where we are going to be in just tell me inside this architecture just look over here so this data we are going to be is store inside the Neo 4J okay this is what this is my Neo 4J whenever user is asking something whenever user asking any sort of a query right so in the three way in the three manner we are going to be retrieve the answer right so here what we are going to do we are going to perform the keyword search let me write over here keyword search okay we are going to fetch the information based on the similarity search and here in a third way right we are going to be fetch the information based on this knowledge graph so guys just think over here how powerful this context will be the context which we are retrieving from the from the database and this context this this context now where we have each and every information we are passing to my llm and then llm is generating a response and that's going to be quite accurate like other than so after this one I'll be starting with the evaluation part evaluation of this rank Pipeline and all I will give you the complete and detailed introduction of the like uh llm and the rag evaluation then uh yes the thing will be more clear to all of you okay so how we can evaluate this rag pipeline so uh this architecture is clear now coming to the next point so I have installed all the libraries and all now let me get the data over here so for the data guys what I'm going to do I'm going to be import from the the data I'm going to be import from the Wikipedia I'm going to be fetched from the Wikipedia now how I can do it so first of all uh let me give you few things over here so here guys this many parameter is required if I want to connect with a new 4J I will let you know how I will be getting each and every parameter over here just be with me okay in this uh entire solution everything I'll be clarify over here then uh one more thing is required so here guys as a model I'm going to be use this opening but you can use any model I have already taught you many open source model and all and soon I will be creating more video on top of it got it now this thing is required now uh apart from this one guys here we required one more thing so we required this Neo forj okay which we are going to be import from the lenon itself and here if we are able to create the graph okay if we are able to create the object of this NE forg class means I'm able to connect it now let's look over here that how we can get this particular information right so with that I can connect to my Neo 4J and it's going to be a very very simple guys don't think if it is a Neo 4J it's a very very tough no it's not like that so uh just do one thing just uh go first of all what you need to do let me uh show you from scratch only so once you will open your Google so over the Google you need to write a NE 4J login or NE 4J Aura okay so once you will write it down here you will get the link so just click on this very first link now after clicking on this very first link you will find out the same uh like homepage then click on this start free so it will give you only one instance okay as a free instance so yes you can change the ID if you want to create the multiple free instance otherwise you will have to pay okay so here uh guys you can see this is opening now let it open now after this one what I will do I'll be creating the uh instance over here so just wait it's taking some time now after this one I think there are maybe too much traffic on top of this NE 4J let it open let's wait until what I can do I can write a code for what for the data as well so here guys what I want to do I want to fetch a data because on top of the data only we are going to be create a rag so uh first of all guys uh for the data okay so we are going to be used the bigy pdia loader from the lch so this is what this uh like here is what here is my code for what for loading the data step by step I'm going to be show you the code guys so here now what I will do see first of all let me show you this page this Elizabeth 1 right so if uh you will simply search over the Google you'll find out this Elizabeth 1 Vick pedia page okay now now just see over here just just go and check with this page so here uh you will find out the complete detail about this Elizabeth 1 so who was who who is the Elizabeth 1 so she was the queen of the Britain right Britain means the UK and the Ireland and all so you'll find out the complete detail of the Elizabeth 1 over here now we are going to be fetch this data from this particular web page I'm not going to be use the beautiful so because in this uh method okay so they have defined everything in a back end actually so I'm just passing my name over here and yes we will be able to fetch the data by uh using this single query now let me do it over here if uh everything is fine then definitely it's going to work so here guys we will be able to find out we are able to get it now is saying please install a Wikipedia so here uh guys just a second let me install this Wikipedia and here for installing this Wikipedia simply I can write it down over here so this is what this my Wikipedia until I can check with my new forer yes so my new forer ready guys now what I have to do over here see so now guys just click on this new instance once you will click on the new instance you will get you will find out two one is free and one is professional so uh you need to select this free one just click on this create free instance and after that it will give you the detail okay now you require this detail to connect with the Neo 4G so just download it just keep it inside your system now I can uh keep inside the system so new for latest WR over here this one and here let it let me download it now see guys this instance will take time now until what I can do I can show you this txt file that what uh detail I got it over here so see what I got over here I got this URI I got this uh username and here is what here is my password Here is my instance ID and this is what this is my instance name but uh I required this three information so what I'm doing I'm just taking this three information from here okay I'm just taking this three information and I'm just going to be replace it inside my notebook so this is what this my three information and I replaced it over here and I can keep it inside this uh double putot just uh let me do it so here is what here uh I'm keeping it perfect now one more thing is required that is what that is the open AI API key so which I'm going to be collect from here itself I already kept open API key inside my notebook only so if I'm going to be executed guys definitely I'll be able to get my openi API key and this is what this is my variable now this variable I will set as a environment variable so here I have installed the Wikipedia also now let me do one thing let me install few more Library which is which is required for this particular implementation and finally I will store the data and I will retrieve it and then finally we are going to be implement the uh generation part so uh here couple of more libraries required which I left over here so here guys you can implement this new 4J okay let me do it in a single shot I think I missed this part so Lang chain Community lch openi experimental I installed NE for Wikipedia tick token for the token and files Jupiter graphs means for implementing the graph let me run it again because I missed this Library that's why I think I was not able to use the bedia also no issue so let me delete this part and everything is perfect now uh the main thing is what so here guys one more thing I have to set it as a environment variable so let me set this thing as a environment variable all the like variable whatever we have collected so yes now perfect open API key I have it forj UI this is also there username and password this is also there so I have all the library now I have my variable and now I'm going to be select as a now I'm going to be pass as a uh environment variable so simply I can import OS so import OS perfect and then what I have I have my environment variable great so now every setup is done and this is a mandatory setup for this project okay okay uh if you're not doing it guys definitely you will be facing the issue you will be facing the error now uh what I did here I created this graph okay Neo 4G graph now what I will do guys by using this graph object I'm going to be store the data okay I'm going to be store the data where inside the Neo 4J so everything is ready everything is fine now one more thing I'll let me do over here let me collect the data first of all and here I'm going to be collect the data and after collecting the data I can split it right I can split it in the uh like uh tokens okay document and tokens so that is very much required before installing inside the neo4j so here guys this is a code which I'm going to be copy and paste for what for splitting the data so here I'm fetching the data now this is the code guys final for splitting into uh like uh chunks okay this is the chunk size and here you'll find out the overlap now guys I already kept the code uh somewhere means in my notepad I'm just going to be copy and paste why because it takes time so more Focus okay here is my more Focus to explain you and definitely I will give you this notebook you can implement it by yourself because your main purpose is the learning and that I am providing you got it so now see this is what this is my token splitter token TX splitter in back end it is using tick token Library okay to convert my data into the tokens and uh yes uh the collection of the token is nothing it's a chunk okay means document so here guys you will find out this raw document if you will find out the raw document you'll be getting the complete detail uh from the Wikipedia itself now this is the detail it's a two along okay so it has collected the detail in the various uh like document if I'm showing you the length here so you'll find out the length is nothing it's uh like a around 23 so what I did over here I just uh took three uh document from here okay so let me show you the document if I'm going to be WR zero so you will get the first one so here uh this is the first document so it has collected the information in terms of the document now how many documents I'm going to be collect from here three document only okay so this is what I have written over here now let me run it and here I will be getting my document so this thing is clear to all of you yes or no if yes then you can mention inside the comment section yes sir whatever you are teaching we are getting everything now coming to the next part over here see guys so we got the data now after this one what we required so we have to store the data where inside the neo4j okay now before coming to the neo4j I would like to explain few more thing and then I will come to the new for so that your each and every confusion will be uh removed so uh guys see what I did I created one document for all of you and it's a simple guide on top of the no SQL database so we have different different type of no SQL database and here I kept four main type of database first is document store store okay the second is what second is the key Value Store the third is what third is what tell me third is a column column family store and the fourth is the graph store okay so in four manner in this four way I can store the data inside the no SQL database so let's see the first one and guys you can read the entire Theory and all so here the example is the mongod DB which I already clarified to all of you now here uh you will find out this is the example so we are going to be store the data in the form of document and the document is nothing it's a Json only all right now uh apart from this one see we have key value store so we are not going to be store see this is also key value store but this key value I kept it in the single document okay inside the single Json object and that we are going to be stored but here in the key Value Store each and every value is going to be key and value each and every value is going to be a key and value okay now uh you will find out this column not family so see uh this key value data store is nothing it's a radius my next solution will be on the RIT radis itself that is remaining and next video you will find out on the radis database now this column family is stor so here you will find out this Apache cassendra and here you can store the data in this particular way means uh in the SQL based database we are going to be uh search right the data rowwise but here we are going to be navigate data on the column wise so here I have written the differences also definitely you can check out but uh my main name see the summary uh each and every detail you will find out so column family store cassendra this is my schema and here the schema of the no my SQL you can check it and you can get the detail over here I will share this document to all of you now my main aim is the graph database so this graph database actually see let me explain you few more uh like in in more detailed way this graph database because everything is about to this gra database only in this particular solution so see this store the data okay it store the in data in the graph structure then with node representing entities okay node actually it is representing to The Entity Focus over here and here edges is representing to the relationship just focus guys between the entities okay this database are designed to handle complex and in uh interconnected data now the example is the new 4G and here you'll find out the use cases for what for the social media recommendation system fraud detection and for any type of data which is interrelated to each other now graph database model so in that we have nodes okay which is our entities relationship means ages okay and here is a properties attribute of nodes and relationship example name and all whatever name you whatever thing you will find out on top of the name that is a property now let's take example so let's take an example over here so here you will find out uh this is a social network example there is a three user Alis Bob and Carol okay now here uh this they have created a post created by the user so they have created one post and see relationship there is a relationship friendship relation between user okay uh friendship relation friendship between user and likes on post right so they are having a friendship and they are liking the post each other post now guys see whenever we write a query in the new FJ so that query is called tell me what is called it is called Cipher query okay Cipher query we have SQL query no inside this new for that is called Cipher query okay now creating the noes how we are creating a node see here if you want to create a node so we write this create then Alis okay this is my user and here is what name and here is one more user then name and age then there one more user name and age right and here is what here is my one more note that is what that's a post now what is this content graph okay this is the content of the post got it so this is the extra information like metadata and all now here what we are doing we are creating a relationship so Alis is a front of Bob B Bob is a friend of Carol Carol is a friend of Alis okay this is the relationship now creating post by user right so Ellis is posting so this is the Alice Post this is the Bob post now Bob is liking post okay post one Carol is liking post one and Alis is liking post two so this is what this is the relationship and here this is what this is a node right you don't need to be Master over here but at least you need to be understand this thing how it is working so guys I hope this thing is clear to all of you now see this is what this is my uh relationship how we were creating and we were creating a notes now finally what we are doing so uh I think this is clear to all of you uh it's a repeated one yes so let me uh red mark to it great it's a repeated guys this is the same one now guys here see if you want to query the graph this graph so for that we are going to be pass this match Alis okay user and here you will find out see this is what this is a connection so and here it's going to be return return what return name it uh might be a little complicated for you if you are reading it first time but guys believe me it is not at all required I'm just giving you uh for your general knowledge because uh somewhere we are going to use this query for getting for fetching the knowledge from the graph database okay now match here is what here is my user and uh this is liking the post and I want to get the content and here basically match what I want to match so find who likes the post graph database are cool so here uh by using this particular query I'm going to find out this name so likewise I will be getting the result okay and here is what here is a complete detail got getting my point now uh in a short what I can say so let me let me tell you so uh this uh is working in such a way let's say we have a node this is what this is my node okay it is containing a information and here it is connecting to the other node and this this is what this is my age okay Edge and it is showing the relationship the nodes Edge and this Ed actually it is showing a relationship between these two nodes gotting my point now coming to the main uh code and guys uh if you're getting bored now you won't get bored because now very amazing thing you will be able to see over here so now you can see my database has connected if I want to open to this database I will simply click on this connect and I will pass the password over here so uh let me copy and paste the password this password is required will ask you always so just a wait it is loading okay no issue later on we can do so uh here guys see now we required one more thing first of all let me load the model okay so here is what guys here is what here is my model this is what this is my model and model is what gpt3 now the next thing is what so here the next thing I'm going to be load this llm graph Transformer okay this is very amazing thing and because of that only we will be able to create this graph in a seconds now uh I think we are able to connect so it is asking the password and simply I can connect over here so guys see so uh here this llm graph Transformer it's a very amazing thing and everything is being done by this llm graph Transformer only now how let me show you this thing so uh see I I got this one and now I'm going to be run this a particular command okay I'm going just going to be called this method convert to graph document okay convert to graph document means whatever document we have I'm going to be convert into the graph graph and in second actually it will be able to do it because see I will be coming to this one what is this it's a very amazing thing first of all let me run it so once I will run it guys so it is going to be convert all the document into what into the graphs okay now if you will look into this uh document so you will find out the uh relationship it's going to find out the notes and relationship in between now uh what I can do I can show you as well so I can plot it uh this thing now uh here uh the plotting is very very easy so let me uh plot this thing to all of you uh let let me show you how we can do it and here uh for plotting this is the query okay default Cipher this is my Cipher query match okay here I'm going to be match whatever thing I'm going to be mentioned uh related to that um I'm going to be show you the relationship now uh guys here this is the uh like uh this is the method okay just to plot it each and everything I'll be showing you guys no need to worry about anything and here is what here is my show graph got it so this is the complete a code if you want to check the graph so let it run until then what I can do I can uh connect with this uh database it is showing connection is filled why it is so uh just a second let me remove it and here this is the one now which we have launched as just now so this is the one if I want to be open it so now I will pass the password which is my password guys uh which one which one which which one I think here it is just a second oh it is running let me check it is done or not great it is done I'm just going to be take the password guys this video is going to be quite long uh so no need to worry about it because at the end you will be learning a very good thing so which is going to be very much powerful as well and you can mention inside your resume and all everywhere now let me connect it and here here here great now I'm able to connect fine so this is what this is my datab base and once I will run it guys once I will store the data you will find out very amazing thing over here okay so I'm able to connect with my new 4G see now what I can do see there is a next thing and which is going to be a very amazing and guys don't miss this thing because after this one we are going to be retrieve the information after restoring and then finally generation so uh here is what here is my graph document now let me show you so this is what this is my relationship each and every relation okay so as of now maybe we are not able to see anything but yes once I will visualize it you will be able to get it see this is what this is my relation but how we are getting it what is the logic behind it that I'm passing everything to this method convert to graph and I'm getting this relation there is any logic right that's why we are able to do it so let me show you this thing guys because this LM graph Transformer is a very very amazing thing and once I will show you literally you will be surprised so here uh let me uh open it which one this uh neo4j okay this Neo 4J link now here they have given you the complete detail about this neo4j llm knowledge graft means see uh once you will click on this one now open the llm knowledge graph Builder just click over here right after clicking over here you will find out one playground see guys this is what this a playground now if you want to connect with your database so simply you can connect it and here what you need to do you need to pass your password so let me pass the password and here I'm going to be connected okay just a second maybe something else so I can take a password from here only where is a password because uh there are so many files and folder going to be M so this is going to be my password guys and let me connect with this playground right so here I'm able to do canot isol address here here here username database okay I think I need to pass the URI also so URI is going to be this one and this is what this is password just a second I'm going to so here is what here is my password okay now connect see it's getting connected okay so let it connect guys it is let uh connected now what I'm going to do here I'm going to be load the data the same data data which I'm showing you over here right so here is what here is my data my data Elizabeth 1 I just need to pass the name and yes I'll be able to open it so see it is scanning and then it will be fetching the data okay so it is doing it guys see what is the logic behind it and see like I I got the data I got the data now see I will select it okay I will select it and here see I will click on this generate graph so it is generating a graph it is a graph mean it is it will show you all the entities and all node or like other node and in between the edges relationship and all everything you will be able to see over here so it is creating a graph and it's a kind of playground okay so let's wait let's uh wait for a 2 minute and guys please don't mind this video is going to be up little long but at the end you will get very amazing thing over here so just a wait let it complete and then you will be able to get uh amazing thing great now see I got this button so grab now if I will show you this graph so you will uh really find out the magic see guys so here what I have I have my complete graph see Elizabeth one okay so let's say if we going to talk about this one so just just focus on this uh like church of England right Church of England you'll find out this uh detail okay so how it is connecting to this Elizabeth so Elizabeth 1 is stabilize this church of England okay now this uh Baragon vergi it is directly connected to the Elizabeth how so here you can see like Elizabeth Man created this Baron vgi Baron vgi maybe it's a like house or something then here you can see Elizabeth one and Spain so mood uh Manu word between so see guys it is automatically a to create a graph and yes it is showing the relation also how amazing it is getting my point now you can see all the entities and all everything over here so yes uh here everything is visible to all of you now see entities is what entities is nothing it's a relation okay the noes itself if you want to check the document so where they are using the document you will get that detail also where they are using the chunks and all okay for creating this one you will get that detail also so this is very amazing now what is the agenda behind it see this class llm graph okay the class uh which like I have imported so what it is doing you know automatically the in behind actually behind behind this class one LM is running now this llm automatically creating a query okay which query new for query new for query so NE for query based on this llm what we are going to be do we are going to be find out this nodes okay nodes and relationship in between noes and relationship in between based on this llm and it's going to generate a query so everything is going to be automate guys and it's a pretty amazing thing this class is a pretty pretty amazing now uh this was the master stroke this llm graph Transformer and here based on this one we are able to do it now guys see what I'm going to do here so here is what this is my data now if I want to store this data I can simply store it by using this particular uh method graph which I already imported now add graph document so here I'm going to be add this graph document inside where inside the ne 4J okay NE 4J Aura so here I'm going to be inserted guys and now you will find out the gra where data over here okay once uh it will run so graph is not Define I think I kept somewhere over here now let me check where is a graph this one guys so let me execute it and here I'm going to be Define the graph now what I will do so I will store the data just a second so here I'm going to be store the data now see finally if I want to be visualize this graph inside my local yes that is that is also possible so simply I will run it here the fall Cipher and once I will run it guys I'll will be able to do it but let me check whether I imported all the import a statement or not so because I can see over here graph database and graph diget is missing so uh I don't want any sort of a error so that's why what I'm going to be do I'm going to be import this particular thing this is what this is a widget okay now now the next thing is what so here I'm going to be use this graph database and this vidget this two things graph database and graph videt and here I'm going to be recognize it that's it now run it and run this one okay both are working fine now here you need to pass your username sorry URI username and password and yes it is done now just run it and once you will run this so graph okay once you will run this so graph so you will find out what we are getting guys we are getting a graph over here and here this Cipher we we are already defined this Cipher either you can Define like this as a global variable or you can pass it from here now see guys the same graph we are able to see over here you can zoom uh you can zoom over here and you can check each and every relation over here guys see how amazing it is and yes each and every relation it's a little complicated so we'll find out some like uh difficulty if we are going to be check it but yeah if you will look look over here carefully you will be finding out each and every detail so this is what this is my one document okay this is what this is my one document and here uh this document actually I'm going to be uh store as a embedding right and this document it is connected to the other document right so here is what here is other document and here we are having a relationship in between so we are it is showing that relation also now maybe it is not very much clear over here but let me show you somewhere else else so if you will open this new 4G okay where H actually I have stored the data now let me refresh it so the same thing you will be able to find out over here as well so just a second Let me refresh it and see guys so all the entity see chunks okay see this is what this is my chunks of the chunks which we have created and with respect to that we have a embeding okay City Country data and event and all so this is nothing this is my entity and every sort of a detail basically you will be able to get over here now once you will click on this entity you will be getting all the entities over here and even you can check which entity connected to which one right so this is a graph view so you can find out the complete a detail over here okay so complete detail if you have a little knowledge of the graph database definitely you can understand each and everything over here getting my point so this is my entity City Country and all and here is what here is my chunk and with respect to this Chun I'm going to be I'm going to be like doing a embedding okay so embedding is there a query search is there and this graph retrieval is also there I will show you how you can retrieve now see relationship and all everything you can check so what is a relationship belong to okay birth okay so Elizabeth work to this particular person right so here you will find out born at so Elizabeth born this at this city now child of so Elizabeth what child of this person and all and the complete detail just just just see over here guys how amazingly you are able to see each and everything now coming to my final solution how to retrieve the data after storing it and then on top of it how to create a uh like generation okay so uh let's do one thing let's uh try to store let's try to retrieve the data from here and that code actually guys it's a little uh complicated but we try to understand if you're not getting it then again and again you will have to do a revision on top of it so see guys this is my first method this is the one okay now uh here uh my next one is going to be this one so let me import this part as well here I can do it and here I'm going to be load this code this one okay so this one now uh we have I have one more thing so here is going to be my prompt so this is what this is my prompt I'm writing a complete retrieval code just wait then uh here this is my chain okay this is what this is my entity chain so let me keep that entity chain over here now after this entity chain guys okay so this chain and now if I'm going to be invoke guys I'll be able to find out the entity you know what is the entity see if you don't know you can revise from here you can revise from this particular documentation which I have written for all of you so just see over here what is the entity node will represent the entity and Ed will represent to the relationship got it now see entity is there entity chain is there now what I will do so here guys uh one more thing which is required so so I told you it's going to be a little longer because we have to extract so many information from the data and now we have one more thing so generate a full text query so here I can keep this one also okay and finally this is what this is my full text query okay step by step I will be explaining you each and everything guys just be here and please believe on me if you believing on me you will be getting many more thing over here so this is what this is my data now I'm fine and here is going to my perfect retrieval guys this one so this is what this is my retrieval and now here is what here is my template and this template actually I'm going to be consumed if you are looking that this code is very very huge no it is not so I'll be explaining you guys and believe me nowhere you will find out this type of solution and all and in the industry we definitely do it and uh yes we like fetch the data and all from the from where from the databases okay so this is my complete solution with respect to the retrieval now after this one you'll find out the final template prom template and with respect to the template you will be getting what so you will be getting the chain which I can directly invoke okay so let me write the final chain and here my code is end guys see this one this is the last and now my code is end this one so step by step guys I'm giving you the complete detail because the retrieval process is going to be a little longer because we have to extract so many information from the database and that's why my R CH is going to be quite accurate okay so let's begin here so first of all guys see here I imported this openi Ed now a new forj Vector from where from the existing graph right so from the database itself I am passing the edding over here the search is going to be hybrid search okay means it going to be performed on the edding as well as on the keyword then here is what here is my document this uh is working this search actually it is working on the document itself this uh we are going to be create an index now on top of it only we are going to perform the simil search then this is the there a type of the document okay it's nothing it's a text only and embedding note property it's nothing it's a embedding okay that's it this is what this is my index now let me check whether I have imported everything or not so let me import everything from my notebook also otherwise I will be getting the error so new 4J Vector Neo 4J Vector uh first of all let me import this typing and all so here is what here is my people list and all everything now new 4J Vector guys here it is this is the one so from the vector store actually I'm going to be imported now here is what here is my NE Vector so fine now uh what I can do let me keep it after this one so just a second here I can keep this code so NE Vector from existing graph we are going to be create this Vector Index right so this Vector index I'm going to be create on top of the node itself where I kept my document so here it is done now what I will do guys see here let just see so chat promp template is also there let me check whether I have imported or not this chat prom template because I told you there are so many things you will find out inside uh this particular solution so chat prom template okay great I have imported now uh here I'm passing this uh system this is my system uh like uh prompt you are extracting organization and person entities from the text whatever text I'll be providing and here is a human human is what means the user itself this is the system use the uh use the given information to extract information from the following so here I'm passing my question got it so this going to my prom template now what I will do see uh here first let me run it okay now it is perfect great now uh see what I will do so here I will be creating one entity okay so in the entity see here is what here is a name just just forget about it so this is the message and all nothing else so identify information about The Entity means about the nodes so whatever we are passing okay whatever we are passing so from that particular uh data I have to exct either person organization or business entity okay this is the thing which we have which I have to get so let me run it so here is going to be entity class so here I'm going to be import this base model which is having some required information later on I will be showing you this B model okay so here is what here is my entity now is what this is my prom template and here I'm going to be create a chain okay prom template and here is what here is my llm where I'm passing this entity now whenever I'm passing anything to The Entity whatever question so what it will do it will return to me this thing whether organization okay whether organization or person organization and person entity which I have defined over here person organization or any business entity right so I'm passing this particular query now let's see what I will be getting from here so here once I will learn it guys I will be getting this Amilia aart right so C is what C is a poster right Amia aart right whatever question you are going to be pass you will be getting the M you will be getting the entity from there now what I'm doing here so here I'm going to be import this remove lense character means whatever unnecessary uh punctuation and all for removing it uh I'm going to be use this particular class now what I'm doing so here I will be passing my query and this particular whatever like input I'm getting from here okay with respect to my query uh which I'm fetching from the database itself I'll be passing over here and I will be converting into the full text query okay you will get it once I will learning see here is what here is my uh like uh this Cipher query which I have written for fetching the data from where from the graph database okay now see what I'm doing here so here I'm passing this question who is a Elizabeth 1 so this question will go over here to the structure retriever okay so from this database what I'm going to do see I'm going to be collect the entity means Elizabeth 1 and with respect to this Elizabeth 1 I'm going to find out all the relationship from the database right now I'm passing this thing this entire data to the where to this particular method where I'm going to be convert into the single structure query okay so let me show you how what I'll will be getting over here so if I'm running it you'll be finding out each and every detail with respect to this elizabth okay so is stay for in full query by Java there is no full text entity full text uh full text entity generate Forex guys just a wait so here what I will be getting structure retriever uh okay this is fine now let me R it here client error let me check why it is so uh this is what this is my entity class guys just wait let me check over here now guys here you can see we are able to extract all the information related to this Elizabeth and that is what I was trying to say so what was the issue in my code so here actually the issue with respect to this index uh Vector index actually when I was creating the vector index at that time uh maybe I uh like uh I run run it two time and because of that it got it got override and the index uh size was not matching okay that was the main issue over here so I just restarted my uh like kernel and then I rerun it again okay so uh here everything is fine so far now I'm able to get each and every relationship with respect to this particular entity and that is what my that is my Moto okay and this particular information I want to provide to my llm now how I can do it so here this is my first uh like uh this is my first context which I'm getting from my Vector databas from my uh like graph database and this is my second one second uh basically which I'm getting based on the index similarity search Okay so the both information I'm going to be connect and then I'm passing to where I'm passing to my llm so let me run it guys this is my final retriever so here is what here is my template which I'm going to be create so given the following conversation as a question rephrase the following up to be a standalone question in it is original language here is a chat history so I will be appending the chat history also and here is what here is my final uh like the uh the latest question is so this is going to my template and it will be a part of my final prom template I will show you where basically I'll be getting that so here is what here is my template now this template actually I'm passing to this uh from template so this is what this is my condens question template okay now uh here this is what this my from chat history so if I want to be like keep the chat history so I'm going to be use this particular method that's it right now our final is what so this is what my final runable Branch so where I can uh accumulate most of the branch right all together so I'm passing this runable Lambda inside this runnable Branch so in in the Lang chain Community you will find out many runable method or many runable class and all runable Branch runnable Lambda runable pass through and all so at the run time dynamically we want to pass anything for that we have this runable now runable Lambda what we are passing uh we are getting the chat history okay and then here what we are going to be do we are going to be assign over here okay this at the run time right so whenever we are passing any sort of a PR at that time we will be getting this chat history also getting my point now uh this is fine so and now this is what this my final uh template so here what I will get I will be getting the context here is my here is my question and then that is what that's my final answer right now this is what this is my final prompt okay so let me do it let me run it again so now everything is perfect so what I'm going to be uh what I'm going to be uh do over here inside this rable parallel see I'm passing the context means what my search query right so where is my search query tell me this is my search query so here basically it's going to be run this runable branch in the in that actually I'm going to be get this entire chat history whatever is there and I'm keeping it where inside the chat history then condens query condense like question prompt means which is containing the entire history then model and then uh output okay so this will be a refine uh answer based on my chat history then uh after that here is what here is my retriever in the retriever actually I'm going going to be collect each and every information okay each and every information from in the form of graph uh this this information based on the particular entity and my based on the similarity okay this is what which I'm getting over here now after that see what I have I have my runable pass through means on the run time itself we can pass the question then uh here is what here's my prompt llm and this is my output par now finally if I'm going to be run this chain and once I invoke it so I will be getting my answer guys and this is going to be a very very precise I have tested on the many questions and I got a very precise answer so whatever prompt you are going to be defined according to that actually you are going to get a answer so if you are going to say get give me in a detail give me something this that according to that you will be getting the answer but this is going to be a more precise whatever you want to ask you can ask because we are going to be pass a multiple see here what we are going to do we are going to be pass a multiple context multiple context to my errl I hope this thing is clear now let me ask a couple of more questions so the idea will be more clear to all of you so let's say if you want to invoke uh if if you are going to be write this question the next question so in the next question what I have I have this one so what I'm doing I'm writing when was heon Who who regarding what I'm asking I'm asking related to this Elizabeth and here is what here is my chat history which house did Elizabeth belong to so this is what this is my like chat history which I'm passing over here okay so here uh here is what here is my question which I'm writing so this chat history guys where it will go so this will go where here okay I'm going to be append it over here and based on that what I'm going to do I'm going to find out a relevant keyword and which is going to be help in this one the next question likewise actually I can connect the multiple question now see whenever I'm going to be invoke it so here you will be able to find out I will be getting my answer and this is going to be quite accurate so Elizabeth 1 was born in SE 7 September 1533 so I hope this solution is clear now uh it is very much important please go through with it and definitely uh you will find out many amazing things you will be find out like my rag is too much powerful it is able to answer each and everything yes so in the next uh video I'll be talking about the redis and then we'll complete this uh no SQL database Series so thank you guys thank you very much for watching this video we'll meet you soon in the next video Until thank you bye-bye take care
Info
Channel: Sunny Savita
Views: 3,560
Rating: undefined out of 5
Keywords: multimodal rag, rag app, rag application, rag tutorial, rag system, multimodal ai, gpt4-v, python programming, ai, generative ai, genai, rag, gpt, openai, chatbot, langchain, openai api, neo4j, graphdatabase, vector embedding, graph knowledgebase
Id: Ik8gNjJ-13I
Channel Id: undefined
Length: 53min 16sec (3196 seconds)
Published: Thu May 23 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.