RouterQueryEngine
mistral-cookbookLlamaIndexthird_party
Export
Router Query Engine with Mistral AI and LlamaIndex
A VectorStoreIndex is designed to handle queries related to specific contexts, while a SummaryIndex is optimized for answering summarization queries. However, in real-world scenarios, user queries may require either context-specific responses or summarizations. To address this, the system must effectively route user queries to the appropriate index to provide relevant answers.
In this notebook, we will utilize the RouterQueryEngine to direct user queries to the appropriate index based on the query type.
Installation
[ ]
Setup API Key
[1]
Set LLM and Embedding Model
[2]
[3]
[4]
Download Data
We will use Uber 10K SEC Filings.
[5]
--2024-03-31 00:24:17-- https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/10k/uber_2021.pdf Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.109.133, ... Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1880483 (1.8M) [application/octet-stream] Saving to: ‘data/10k/uber_2021.pdf’ data/10k/uber_2021. 100%[===================>] 1.79M --.-KB/s in 0.05s 2024-03-31 00:24:17 (38.5 MB/s) - ‘data/10k/uber_2021.pdf’ saved [1880483/1880483]
Load Data
[22]
Index and Query Engine creation
- VectorStoreIndex -> Specific context queries
- SummaryIndex -> Summarization queries
[24]
[26]
Create Tools
[27]
Create Router Query Engine
[28]
Querying
Summarization Query
You can see that it uses SummaryIndex to provide answer to the summarization query.
[31]
Selecting query engine 1: This choice specifically mentions a 'summary' of Uber's financials for the year 2021, which directly aligns with the question asked..
In 2021, Uber's Gross Bookings increased by $32.5 billion, a 56% increase compared to 2020. This growth was driven by a 66% increase in Delivery Gross Bookings due to higher demand for food delivery and larger order sizes, as well as expansion in U.S. and international markets. Mobility Gross Bookings also grew by 36% due to increased trip volumes as the business recovered from COVID-19 impacts.
Uber's revenue for the year was $17.5 billion, a 57% increase from the previous year. This growth was attributed to the overall expansion of the Delivery business and an increase in Freight revenue due to the acquisition of Transplace in the fourth quarter of 2021.
The net loss attributable to Uber Technologies, Inc. was $496 million, a 93% improvement from the previous year. This improvement was driven by a $1.6 billion pre-tax gain on the sale of the ATG Business to Aurora, a $1.6 billion pre-tax net benefit related to Uber’s equity investments, as well as reductions in fixed costs and increased variable cost efficiencies. The net loss also included $1.2 billion in stock-based compensation expense.
Adjusted EBITDA loss was $774 million, an improvement of $1.8 billion from 2020. Mobility Adjusted EBITDA profit was $1.6 billion, and Delivery Adjusted EBITDA loss was $348 million, an improvement of $525 million from the previous year.
Uber ended the year with $4.3 billion in cash and cash equivalents. The company also completed several acquisitions in 2021, including the remaining 45% ownership interest in Cornershop and 100% ownership interest in Drizly, an on-demand alcohol marketplace in North America.
Specific Context Query
You can see it uses VectorStoreIndex to answer specific context type query.
[29]
Selecting query engine 0: This choice is more likely to contain detailed financial information about Uber in 2021, including revenue..
The revenue of Uber in 2021 was $17,455 million.