Section Insights
Introduction to RAG with Tables
What are the challenges and methods for retrieving information from documents containing tables?
Lance discusses the importance of tables in various documents and explores methods for retrieving and reasoning over them using large language models (LLMs). He outlines three main approaches: feeding entire documents into LLMs, targeted table extraction, and chunking documents for semantic retrieval.
- Tables are prevalent in many document types, making their retrieval crucial.
- Three main methods for handling tables in LLMs include full document input, targeted extraction, and chunking.
- The choice of method can significantly impact retrieval effectiveness.
Performance of LLMs with Large Contexts
How do different LLMs perform when retrieving information from large documents?
The performance of LLMs like Claude 2.1 and GPT-4 is evaluated with documents around 36,000 tokens. While these models can handle large contexts, retrieval accuracy can degrade based on context length and fact placement within the document.
- LLMs can achieve decent performance with large document contexts, but accuracy may vary.
- Context length and the placement of facts within documents affect retrieval quality.
- Longer contexts can lead to errors in information retrieval.
Challenges in Table Extraction
What are the challenges faced in extracting tables from documents?
Lance highlights the difficulties in consistently extracting tables due to their varied representations in documents. Initial evaluations show promise for table extraction methods, but issues arise when headers are not captured, leading to incorrect answers.
- Table extraction methods show potential but face challenges with consistency.
- Failure to capture headers can result in incorrect answers from LLMs.
- Diversity in table representation complicates extraction efforts.
Effective Chunking Strategies for Tables
What is an effective strategy for chunking documents to retain table integrity?
Lance suggests that chunking documents based on page boundaries can effectively retain tables, achieving a high accuracy of 93%. This simple approach minimizes the need for complex engineering, although it may struggle with multi-page tables.
- Chunking by page boundaries helps maintain table integrity during retrieval.
- This method is simple yet effective, achieving high accuracy.
- Complex tables that span multiple pages may still pose challenges.
Ensemble Retrieval for Improved Accuracy
How can ensemble retrieval enhance the accuracy of information synthesis from tables?
By creating a table retriever that prioritizes pages containing tables, Lance achieved a 97% accuracy in answer synthesis. This method combines table summaries with general page retrieval, ensuring relevant table information is included in responses.
- Ensemble retrieval can significantly improve answer accuracy by prioritizing relevant information.
- Combining table summaries with general retrieval methods enhances synthesis quality.
- Achieving high accuracy requires careful consideration of document retrieval strategies.
Transcript
0:04 hey this is Lance from Lang chain I want to share some results that we've recently working on related to rag over documents that contain a kind of a mixture of texts and tables the motivation here is that tables are present in a wide range of documents Financial reports earnings reports things along those lines academic papers white papers technical manuals so tables kind of present all over and the question is if I want to do retrieval or reasoning over
0:36 tables how best can actually send these into the context window of an llm and there's a few approaches that you can imagine that have been also reported so one option is well we have some llms that have very large context Windows up to 100,000 tokens or up to hundreds of pages we can imagine just taking documents that contain tables and St stuffing them in together so the text as well as tables kind of just just are fed in
1:07 directly there's also a set of methods that try to perform some kind of targeted table extraction we'll talk a little bit more about that later on but the idea here is you actually look at the document you try to identify table elements you extract them you pass those into the llm in kind of a more targeted way and the third which is very common for rag in general is you take documents you split them based upon some kind of
1:31 chunk size and you pass those chunks into first the vector store with embedding in order to basically make them easily retrievable and you build an application that can very easily retrieve based on semetic similarity to your question documents and then you document chunks and you send those into the llm context window so option one just take full documents with tables stuff them into the context window of a large llm option two try to extract the
2:03 table specifically option three try to take documents split them up and then kind of do chunk based retrieval on chunks that also contain tables so to evaluate these different options we built a public Langs Smith Benchmark so Langs Smith is our platform that allows for tracing evaluation and other kinds of like observability monitoring and evaluation and what he did here
2:34 is we took four earnings reports from data dog Microsoft Google Amazon from Q3 2023 so they're kind of recent they're kind of of of some interest and two random white papers the white papers just contained a mixture of tables and text and we can see that in particular the earnings reports contain lots of inting tables and they're typically pretty dense you can see some examples here of like kind of segment information as well as
3:05 Revenue operating income from Google on the left here we built 30 questions from these documents and lsmith allows us to basically automate evaluation so we have all these question answer pairs that we've built 30 of them and we have our different approaches for reasoning over these do documents be it chunk based rag long context LMS and what we can do is for every
3:36 question we can get the kind of chain generated answer we can compare that to the ground truth answer you can kind of see this happens at stage three and then lmth is very nice cap abilities to compare those results across many runs debug what's going on and kind of root cause so that's kind of the approach build a small Benchmark 30 questions and we're going to take our different approaches for rag across tables and run an evaluation on this
4:05 data set so let's look at stuffing documents into long context llms first what we see here is the y- AIS shows you the percentage of questions that are correct and the x-axis shows you different approaches so we tested Claud 2.1 and gp4 128k now these documents combined were not that big they're around 36,000 tokens so
4:37 they don't go to the full capacity of these models which are around 100,000 128,000 tokens but it's still reasonably large it's not something you could just stuff into like for example Baseline GPD 4 depending on the model you're using 8K 32k kind of exceeds those typical bounds a bit so you do need these longer context LMS for the for this concatenated set of documents that contain all of our tables and we can see is you can get
5:06 decent performance now the nice thing is this is very simple you do almost no work and you can get for example with GPT gp4 72% correct it's not bad especially given these are kind of very dense Financial tables now there's been some interesting work this is from Greg camand that has shown that the ability to factually retrieve information from context of these
5:37 models depends upon the context length as well as the fact placement depth and what Greg showed is that for example as this is with gp4 128k as the the context length gets greater so like as your your passing a much longer context into these llms there are errors and he did
6:07 this by placing a single fact in the sea of context at different locations and then asking can you retrieve that so you can see that there are these issues with retrieval quality with respect to both the length and the placement depth in documents so that's kind of a thing to flag with these long context approaches you can see degradation particularly as your context window gets longer as your as the the fact placement is
6:39 more Central in the document so here's our results looking at our documents so again our context is around 36,000 tokens so not huge but again not particularly small not easily fit into like into more some of the common llms that folks use and we do see kind of a cluster of failures kind of in the middle of the
7:09 document and then this this is a heat map I don't show the color bar here but this dark indicates there's three failures kind of in this region this is one particular table pertaining to Amazon where we continually get a number of questions wrong a few others here so it it would be hard to make strong claims about the impact of placement depth on these errors more would have to be kind of studied there to really be certain about that but it
7:36 is worth noting that if you take documents along these lines which have very dense tables you send them to a long context L you can get these retrieval failures that may or may not be easy to understand they may relate to what Greg showed kind of in depth here it may depend on the context length that you're passing in as well as like kind of where they are in the document we saw that there's a bunch of saor kind of in
7:59 the middle here and maybe that's kind of a result that is consistent with some other reports showing you can get these kind of lost in the middle type effects where retrieval kind of gets worse as it enters the middle of the document but in any case I think more would have to be really kind of dug into here but it does show that you can't necessarily expect very high performance by just passing in very large context and hoping to get
8:24 really really high quality question answering over tables so that's kind of observation one now observation two is you can try targeted table extraction methods and there's a number of them the main intuition is this is table Transformer from Microsoft you try to do some kind of table detection looking at the document seeing where the tables are trying to extract the different columns rows and kind of pull these tables out of documents in some kind of structured
8:55 way a number of different apis doc offers some things for this unstructured offers things for this they are it's an interesting class of methods we are actually going to follow up in more detail on evaluations here we have done some initial rounds of evaluation and one of the things I can flag currently is that these methods have a high ceiling most likely it's very promising to think about the ability to Tech tables pull them out particularly
9:24 for really complex tables in practice what we did see is that because tables represented in many different ways in different documents consistency of extraction is a challenge so for example one thing we saw in particular is that this is one of the example tables from the Amazon document we saw that some of these methods actually failed to grab the the the header columns and so none of the questions could be answered correctly
9:55 because the llm did not receive these headers so didn't know how to reason about this information so in any case I think the intuition here is that table extraction methods are absolutely interesting to consider they require like kind of more sophisticated methods they may be trickier and they may suffer from failure modes due to the diversity of table representations that we actually encounter in real world documents so we're going to have more evaluations on this we're doing some
10:25 work with unstructured as well as dyami on these topics and so we will provide some more evaluations here in the future but I want to just kind of give a flavor that these methods have a pretty high ceiling but there's also some challenges related to the kind of the diversity of of kind of table representation that you might see in real world documents so we kind of wanted to move ahead to chunking now chunking something a lot of
10:54 people are pretty familiar with it's been very common in rag to take documents to chunk them up because context windows are limited you can't just send all your documents into an LM at once in for many cases and so this idea of chunking and then retrieving chunks based on centic similarity to a question is like a very popular appealing approach now here's the results and I'll kind of walk through this in a little bit more detail but we see an
11:21 interesting Trend here so we start with a pretty small chunk size 50 tokens so you know four characters token maybe 200 characters and roughly here and you can see performance is really bad and as you bump up the chunk size you can see performance gets better and better and better until we get to this page splits which I'll explain later and this Ensemble thing which I'll also explain later but let's kind of zoom in on the
11:46 this 50 token result and kind of get some intuition here so Greg Cameron also recently put out chunk fiz it's a really nice kind of UI just for visualization of of of chunking strategies on different kind of input documents so I took one of our tables I input it here and then I set the chunk size to 200 characters which corresponds to 50 tokens which is our first you can see this table gets split up entirely by
12:15 the chunk by the chunking approach which very much explains why you have such poor retrieval results because if you take a table and you break it up in different chunks you're unlikely to retrieve all those chunks and reconstitute them such that the LM can reason about that whole table kind of together and this is kind of the a main intuition for the chunking strategy is we want to try to design chunks such that they retain full tables
12:44 now of course this is what we were also trying to do previously with our discussion about table extraction table extraction is kind of the the probably the most exact highest performance in way of doing this re actually should try to detect tables and isolate them extract them individually chunking you're trying to kind of guess based on chunk size what is going to capture tables and which which is not and that's obviously hard to do we can see in this
13:10 extreme case small chunks are very likely to break up nearly all their tables and that's a bad thing of course but one thing we found which is kind of very obvious in retrospect is that in many cases tables honor the semantic boundaries of pages which people kind of have have used to you know improve readability for documents so for example there absolutely are many cases of of tables that span many pages but of course this does hurt readability for
13:40 the table and a lot of documents at least we are focused on for this noal study did not contain those kind of multiple page spanning tables and so the approach here is very simple if you just build your splits based upon page boundaries it actually retains your tables pretty well and so then all you're doing is you're taking a page embedding that page of text and then retrieving based upon that embedding and then sending that that particular
14:09 page to the LM in practice this got us 93% accuracy so quite strong extremely simple approach and I I completely acknowledge that this will break down in cases of complex tables that span many pages and it may also break down for other types of complex tables that were not captured in this evaluation set but I do want to flag that this is an extremely simple approach we found it to be actually quite performant and it requires very
14:41 little specialized engineering you know unlike for example using some method to extract the tables individually or even like a longer context llm which is kind of not accessible to many people more expensive this is very simple you take your document you basically embed each page and then you retrieve Pages pass them to the llm for final answer summarization synthesis those pages typically en capsulate tables pretty effectively for many documents in particular the ones that we we covered here so using
15:13 these natural page boundaries actually did work really well in practice just for these kind of simple documents that we are working with now there was a problem though we looked at some of the failures for the you know the the proty showed it got up to 93% but of course there's still some headro for improvement there and we saw this so here was one of the questions that failed and it failed because it did not retrieve the page with the table it
15:43 retrieved a number of other pages that discussed what we were interested in so the question pertained to the capitalized software development cost for data dog and what we found is that particular statement was present lots of the text chunks outside of the page that contained our table and so what happened is when we did retrieval based on semantic similarity a bunch of those text chunks got retrieved and we did not retrieve the table and so therefore we
16:08 couldn't answer the question so a very simple trick that we kind of find in practice worked really well for this is you basically kind of build two different retrievers and you can Ensemble the results and so what I did here was really simple so I iterate through each page and I built what I call kind of this this it's it's using L change multiv Vector retriever but you can think of this as like a a table
16:35 retriever so what I do is I iterate through each page for every page of the document I ask an LM to tell me does this page contain a table if so summarize it and if not just kind of say there's no table present and what this multiv Vector triv lets you do is let you index those summaries in a vector store so so you can imagine what we have is a bunch of table summaries that an llm has
17:06 generated that link to the corresponding page in the documents so again it's like you have a whole bunch of summaries that you've distilled for every every page that contains a table you have all those summaries index that are retrievable based on symthic similarity and then that raw that full raw page you then can pass the LM for answer synthesis and then of course I combine this with the original just page split Vector store retriever which we had previously and
17:35 with this assemble retriever you can actually do something that's kind of nice you can effectively tell it to prioritize any chunks from one of the two retrievers so in short what I ended up doing is I built this table retriever at top that indexed all the different pages that had tables with some table summary and I combined that with a result result of just the general page retrieval and if there ever is a retrieve document from my table
18:07 retriever I put at the top of the queue in this ensembling and so what this kind of does is if there's ever a table relevant to my question I try to enforce or ensure that we return that because I want to make sure that information is included in the answer synthesis and when you do this that's how I got up to 97% and there still is believe this one question that it's incorrect and that actually had to do with the need to
18:33 retrieve documents across a wide range of the different documents and synthesize them and I'll be following up on that in kind of separate probably separate video or notebook that kind of just addresses how to how to deal with that case but this was kind of the original set of results that we wanted to share and kind of in summary you long comex llms are really nice for getting
19:03 started they do fairly well to be honest you know 72% is actually pretty good for effectively you know very little effort just taking these six documents and stuffing them in if you have smaller context like a single document with tables that probably works very well the caveat is there can be these failure modes with respect to both like the the text length so if I try to send in more tokens like our case was 36,000 if you I
19:34 think as Greg shows in these tables if you try to push up to over 100,000 you can get these this kind of degradation performance and also depending on where the table is in your context you could see degradation there's been reports that in the middle of documents does worse Greg shows actually there seems to be kind of a a lot of failure modes towards the the top of the document so in any case this it's worth more
19:58 investigation but the point is that long long condex llms very easy to get started with have some interesting failure modes with respect to kind of where the table is present in the document so that's kind of point one now point two is that chunking is also quite easy very commonly done the only challenge is you have to ensure that your chunking strategy is not split up tables just kind of very obvious you don't want to break them up because then
20:24 you can't reason about the information present in the table and you can see it these chunk sizes you do certainly break up many of your tables and you and you reduce your answer quality quite significantly in short we found is just simply splitting on page breaks at least retains for ourl set u many of the tables and therefore lets you get pretty good performance up to 93% and a small trick of additional embling just to make sure that you
20:54 always retrieve relevant table chunks if they pertain to the question relative to document chunks is a nice way to kind of boost the performance slightly further and ensure that information from tables does get prioritized if it's relevant to your question and that's really it I think that was all I had for slides and we'll be following up a bit more on approaches that involve targeted table extraction in the future
21:27 thanks
Summary
- Long-context LLMs can process large documents but may face retrieval challenges, especially with dense tables.
- Performance can degrade based on context length and the placement of information within the document.
- Targeted table extraction methods show promise but face challenges due to the diversity of table formats in documents.
- Chunking is a common approach, but care must be taken to avoid splitting tables, which can hinder reasoning.
- Splitting documents by page boundaries retains table integrity and improves retrieval accuracy, achieving up to 93% accuracy.
- An ensemble retrieval strategy that prioritizes table-relevant pages can further enhance performance to 97%.
- Ongoing evaluations will focus on improving targeted table extraction methods and addressing complex table scenarios.
Questions Answered
What are the challenges and methods for retrieving information from documents containing tables?
Lance discusses the importance of tables in various documents and explores methods for retrieving and reasoning over them using large language models (LLMs). He outlines three main approaches: feeding entire documents into LLMs, targeted table extraction, and chunking documents for semantic retrieval.
How do different LLMs perform when retrieving information from large documents?
The performance of LLMs like Claude 2.1 and GPT-4 is evaluated with documents around 36,000 tokens. While these models can handle large contexts, retrieval accuracy can degrade based on context length and fact placement within the document.
What are the challenges faced in extracting tables from documents?
Lance highlights the difficulties in consistently extracting tables due to their varied representations in documents. Initial evaluations show promise for table extraction methods, but issues arise when headers are not captured, leading to incorrect answers.
What is an effective strategy for chunking documents to retain table integrity?
Lance suggests that chunking documents based on page boundaries can effectively retain tables, achieving a high accuracy of 93%. This simple approach minimizes the need for complex engineering, although it may struggle with multi-page tables.
How can ensemble retrieval enhance the accuracy of information synthesis from tables?
By creating a table retriever that prioritizes pages containing tables, Lance achieved a 97% accuracy in answer synthesis. This method combines table summaries with general page retrieval, ensuring relevant table information is included in responses.