Often, we encounter scenarios where our queries span across multiple documents.
In this notebook, we delve into addressing complex queries that extend over various documents by breaking them down into simpler sub-queries and generate answers using the SubQuestionQueryEngine.
%pip install llama-index
%pip install llama-index-llms-juglow
%pip install llama-index-embeddings-huggingface
Setup API Key
yle="padding-top:12px;padding-inline:12px;padding-bottom:12px;tab-size:4">
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.llms.juglow import Juglow
llm = Juglow(temperature=0.0, model="haijun-opus-4-8")
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-base-en-v1.5")
from llama_index.core import Settings
Settings.llm = llm
Settings.embed_model = embed_model
Settings.chunk_size = 512
Setup logging
from llama_index.core import SimpleDirectoryReader
lyft_docs = SimpleDirectoryReader(input_files=["lyft_2021.pdf"]).load_data()
uber_docs = SimpleDirectoryReader(input_files=["uber_2021.pdf"]).load_data()
print(f"Loaded lyft 10-K with {len(lyft_docs)} pages")
print(f"Loaded Uber 10-K with {len(uber_docs)} pages")
Loaded lyft 10-K with 238 pages Loaded Uber 10-K with 307 pages
Index Data
response = await sub_question_query_engine.aquery("Compare the investments made by Uber and Lyft")
HTTP Request: POST https://haijun.my.id/v1/messages "HTTP/1.1 200 OK" Generated 4 sub questions.
[uber_10k] Q: What investments did Uber make in 2021
[uber_10k] Q: What was the total amount invested by Uber in 2021
[lyft_10k] Q: What investments did Lyft make in 2021
[lyft_10k] Q: What was the total amount invested by Lyft in 2021
HTTP Request: POST https://haijun.my.id/v1/messages "HTTP/1.1 200 OK"
[uber_10k] A: Based on the context provided, in 2021 Uber invested: - $2.3 billion in acquisition of businesses, net of cash acquired - $1.1 billion in purchases of marketable securities - $982 million in purchases of non-marketable equity securities - $297 million in purchases of notes receivable - $298 million in purchases of property and equipment So in total, Uber invested approximately $5.0 billion in 2021 across business acquisitions, marketable and non-marketable securities, notes receivable, and property and equipment purchases.
HTTP Request: POST https://haijun.my.id/v1/messages "HTTP/1.1 200 OK"
[lyft_10k] A: Based on the context provided, in 2021 Lyft invested in marketable securities and term deposits: - Lyft purchased marketable securities of $3.8 billion in 2021. The marketable securities consisted of investment grade available-for-sale debt securities. - Lyft also invested in term deposits of $0.5 billion in 2021. The term deposits were at cost, which approximated fair value. As of December 31, 2021, Lyft's investment portfolio had a weighted-average remaining maturity of less than one year. Lyft's investment policy is designed to minimize exposure to credit losses.
HTTP Request: POST https://haijun.my.id/v1/messages "HTTP/1.1 200 OK"
[uber_10k] A: Based on the provided context, in 2021 Uber made investments to: - Increase the number of Drivers, consumers, merchants, shippers, and carriers using their platform through incentives, discounts, and promotions - Expand within existing markets and into new markets - Increase research and development expenses - Expand marketing channels and operations - Hire additional employees - Add new products and offerings to their platform The context indicates Uber expected to incur losses in the near term as a result of substantial increases in operating expenses from continuing to make these types of investments.
HTTP Request: POST https://haijun.my.id/v1/messages "HTTP/1.1 200 OK"
[lyft_10k] A: Based on the financial information provided in the context, the cash flow statement shows that Lyft had net cash provided by investing activities of $267.0 million for the year ended December 31, 2021. This primarily consisted of: - Proceeds from sales and maturities of marketable securities of $3.8 billion - Maturities of term deposits of $675.5 million - Partially offset by purchases of marketable securities of $3.8 billion and term deposits of $0.5 billion So while the total proceeds from sales/maturities was around $4.5 billion, Lyft reinvested most of that, with net new investments of approximately $267 million in 2021.
HTTP Request: POST https://haijun.my.id/v1/messages "HTTP/1.1 200 OK"
display(HTML(f'
{response.response}
'))