Superior RAG for Complex PDFs using LlamaParse | Open Source LLM | Text + Tables from PDF

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and welcome to this new video where we will solve very interesting problem so we will build a rack pipeline to ask question answer or complex PDF where we have table information also so the idea is like from the tables which are present in a PDF I want to some ask some questions and we'll see whether we can get the right answers or not this is always a very challenging problem and we'll see how accurately we can solve it so first we'll use llama pars here so this is a new uity build by llama index which helps us to uh extract the information text plus the temp information from the PDF and it is working pretty good it can extract most of the information correctly so we will use Lama pars as uh as a PDF reader which will extract information and uh we will use uh this uh document uh which is like uber 2022 March quarterly report which has lot of complex tables like this big tables and all so we'll ask different questions from these tables and and under these different columns and see whether we can get the right answers or not so let's get it started so for this we import like installing the required packages as we do always then there some other packages also we need for this so we are installing all them and then I'm just downloading this uh PDF file using this uh command and then to use llama part so currently recently like llama index launched their new Cloud platform which they call Llama cloud and it has option of passing also so from here you have to create API key so this you can generate new API key from here and that API can key can be used to uh use llama Parts uh to query the like ex information from the PDF so what I'm doing is like uh in kagle you have options on add-on so here you can save your secrets I have saved my secret here and I'm just reading that secret here using this command and my secret value is stored here which I will use later similarly if you're using Google collab there also you have an option to uh store your secret key so this is what I'm doing just go to this link get your key and store your key safely somewhere so that you can just use it later then I'm just importing all the required packages and then I'm just installing my llm model the same Cipher model from hugging face llm and I'm using the same embedding which is BG small embedding and I'm downloading using Hy face embedding so this is my Lama pars I'm just uh calling like inting Lama pars and to use lamaar you need to provide this key uh then only you can use it as a AP so I'm just passing my key here and I'm passing the path of the data and it will just exct the documents into this uh documents variable I'm just printing this like how this ex extracted information looks like so it looks good so next what I'm doing is like so to read this like ex information like the text and the table I would be using uh markdown element node parcel so it will read my uh documents which has text and table and create different notes now how it works like it uses a large L as model and why why it use LM is to for the tables it creates summary also so while excting the text and the table information it creates summary of the table and keeps a mapping of it but I don't want to use summary I will show like without using summary also how good performance we can get so it doesn't have an option like user friendly option to disable summary part and passing llm as so I what I have to do is that first I have to modify that class so I'm just calling this m element node CL it calls this base element like can added this base element not passer so I've done some changes here here in this base element note pass first one is related to LM I just commented this piece of code what is like checks if LM is there then it uses LM if you pass none it goes for open a I don't want to use open a so that's why what I've done is that I just commented this p and I'm just passing whatever value I'm passing into LM so if I pass none also it will be passed into LM as none which goes in there so that's one change I have done second this is a function which creates a summary I don't want to create a summary so what I'm doing is in table output under summary where just storing the table context like the input text only I'm just passing as summary only I don't want to call LM and it takes a lot of time to do that so that's avoiding it and without this also it works pretty well so these are the two changes I've done rest of the things is pretty well same so I'm just uh calling this class which I modified here and passing LM as n number of work so it works as node passer and then from node passer I can call get noes from document as we do Always by passing my expected ents from using llama pass it will create different nodes now what you have to do is like from node parcel you have to call this get nodes and objects so what it will do is like it will except the text and the tables also so text will be stored in Bas notes and the tables will be stored in objects so I just printed this table one table and you see this is how it's storing all the table information and then what I'm doing so I will be creating three different r or three different strategies and we'll see how all of all the three are performing and which one is working the best so first one is I'm just creating Vector store index and I'm passing in the nodes both the text node and table node like the objects and the base no both I'm passing as nodes and I'm creating a vector Stone X that's one retrial we have defined second one is I'm just creating a new Vector Stone and I'm don't I'm not passing any notes and table I'm just passing the excted document only and it will just create chunks out of it by assuming tables as a text only and it will create chance and we'll see how this also performs and idea is to show like whether we if we segregate text and table separately in different nodes will my performance improve or not that's what we want to see and the third one is the recursive retriever the powerful retriever so what I'm doing first I'm just calling this node part get base nodes and mappings so it creates a mapping of the tables and base notes are stored in this and then I'm just passing base nodes only into this Vector Stone index and which has a in mapping like ID of my tables which are stored in this and uh recursive retriever will help with us to find that information from this node mappings and then I'm just calling this index as retriever I'm saying top case 15 and then in recursive retriever I'm just passing this index retriever which has the base note only and then node mappings are the one which is there present here so if for a given query if we found the index node which has the ID of this table which is present node mapping so it will give me the table information and that table will be pass to the L model so this is how recursive index will work and then what I'm doing I'm just using one more advanced technique which is rankers so what I'm doing I'm just taking top 15 like you seen I'm just taking top 15 as my context but I don't want all top 15 directly to pass to uh my llm I want to rank them first and pass the top five and for that I'm using flag embedding ranker and what it does like it will take your query and every context and it will pass that as a input to this BG rankle large model and it will give me a score so if you see this is the link of this like up link and of this ranker so you just call this ranker and you pass your query and the passage passage is the context and for every combination you get this score and then it just gives you the top five uh uh scores combination so same way we are doing here so this is my deer which will be which I will use in all my three retrievers so first one is the index with object where the vector store index where I pass the node and the table together I'm calling as a query Engine with top ks5 passing node post processor as ranker so how it works that it works as a note post processor so first based on the query I will get the top 50 context and then those top 15 contexts and the query combination like every like query plus every context would be passed to this ranker and all those 15 combination and we'll get this score and this based on this ranker I will get the top five which will be passed to my LM that's why we call node post processor it's after getting the nodes we do post processing so this is one query engine we have defined the other query engine is using our raw index which is my base one which has it all all the documents it doesn't know what are tables what are text and I'm calling a engine top 15 here also and I'm here also I'm passing note processor then the third one is our retriever query engine which we uh using this recursive index so I'm just importing this retriever query in it takes the retriever recursive Retriever and it also takes the node processor and thenos is false and this is my recursive query engine so these are the three query engines which which we will be using to ask different questions from the tables and we'll see whether we are getting the right answers or not and which one is performing the best so let's test all the three query Eng so we have our first question the question is that how is the cash paid for income taxes net of refunds from supplemental disclosures of cash flow information so first this query will go into my first raw query engine which is the basic one where it doesn't know what are the the tables what is text I'm just passing complete document into Vector stex second my query will go into this index with object query engine which has the index with table information so this is a vector index where I have passed text notes also and table notes separately as a combination and third one is my recursive query engine where I'm passing my text node into my Vector Stone index and then the table nodes as part of mapping into this recursive retal so for this question we let's see what answer we get so from the first one basic querer we got so I just put a screenshot also so like this was the question from this table like income tax and net of refund like cash paid for and the answer should be like $22 and $41 so if you see the first query engine it got the correct answer like 22 uh is 2021 and uh it was 41 in 2022 and this is right answer and from from our second uh query engine also we got the right information 30 22 and 41 and from recursive also we got the right information 22 and 41 so for this question all three retriever Square engine works pretty well now this is my second question what is a change of free cash flow so this is from this table I've asked what is free cash flow and the answers would be like 682 and 47 so let's see what we got so from basic qu engine what we got is like we got 47 and 682 so it f the right information but uh I think the sentencing is not the free cash flow for the first quarter of which is a decrease of 682 million compared to the same period I think the sentencing is not correct it's not decrease of so we'll see how others are giving the answer so for second one I think it's not fetching the right answer it fet like 229 million and something and 15 million which is not the right answer so my second quer is not working well let's see what we get from recursive so from here we got the right information so it just says free cash flow for the finan is decrease of 682 million for the first 3 months of 22 compared to decrease of 47 million for 21 so it got the answer correct also and it interpreted also like this represent a decrease of 635 million but here it's was saying it's a decrease of 680 something so like basic found the answer right but it could not interpret it correctly but I think our recursive F correct information and it interpreted it correctly and gave us a percentage like right percentage also 93.5 so yeah in this I think recursive Works uh the best and these two did not work well so let's see the next question so what is the net loss value to uh Uber compared to last year so this is from this uh yeah net loss attributable to uh Uber Technologies so it should be like 5.9 billion and 108 million so let's see what we get from first basic qu engine so it fed the information correctly like 5,918 million and net loss of 122 I think this is not right I think it FS this information 122 which is not as it should be 108 so I think your basic did not work right for both let's see how my second one worked so yeah it gave 5.9 billion and 108 this is right and recursive also it gave the right information so yeah these two work well for this and this is my next question what were cash flows like from investing activities so let's see the temple so you have cash flow from investing activity and these are the sub activities and the final cash flow like 250 and 135 so this should be so I think basic arang just F the table only it did not accept information so till now I think basic is not working well I think it worked well in only one question let's see how this second one worked so it's giving me 135 million primally consisting 60 purchase of 55 I think it's giving the breakup also and net Cas us was 15 million consisting 803 million in purchase of 336 million like this so yeah it's giving very detail also not like not a specific to this question it's what we ask but if you see recursive it's giving a Accord to the given context the cash flows for Investing For first 3 month in 2011 were negative with a net cash of 250 which is this one and 22 the is 135 you can see recursive retri is working well for this question also it F 250 and 135 answers correctly so in all the four questions I think recursive retriever is working the best it's not only extracting the information for a given question but it's framing the answer very well otherwise the other retriever sometimes they're not able to get the right answer sometimes they not able to frame the answers correctly so yeah if you use llama Parts with this recursive retrial engine the way I've have designed it without the summary and using open source Cipher model I think you can get the best result in any of the complex PDF so yeah that's all for today thank you for watching the video please do subscribe and share your feedback thank you
Info
Channel: Tech with Ashish Singh
Views: 3,772
Rating: undefined out of 5
Keywords: llm, zephyr, Chunking strategy, Retrieval Augmented Generation, rag with Zephyr, Rag with Open AI, GenAI, llm rag, LlamaIndex, LangChain, Rag using LlamaIndex, Rag using LangChain, how does rag works, rag projects, what is rag, explain rag, how to create rag, advance rag pipeline, advance rag, rag, open source model, understand rag, rag with open source model, rag with llama2, create rag pipeline, genai, chatgpt, rag on pdf tables, text & tables from pdf, llamaparse
Id: -8rMQRdBb00
Channel Id: undefined
Length: 15min 20sec (920 seconds)
Published: Tue Feb 27 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.