Discover LlamaIndex: Ask Complex Queries over Multiple Documents
Key Takeaways
LlamaIndex's SubQuestionQueryEngine allows users to ask complex comparison queries over multiple documents, breaking down queries into sub-questions and executing them on specific data sources.
Full Transcript
hey everyone welcome to discover llama Index this is a new tutorial series that we're starting up to tell you guys all about the latest features of llama index and how you can really use it to supercharge your large language model applications especially when dealing with large amounts of data I'm Simon the co-founder and CTO of llama index and today I'm super excited to tell you guys just a little bit more about our latest feature the sub question query engine before we dive down into the details let's recap at a high level what a query engine is in Lama index a query engine really is a high level natural language interface that we build over your data source so that you can very easily ask a question over your data and extract very nuanced insights out of it now the key challenge in building such a unified query interface over your data is that there's often a wide range of complicated questions that you might want to ask over multiple data sources now for example you might have multiple financial documents and you want to compare and contrast the financial statements of multiple companies over multiple years now just naively combining all those data sources and doing topk retrieval of Chunk documents for a final synthesis is simply not good enough to get a very good and nuanced answers for complex questions now how do we do this the sub question query engine is one step in the direction of answering these complex questions the key intuition is that when you have a complex multi-part question the best way to deal with it is to First decompose it into multiple sub questions that are relevant to specific data sources now for example here we have three data sources and we might want to decompose the question that targets a subset of them first and then combines the response over multiple data sources to get the final answer now this approach really leverages the composability aspect of our framework by first defining sub query engines over each of these data sources and then Define a top level sub question query engine on top now how does this work exactly to start when given an initial complex questions we will use the large language model to generate sub questions given the description of our data sources that are available then we will execute the sub questions on the select data sources and then gather all the sub responses and then lastly we will take all the relevant contacts from these sub sources and synthesize the final answer now let's take a look at this in action to help us do some complex analysis over multiple financial documents which are called 10ks okay now that we have our notebook open we can finally go ahead and play around with some code before I dive down into the notebook let me just show you the data that we'll be working with so we have these two PDFs which are the lift 10K document for 2021 and the Uber document for 2021 so these are fairly large financial documents that I think have oh yeah 307 Pages for this one and 238 Pages for this one so quite a lot of data here and it's very heterogeneous there are texts bullet points and I think a whole bunch of tables where a lot of financial terms are found okay going back to the notebook let's just uh go straight into it by doing some imports we're going to first configure our large language model service um here we're just setting the temperature to zero so the output is more deterministic we're using gpt3 and then basically setting the max token to negative one so that we don't limit the amount of outputs for these models we're going to wrap the Ln predictor into our service context which we'll be using to pass into our indexing query engine now for the first step we're going to use this simple directory reader to read these two files separately so I think this might take a little bit of time since these are 300 Page documents okay now we have the lift 10K loaded 238 documents I think that's correct yep and see how long this takes okay there we go now the next step is to build our indices here we're just going to use the vector store index what is happening under the hood here when we call the index style from document is that each of these documents will be chunked up into text chunks we'll be calling the embedding API to get a dense Vector embedding for each of these chunks and save it to R in-memory Vector store so this takes a little bit of time just because there's a lot of data so in total 500 pages of text that needs to kind of pass through the API calls and get back the responses now okay so we finished building the left 10K index was 379 notes you can see that is a little bit higher than the 238 pages I think most of the pages gets broken to one or two nodes given our default chunk size right now okay many time now just waiting for the Uber index to be built okay there we go now we're going to build individual query engines for each of these indexes here when we do s-query engine what we're really what's really happening under the hood is uh we're setting up the configuration so the query engine knows what to do at great time now the next step is to add sort of the metadata to identify these query engines to the top level sub question query engine here we're just specifying the name of this query Engine 2 and also giving a description so the top level large language model can know how to make use of this data source okay now that we're we have that built we're ready to run some queries the first one that we're going to ask is to compare and contrast the customer segments and geographies that grew the fastest over the lift-in Uber documents so as we run these you should be able to see various sub questions being generated and executed on the sub query engines before synthesizing the final answer okay so we generated four sub questions and the first one is what customer segments grew the fastest for Uber being asked on the Uber 10K documents um you can see a sub response generated another question being asked for the Uber 10K about what geography screw the fastest in 2021 the corresponding responses the customer segments for Lyft and then the geography that grew the fastest foreclosed so one thing to know is that I think given the context here the model actually decided that not possible to answer this question was to give in the context um okay now that all the sub questions have been generated all of these question and answer pairs will be used to create a final response and you can see yeah the large language model is pretty good at kind of stitching together all these information for a final synthesis and that really talks about um the various aspects comparing between lift now just to Showcase another example we can compare the revenue growth of uber and Lyft from 2020 to 2021 this should be a pretty straightforward answer that really just depends on querying the right index using the right sub question so in this case we only needed two sub questions one is the revenue girls of uber being as an Uber document and the revenue growth of lift being asked on lift document and as you can see we have a clear comparison between the two as the final answer where Uber had a higher rate of Revenue growth than left cool that's all hopefully you enjoyed this tutorial
Original Description
In this video, we show how to ask complex comparison queries over multiple documents with LlamaIndex. Specifically, we show how to use our SubQuestionQueryEngine object which can break down complex queries into a query plan over subsets of documents.
LlamaIndex: https://github.com/jerryjliu/llama_index
Docs: https://gpt-index.readthedocs.io/en/latest/
Questions? Hop on our Discord: https://discord.gg/dGcwcsnxhU
Twitter: https://twitter.com/gpt_index
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from LlamaIndex · LlamaIndex · 3 of 60
1
2
▶
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
LlamaIndex Virtual Meetup (May 4th, 2023)
LlamaIndex
LlamaIndex + MongoDB Workshop/Fireside Chat
LlamaIndex
Discover LlamaIndex: Ask Complex Queries over Multiple Documents
LlamaIndex
Discover LlamaIndex: Document Management
LlamaIndex
Discover LlamaIndex: Joint Text to SQL and Semantic Search
LlamaIndex
Discover LlamaIndex: JSON Query Engine
LlamaIndex
LlamaIndex Webinar: Active Retrieval Augmented Generation
LlamaIndex
LlamaIndex Webinar: Demonstrate-Search-Predict (DSP) with Omar Khattab
LlamaIndex
LlamaIndex Sessions: Practical challenges of building a Legal Chatbot over your PDFs
LlamaIndex
LlamaIndex Webinar: Graph Databases, Knowledge Graphs, and RAG with Wey (NebulaGraph)
LlamaIndex
LlamaIndex Webinar: Community Project Showcase (07/07/2023)
LlamaIndex
LlamaIndex Webinar: LLMs for Investment Research (with Didier Lopes, co-founder/CEO at OpenBB)
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development With LLMs (Part 1, LLMs and Prompts)
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development With LLMs (Part 2, Documents and Metadata)
LlamaIndex
Discover LlamaIndex: Key Components to build QA Systems
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 3, Evaluation)
LlamaIndex
LlamaIndex Webinar: From Prompt to Schema Engineering with Pydantic (with @jxnlco)
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 4, Embeddings)
LlamaIndex
Discover LlamaIndex: Custom Retrievers + Hybrid Search
LlamaIndex
LlamaIndex Webinar: Document Metadata and Local Models for Better, Faster Retrieval
LlamaIndex
LlamaIndex Webinar: Build Personalized AI Characters with RealChar
LlamaIndex
LlamaIndex Webinar: Make RAG Production-Ready
LlamaIndex
LlamaIndex Workshop: Building RAG with Knowledge Graphs
LlamaIndex
Discover LlamaIndex: Introduction to Data Agents for Developers
LlamaIndex
LlamaIndex Webinar: Finetuning + RAG
LlamaIndex
Discover LlamaIndex: SEC Insights, End-to-End Guide
LlamaIndex
Discover LlamaIndex: Custom Tools for Data Agents
LlamaIndex
LlamaIndex Sessions: Building a Lending Criteria Chatbot in Production
LlamaIndex
Discover LlamaIndex: Bottoms-Up Development with LLMs (Part 5, Retrievers + Node Postprocessors)
LlamaIndex
LlamaIndex Webinar: How to Win a LLM Hackathon
LlamaIndex
LlamaIndex Webinar: LLM Challenges in Production (w/ Mayo Oshin, AI Jason, Dylan from Starmorph)
LlamaIndex
LlamaIndex Webinar: Agents Showcase!
LlamaIndex
LlamaIndex Webinar: Learn about DSPy
LlamaIndex
LlamaIndex Webinar: Time-based retrieval for RAG (with Timescale)
LlamaIndex
LlamaIndex Webinar: Build/Break/Test LLM Apps Showcase (co-hosted with TrueEra, Pinecone)
LlamaIndex
LlamaIndex Workshop: Evaluation-Driven Development (EDD)
LlamaIndex
LlamaIndex Webinar: Building LLM Apps for Production, Part 1 (co-hosted with Anyscale)
LlamaIndex
LlamaIndex Webinar: Learn about Fine-tuning + RAG (w/ Victoria Lin, author of RA-DIT)
LlamaIndex
LlamaIndex Webinar: What's next for AI after OpenAI Dev Day?
LlamaIndex
Introducing create-llama
LlamaIndex
LlamaIndex Webinar: PrivateGPT - Production RAG with Local Models
LlamaIndex
Multi-modal Retrieval Augmented Generation with LlamaIndex
LlamaIndex
LlamaIndex Webinar: LLaVa Deep Dive
LlamaIndex
A deep dive into Retrieval-Augmented Generation with Llamaindex
LlamaIndex
LlamaIndex Workshop: Multimodal + Advanced RAG Workhop with Gemini
LlamaIndex
LlamaIndex Webinar: Efficient Parallel Function Calling Agents with LLMCompiler
LlamaIndex
Introduction to Query Pipelines (Building Advanced RAG, Part 1)
LlamaIndex
LLMs for Advanced Question-Answering over Tabular/CSV/SQL Data (Building Advanced RAG, Part 2)
LlamaIndex
LlamaIndex Webinar: Advanced Tabular Data Understanding with LLMs
LlamaIndex
Ollama X LlamaIndex Multi-Modal
LlamaIndex
Build Agents from Scratch (Building Advanced RAG, Part 3)
LlamaIndex
LlamaIndex Webinar: Build No-Code RAG with Flowise
LlamaIndex
LlamaIndex Sessions: Practical Tips and Tricks for Productionizing RAG (feat. Sisil @ Jasper)
LlamaIndex
Introduction to LlamaIndex v0.10
LlamaIndex
Build SELF-DISCOVER from Scratch with LlamaIndex
LlamaIndex
Introducing LlamaCloud (and LlamaParse)
LlamaIndex
LlamaIndex Sessions: 12 RAG Pain Points and Solutions
LlamaIndex
LlamaIndex Webinar: RAG Beyond Basic Chatbots
LlamaIndex
A Comprehensive Cookbook for Claude 3
LlamaIndex
LlamaIndex Webinar: RAPTOR - Tree-Structured Indexing and Retrieval
LlamaIndex
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
Designing a Production-Grade RAG System for PDF Question Answering
Medium · AI
ChatGPT vs. Gemini 2.5: Which Brain Fits Your 2026 Stack?
Dev.to AI
I Scored 10,000 Job Listings a Day With GPT-4. Here's What Broke
Dev.to AI
Knowledge Distillation: Fit a Big Model's Smarts Into a Small One
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI