Files
rag-bedrock/2_llama_index_bedrock_kb.ipynb
Simon Suo 6118abe00b wip
2024-04-18 14:17:37 -07:00

893 lines
77 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "markdown",
"id": "6d688c05-4842-46fc-97a5-5ee2882a0aa7",
"metadata": {},
"source": [
"# 2 - Agentic RAG with Bedrock KB and LlamaIndex SubQuestionQueryEngine"
]
},
{
"cell_type": "markdown",
"id": "9da233af-4204-4249-a38f-29aa3fb12e7a",
"metadata": {},
"source": [
"Naive RAG based on top-k search often fail to address complex queries that require reasoning about multiple entities.\n",
"\n",
"In this notebook, we build an agentic RAG system with Bedrock KB and LlamaIndex `SubQuestionQuery Engine`.\n",
"\n",
"Additional resources on `SubQuestionQueryEngine`:\n",
"* tutorial: https://docs.llamaindex.ai/en/stable/examples/query_engine/sub_question_query_engine/\n",
"* API docs: https://docs.llamaindex.ai/en/stable/api_reference/query_engine/sub_question/"
]
},
{
"cell_type": "markdown",
"id": "ab882819-a8a0-4748-8840-e39955c8f96f",
"metadata": {},
"source": [
"### Installation"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3b9d72e0-91ad-403a-aea7-d3812244678b",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: llama-index in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (0.10.30)\n",
"Requirement already satisfied: llama-index-agent-openai<0.3.0,>=0.1.4 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.2.2)\n",
"Requirement already satisfied: llama-index-cli<0.2.0,>=0.1.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.1.12)\n",
"Requirement already satisfied: llama-index-core<0.11.0,>=0.10.30 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.10.30)\n",
"Requirement already satisfied: llama-index-embeddings-openai<0.2.0,>=0.1.5 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.1.7)\n",
"Requirement already satisfied: llama-index-indices-managed-llama-cloud<0.2.0,>=0.1.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.1.5)\n",
"Requirement already satisfied: llama-index-legacy<0.10.0,>=0.9.48 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.9.48)\n",
"Requirement already satisfied: llama-index-llms-openai<0.2.0,>=0.1.13 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.1.15)\n",
"Requirement already satisfied: llama-index-multi-modal-llms-openai<0.2.0,>=0.1.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.1.5)\n",
"Requirement already satisfied: llama-index-program-openai<0.2.0,>=0.1.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.1.5)\n",
"Requirement already satisfied: llama-index-question-gen-openai<0.2.0,>=0.1.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.1.3)\n",
"Requirement already satisfied: llama-index-readers-file<0.2.0,>=0.1.4 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.1.19)\n",
"Requirement already satisfied: llama-index-readers-llama-parse<0.2.0,>=0.1.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index) (0.1.4)\n",
"Requirement already satisfied: openai>=1.14.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-agent-openai<0.3.0,>=0.1.4->llama-index) (1.17.0)\n",
"Requirement already satisfied: PyYAML>=6.0.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (6.0.1)\n",
"Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2.0.29)\n",
"Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (3.9.4)\n",
"Requirement already satisfied: dataclasses-json in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (0.6.4)\n",
"Requirement already satisfied: deprecated>=1.2.9.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.2.14)\n",
"Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.0.8)\n",
"Requirement already satisfied: fsspec>=2023.5.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2024.3.1)\n",
"Requirement already satisfied: httpx in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (0.27.0)\n",
"Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (0.1.18)\n",
"Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.6.0)\n",
"Requirement already satisfied: networkx>=3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (3.3)\n",
"Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (3.8.1)\n",
"Requirement already satisfied: numpy in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.26.4)\n",
"Requirement already satisfied: pandas in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2.2.2)\n",
"Requirement already satisfied: pillow>=9.0.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (10.3.0)\n",
"Requirement already satisfied: requests>=2.31.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (2.31.0)\n",
"Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (8.2.3)\n",
"Requirement already satisfied: tiktoken>=0.3.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (0.6.0)\n",
"Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (4.66.2)\n",
"Requirement already satisfied: typing-extensions>=4.5.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (4.11.0)\n",
"Requirement already satisfied: typing-inspect>=0.8.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (0.9.0)\n",
"Requirement already satisfied: wrapt in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.30->llama-index) (1.16.0)\n",
"Requirement already satisfied: beautifulsoup4<5.0.0,>=4.12.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-readers-file<0.2.0,>=0.1.4->llama-index) (4.12.3)\n",
"Requirement already satisfied: pypdf<5.0.0,>=4.0.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-readers-file<0.2.0,>=0.1.4->llama-index) (4.2.0)\n",
"Requirement already satisfied: striprtf<0.0.27,>=0.0.26 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-readers-file<0.2.0,>=0.1.4->llama-index) (0.0.26)\n",
"Requirement already satisfied: llama-parse<0.5.0,>=0.4.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-readers-llama-parse<0.2.0,>=0.1.2->llama-index) (0.4.0)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.3.1)\n",
"Requirement already satisfied: attrs>=17.3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (23.2.0)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.4.1)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (6.0.5)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.9.4)\n",
"Requirement already satisfied: soupsieve>1.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from beautifulsoup4<5.0.0,>=4.12.3->llama-index-readers-file<0.2.0,>=0.1.4->llama-index) (2.5)\n",
"Requirement already satisfied: pydantic>=1.10 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.7.0)\n",
"Requirement already satisfied: anyio in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (4.3.0)\n",
"Requirement already satisfied: certifi in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (2024.2.2)\n",
"Requirement already satisfied: httpcore==1.* in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.0.5)\n",
"Requirement already satisfied: idna in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.7)\n",
"Requirement already satisfied: sniffio in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.3.1)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.30->llama-index) (0.14.0)\n",
"Requirement already satisfied: click in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.30->llama-index) (8.1.7)\n",
"Requirement already satisfied: joblib in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.4.0)\n",
"Requirement already satisfied: regex>=2021.8.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.30->llama-index) (2023.12.25)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from openai>=1.14.0->llama-index-agent-openai<0.3.0,>=0.1.4->llama-index) (1.9.0)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.3.2)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.26.18)\n",
"Requirement already satisfied: greenlet!=0.4.17 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.0.3)\n",
"Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.0.0)\n",
"Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.30->llama-index) (3.21.1)\n",
"Requirement already satisfied: python-dateutil>=2.8.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.9.0.post0)\n",
"Requirement already satisfied: pytz>=2020.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (2024.1)\n",
"Requirement already satisfied: tzdata>=2022.7 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (2024.1)\n",
"Requirement already satisfied: packaging>=17.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.30->llama-index) (24.0)\n",
"Requirement already satisfied: annotated-types>=0.4.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.30->llama-index) (0.6.0)\n",
"Requirement already satisfied: pydantic-core==2.18.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.30->llama-index) (2.18.1)\n",
"Requirement already satisfied: six>=1.5 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.30->llama-index) (1.16.0)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"Requirement already satisfied: llama-index-llms-bedrock in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (0.1.6)\n",
"Requirement already satisfied: boto3<2.0.0,>=1.34.26 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-llms-bedrock) (1.34.85)\n",
"Requirement already satisfied: llama-index-core<0.11.0,>=0.10.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-llms-bedrock) (0.10.30)\n",
"Requirement already satisfied: llama-index-llms-anthropic<0.2.0,>=0.1.7 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-llms-bedrock) (0.1.10)\n",
"Requirement already satisfied: botocore<1.35.0,>=1.34.85 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from boto3<2.0.0,>=1.34.26->llama-index-llms-bedrock) (1.34.85)\n",
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from boto3<2.0.0,>=1.34.26->llama-index-llms-bedrock) (1.0.1)\n",
"Requirement already satisfied: s3transfer<0.11.0,>=0.10.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from boto3<2.0.0,>=1.34.26->llama-index-llms-bedrock) (0.10.1)\n",
"Requirement already satisfied: PyYAML>=6.0.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (6.0.1)\n",
"Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (2.0.29)\n",
"Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (3.9.4)\n",
"Requirement already satisfied: dataclasses-json in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (0.6.4)\n",
"Requirement already satisfied: deprecated>=1.2.9.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.2.14)\n",
"Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.0.8)\n",
"Requirement already satisfied: fsspec>=2023.5.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (2024.3.1)\n",
"Requirement already satisfied: httpx in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (0.27.0)\n",
"Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (0.1.18)\n",
"Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.6.0)\n",
"Requirement already satisfied: networkx>=3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (3.3)\n",
"Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (3.8.1)\n",
"Requirement already satisfied: numpy in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.26.4)\n",
"Requirement already satisfied: openai>=1.1.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.17.0)\n",
"Requirement already satisfied: pandas in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (2.2.2)\n",
"Requirement already satisfied: pillow>=9.0.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (10.3.0)\n",
"Requirement already satisfied: requests>=2.31.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (2.31.0)\n",
"Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (8.2.3)\n",
"Requirement already satisfied: tiktoken>=0.3.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (0.6.0)\n",
"Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (4.66.2)\n",
"Requirement already satisfied: typing-extensions>=4.5.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (4.11.0)\n",
"Requirement already satisfied: typing-inspect>=0.8.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (0.9.0)\n",
"Requirement already satisfied: wrapt in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.16.0)\n",
"Requirement already satisfied: anthropic<0.24.0,>=0.23.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (0.23.1)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.3.1)\n",
"Requirement already satisfied: attrs>=17.3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (23.2.0)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.4.1)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (6.0.5)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.9.4)\n",
"Requirement already satisfied: anyio<5,>=3.5.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from anthropic<0.24.0,>=0.23.1->llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (4.3.0)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from anthropic<0.24.0,>=0.23.1->llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (1.9.0)\n",
"Requirement already satisfied: pydantic<3,>=1.9.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from anthropic<0.24.0,>=0.23.1->llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (2.7.0)\n",
"Requirement already satisfied: sniffio in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from anthropic<0.24.0,>=0.23.1->llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (1.3.1)\n",
"Requirement already satisfied: tokenizers>=0.13.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from anthropic<0.24.0,>=0.23.1->llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (0.19.0)\n",
"Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from botocore<1.35.0,>=1.34.85->boto3<2.0.0,>=1.34.26->llama-index-llms-bedrock) (2.9.0.post0)\n",
"Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from botocore<1.35.0,>=1.34.85->boto3<2.0.0,>=1.34.26->llama-index-llms-bedrock) (1.26.18)\n",
"Requirement already satisfied: certifi in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (2024.2.2)\n",
"Requirement already satisfied: httpcore==1.* in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.0.5)\n",
"Requirement already satisfied: idna in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (3.7)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (0.14.0)\n",
"Requirement already satisfied: click in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (8.1.7)\n",
"Requirement already satisfied: joblib in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.4.0)\n",
"Requirement already satisfied: regex>=2021.8.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (2023.12.25)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (3.3.2)\n",
"Requirement already satisfied: greenlet!=0.4.17 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (3.0.3)\n",
"Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (1.0.0)\n",
"Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (3.21.1)\n",
"Requirement already satisfied: pytz>=2020.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (2024.1)\n",
"Requirement already satisfied: tzdata>=2022.7 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (2024.1)\n",
"Requirement already satisfied: packaging>=17.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.1->llama-index-llms-bedrock) (24.0)\n",
"Requirement already satisfied: annotated-types>=0.4.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pydantic<3,>=1.9.0->anthropic<0.24.0,>=0.23.1->llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (0.6.0)\n",
"Requirement already satisfied: pydantic-core==2.18.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pydantic<3,>=1.9.0->anthropic<0.24.0,>=0.23.1->llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (2.18.1)\n",
"Requirement already satisfied: six>=1.5 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.35.0,>=1.34.85->boto3<2.0.0,>=1.34.26->llama-index-llms-bedrock) (1.16.0)\n",
"Requirement already satisfied: huggingface-hub<1.0,>=0.16.4 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from tokenizers>=0.13.0->anthropic<0.24.0,>=0.23.1->llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (0.22.2)\n",
"Requirement already satisfied: filelock in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic<0.24.0,>=0.23.1->llama-index-llms-anthropic<0.2.0,>=0.1.7->llama-index-llms-bedrock) (3.13.4)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"Requirement already satisfied: llama-index-embeddings-bedrock in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (0.1.4)\n",
"Requirement already satisfied: boto3<2.0.0,>=1.34.23 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-embeddings-bedrock) (1.34.85)\n",
"Requirement already satisfied: llama-index-core<0.11.0,>=0.10.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-embeddings-bedrock) (0.10.30)\n",
"Requirement already satisfied: botocore<1.35.0,>=1.34.85 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from boto3<2.0.0,>=1.34.23->llama-index-embeddings-bedrock) (1.34.85)\n",
"Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from boto3<2.0.0,>=1.34.23->llama-index-embeddings-bedrock) (1.0.1)\n",
"Requirement already satisfied: s3transfer<0.11.0,>=0.10.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from boto3<2.0.0,>=1.34.23->llama-index-embeddings-bedrock) (0.10.1)\n",
"Requirement already satisfied: PyYAML>=6.0.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (6.0.1)\n",
"Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2.0.29)\n",
"Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (3.9.4)\n",
"Requirement already satisfied: dataclasses-json in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (0.6.4)\n",
"Requirement already satisfied: deprecated>=1.2.9.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.2.14)\n",
"Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.0.8)\n",
"Requirement already satisfied: fsspec>=2023.5.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2024.3.1)\n",
"Requirement already satisfied: httpx in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (0.27.0)\n",
"Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (0.1.18)\n",
"Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.6.0)\n",
"Requirement already satisfied: networkx>=3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (3.3)\n",
"Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (3.8.1)\n",
"Requirement already satisfied: numpy in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.26.4)\n",
"Requirement already satisfied: openai>=1.1.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.17.0)\n",
"Requirement already satisfied: pandas in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2.2.2)\n",
"Requirement already satisfied: pillow>=9.0.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (10.3.0)\n",
"Requirement already satisfied: requests>=2.31.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2.31.0)\n",
"Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (8.2.3)\n",
"Requirement already satisfied: tiktoken>=0.3.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (0.6.0)\n",
"Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (4.66.2)\n",
"Requirement already satisfied: typing-extensions>=4.5.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (4.11.0)\n",
"Requirement already satisfied: typing-inspect>=0.8.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (0.9.0)\n",
"Requirement already satisfied: wrapt in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.16.0)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.3.1)\n",
"Requirement already satisfied: attrs>=17.3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (23.2.0)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.4.1)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (6.0.5)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.9.4)\n",
"Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from botocore<1.35.0,>=1.34.85->boto3<2.0.0,>=1.34.23->llama-index-embeddings-bedrock) (2.9.0.post0)\n",
"Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from botocore<1.35.0,>=1.34.85->boto3<2.0.0,>=1.34.23->llama-index-embeddings-bedrock) (1.26.18)\n",
"Requirement already satisfied: pydantic>=1.10 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2.7.0)\n",
"Requirement already satisfied: anyio in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (4.3.0)\n",
"Requirement already satisfied: certifi in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2024.2.2)\n",
"Requirement already satisfied: httpcore==1.* in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.0.5)\n",
"Requirement already satisfied: idna in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (3.7)\n",
"Requirement already satisfied: sniffio in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.3.1)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (0.14.0)\n",
"Requirement already satisfied: click in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (8.1.7)\n",
"Requirement already satisfied: joblib in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.4.0)\n",
"Requirement already satisfied: regex>=2021.8.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2023.12.25)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from openai>=1.1.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.9.0)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (3.3.2)\n",
"Requirement already satisfied: greenlet!=0.4.17 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (3.0.3)\n",
"Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (1.0.0)\n",
"Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (3.21.1)\n",
"Requirement already satisfied: pytz>=2020.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2024.1)\n",
"Requirement already satisfied: tzdata>=2022.7 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2024.1)\n",
"Requirement already satisfied: packaging>=17.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (24.0)\n",
"Requirement already satisfied: annotated-types>=0.4.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (0.6.0)\n",
"Requirement already satisfied: pydantic-core==2.18.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.1->llama-index-embeddings-bedrock) (2.18.1)\n",
"Requirement already satisfied: six>=1.5 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.35.0,>=1.34.85->boto3<2.0.0,>=1.34.23->llama-index-embeddings-bedrock) (1.16.0)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"Requirement already satisfied: llama-index-retrievers-bedrock in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (0.1.1)\n",
"Requirement already satisfied: llama-index-core<0.11.0,>=0.10.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-retrievers-bedrock) (0.10.30)\n",
"Requirement already satisfied: PyYAML>=6.0.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (6.0.1)\n",
"Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2.0.29)\n",
"Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (3.9.4)\n",
"Requirement already satisfied: dataclasses-json in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (0.6.4)\n",
"Requirement already satisfied: deprecated>=1.2.9.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.2.14)\n",
"Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.0.8)\n",
"Requirement already satisfied: fsspec>=2023.5.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2024.3.1)\n",
"Requirement already satisfied: httpx in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (0.27.0)\n",
"Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.18 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (0.1.18)\n",
"Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.6.0)\n",
"Requirement already satisfied: networkx>=3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (3.3)\n",
"Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (3.8.1)\n",
"Requirement already satisfied: numpy in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.26.4)\n",
"Requirement already satisfied: openai>=1.1.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.17.0)\n",
"Requirement already satisfied: pandas in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2.2.2)\n",
"Requirement already satisfied: pillow>=9.0.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (10.3.0)\n",
"Requirement already satisfied: requests>=2.31.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2.31.0)\n",
"Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (8.2.3)\n",
"Requirement already satisfied: tiktoken>=0.3.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (0.6.0)\n",
"Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (4.66.2)\n",
"Requirement already satisfied: typing-extensions>=4.5.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (4.11.0)\n",
"Requirement already satisfied: typing-inspect>=0.8.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (0.9.0)\n",
"Requirement already satisfied: wrapt in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.16.0)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.3.1)\n",
"Requirement already satisfied: attrs>=17.3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (23.2.0)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.4.1)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (6.0.5)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.9.4)\n",
"Requirement already satisfied: pydantic>=1.10 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2.7.0)\n",
"Requirement already satisfied: anyio in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (4.3.0)\n",
"Requirement already satisfied: certifi in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2024.2.2)\n",
"Requirement already satisfied: httpcore==1.* in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.0.5)\n",
"Requirement already satisfied: idna in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (3.7)\n",
"Requirement already satisfied: sniffio in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.3.1)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (0.14.0)\n",
"Requirement already satisfied: click in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (8.1.7)\n",
"Requirement already satisfied: joblib in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.4.0)\n",
"Requirement already satisfied: regex>=2021.8.3 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2023.12.25)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from openai>=1.1.0->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.9.0)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (3.3.2)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.26.18)\n",
"Requirement already satisfied: greenlet!=0.4.17 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (3.0.3)\n",
"Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.0.0)\n",
"Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (3.21.1)\n",
"Requirement already satisfied: python-dateutil>=2.8.2 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2.9.0.post0)\n",
"Requirement already satisfied: pytz>=2020.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2024.1)\n",
"Requirement already satisfied: tzdata>=2022.7 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2024.1)\n",
"Requirement already satisfied: packaging>=17.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (24.0)\n",
"Requirement already satisfied: annotated-types>=0.4.0 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (0.6.0)\n",
"Requirement already satisfied: pydantic-core==2.18.1 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.18->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (2.18.1)\n",
"Requirement already satisfied: six>=1.5 in /Users/suo/dev/odr-poc/.env/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.0->llama-index-retrievers-bedrock) (1.16.0)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install llama-index\n",
"%pip install llama-index-llms-bedrock\n",
"%pip install llama-index-embeddings-bedrock\n",
"%pip install llama-index-retrievers-bedrock"
]
},
{
"cell_type": "markdown",
"id": "678a6063-1d28-4cf4-88fb-01da46f6bb40",
"metadata": {},
"source": [
"### Pre-req: Created Amazon Bedrock KB"
]
},
{
"cell_type": "markdown",
"id": "25106c68-09bf-45f6-8dcb-8103ff6977f6",
"metadata": {},
"source": [
"Here, you should have a running Amazon Bedrock KB. To create one, either:\n",
"1. via the AWS managment console, or\n",
"2. programmatically following this guide: https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/02_KnowledgeBases_and_RAG/0_create_ingest_documents_test_kb.ipynb\n",
"\n",
"Note down the knowledge base ID."
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "5c44a586-f843-45e6-8cf8-6ba466f03ed2",
"metadata": {},
"outputs": [],
"source": [
"knowledge_base_id = \"JQXQKUAFMZ\""
]
},
{
"cell_type": "markdown",
"id": "55c5a903-fdcb-4326-a0d4-8e44e2895e91",
"metadata": {},
"source": [
"### Setup and imports"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "c19fc0a8-06fc-435c-9298-5632d81902e9",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core import Settings\n",
"from llama_index.core.query_engine import RetrieverQueryEngine\n",
"from llama_index.core.tools import QueryEngineTool, ToolMetadata\n",
"from llama_index.core.response.pprint_utils import pprint_response\n",
"\n",
"from llama_index.retrievers.bedrock import AmazonKnowledgeBasesRetriever\n",
"from llama_index.llms.bedrock import Bedrock\n",
"from llama_index.embeddings.bedrock import BedrockEmbedding"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "487a6e1d-f211-46bb-acb1-850eb31602b3",
"metadata": {},
"outputs": [],
"source": [
"llm = Bedrock(model = \"anthropic.claude-v2\")\n",
"embed_model = BedrockEmbedding(model = \"amazon.titan-embed-text-v1\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "2ab469e8-245d-4cf5-a385-23f2046b99fb",
"metadata": {},
"outputs": [],
"source": [
"Settings.llm = llm\n",
"Settings.embed_model = embed_model\n",
"Settings.chunk_size = 1024"
]
},
{
"cell_type": "markdown",
"id": "37b1b2d4-1d1a-4b8a-8077-d77bdf11befb",
"metadata": {},
"source": [
"### Setup agentic RAG with SubQuestionQueryEngine"
]
},
{
"cell_type": "markdown",
"id": "0c5808d6-41ad-44f1-894e-40f017f923d1",
"metadata": {},
"source": [
"We setup separate retriever & query engine for Uber and Lyft via metadata filters."
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "d45ec59f-5e59-40ca-8016-e2d3796ff9fa",
"metadata": {},
"outputs": [],
"source": [
"top_k = 4\n",
"search_mode = \"HYBRID\""
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "09dbcf64-181a-46a7-ab10-3c2b250c859f",
"metadata": {},
"outputs": [],
"source": [
"lyft_fname = \"lyft_2021.pdf\"\n",
"lyft_retriever = AmazonKnowledgeBasesRetriever(\n",
" knowledge_base_id=knowledge_base_id,\n",
" retrieval_config={\n",
" \"vectorSearchConfiguration\": {\n",
" \"numberOfResults\": top_k,\n",
" \"overrideSearchType\": search_mode,\n",
" \"filter\": {\"equals\": {\"key\": \"file_name\", \"value\": lyft_fname}},\n",
" }\n",
" },\n",
")\n",
"lyft_engine = RetrieverQueryEngine(retriever=lyft_retriever)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "8e5c7d0a-4760-4f06-9f36-10193c55ecfe",
"metadata": {},
"outputs": [],
"source": [
"uber_fname = \"uber_2021.pdf\"\n",
"uber_retriever = AmazonKnowledgeBasesRetriever(\n",
" knowledge_base_id=knowledge_base_id,\n",
" retrieval_config={\n",
" \"vectorSearchConfiguration\": {\n",
" \"numberOfResults\": top_k,\n",
" \"overrideSearchType\": search_mode,\n",
" \"filter\": {\"equals\": {\"key\": \"file_name\", \"value\": uber_fname}},\n",
" }\n",
" },\n",
")\n",
"uber_engine = RetrieverQueryEngine(retriever=uber_retriever)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "3872f957-68ce-45dc-a152-62e64ac31702",
"metadata": {},
"outputs": [],
"source": [
"tools = [\n",
" QueryEngineTool(\n",
" query_engine=lyft_engine,\n",
" metadata=ToolMetadata(\n",
" name=\"lyft_2021\",\n",
" description=\"10K filing for Lyft 2021\",\n",
" ),\n",
" ),\n",
" QueryEngineTool(\n",
" query_engine=uber_engine,\n",
" metadata=ToolMetadata(\n",
" name=\"uber_2021\",\n",
" description=\"10K filing for Uber 2021\",\n",
" ),\n",
" ),\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "8c388cbc-24aa-40ad-9a38-3e4497b6df93",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.query_engine import SubQuestionQueryEngine"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "9a961416-717e-4bc1-bf19-c78e9b4ee554",
"metadata": {},
"outputs": [],
"source": [
"query_engine = SubQuestionQueryEngine.from_defaults(\n",
" query_engine_tools=tools,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "89f84afc-eba2-4d55-9b7f-71f00f51ce0a",
"metadata": {},
"source": [
"### Run queries"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "8e1947b9-b218-4a9f-ab46-91b59bc7e214",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generated 2 sub questions.\n",
"\u001b[1;3;38;2;237;90;200m[uber_2021] Q: What was Uber's revenue growth from 2020 to 2021?\n",
"\u001b[0m\u001b[1;3;38;2;237;90;200m[uber_2021] A: Based on the context provided, Uber's revenue grew 57% from 2020 to 2021. Specifically, the context states:\n",
"\n",
"Revenue increased $6.3 billion, or 57%, primarily attributable to an increase in Gross Bookings of 56%, or 53% on a constant currency basis.\n",
"\n",
"And later: \n",
"\n",
"Revenue was $17.5 billion, or up 57% year-over-year, reflecting the overall growth in our Delivery business and an increase in Freight revenue attributable to the acquisition of Transplace in the fourth quarter of 2021 as well as growth in the number of shippers and carriers on the network combined with an increase in volumes with our top shippers.\n",
"\n",
"So Uber's revenue grew by 57% from 2020 to 2021.\n",
"\u001b[0m\u001b[1;3;38;2;90;149;237m[lyft_2021] Q: What was Lyft's revenue growth from 2020 to 2021?\n",
"\u001b[0m\u001b[1;3;38;2;90;149;237m[lyft_2021] A: Based on the provided context, Lyft's revenue in 2021 was $3.2 billion, an increase of 36% compared to revenue of $2.4 billion in 2020. Specifically, the context states:\n",
"\n",
"\"Revenue in 2021 was $3,208 million, an increase of $836 million, or 36%, from $2,372 million in 2020. The increase in revenue was primarily due to growth in Active Riders as recovery from the COVID-19 pandemic continued and demand for our multimodal offerings increased.\"\n",
"\n",
"This indicates that Lyft's revenue grew by 36% from 2020 to 2021.\n",
"\u001b[0m"
]
}
],
"source": [
"response = await query_engine.aquery('Compare revenue growth of Uber and Lyft from 2020 to 2021')"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "6f37234d-9322-48f4-b03f-d034757716ab",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Final Response: Based on the provided context, Uber's revenue grew by\n",
"57% from 2020 to 2021, increasing from $11.1 billion to $17.5 billion.\n",
"Lyft's revenue grew by 36% over the same period, increasing from $2.4\n",
"billion in 2020 to $3.2 billion in 2021. In summary, Uber\n",
"experienced higher revenue growth compared to Lyft from 2020 to 2021,\n",
"with Uber's revenue growing by 57% compared to 36% growth for Lyft.\n",
"However, both companies saw strong revenue growth during this period\n",
"as demand recovered from the COVID-19 pandemic.\n",
"______________________________________________________________________\n",
"Source Node 1/10\n",
"Node ID: ae3edb68-3448-43c9-a502-4824137c3112\n",
"Similarity: None\n",
"Text: Sub question: What was Uber's revenue growth from 2020 to 2021?\n",
"Response: Based on the context provided, Uber's revenue grew 57% from\n",
"2020 to 2021. Specifically, the context states: Revenue increased\n",
"$6.3 billion, or 57%, primarily attributable to an increase in Gross\n",
"Bookings of 56%, or 53% on a constant currency basis. And later:\n",
"Revenue w...\n",
"______________________________________________________________________\n",
"Source Node 2/10\n",
"Node ID: 2911d1c5-b298-4149-99c1-cba26b2c677d\n",
"Similarity: None\n",
"Text: Sub question: What was Lyft's revenue growth from 2020 to 2021?\n",
"Response: Based on the provided context, Lyft's revenue in 2021 was\n",
"$3.2 billion, an increase of 36% compared to revenue of $2.4 billion\n",
"in 2020. Specifically, the context states: \"Revenue in 2021 was\n",
"$3,208 million, an increase of $836 million, or 36%, from $2,372\n",
"million in 2020....\n",
"______________________________________________________________________\n",
"Source Node 3/10\n",
"Node ID: 9840ec83-4447-42f3-a173-111d35e0cc1f\n",
"Similarity: 0.67621344\n",
"Text: | |—%|—%| |Net loss attributable to Uber Technologies, Inc.|\n",
"|(61)%|(3)%| (1) Totals of percentage of revenues may not foot due to\n",
"rounding. ## Comparison of the Years Ended December 31, 2020 and 2021\n",
"|Revenue|Year Ended December 31,|2020|2021|2020 to 2021 % Change|\n",
"|---|---|---|---|---| |Revenue|$11,139|$17,455|57%| | 2021 Compared\n",
"to 2020 ...\n",
"______________________________________________________________________\n",
"Source Node 4/10\n",
"Node ID: ff11ddbd-a4ae-418e-9783-7821f1e7ebc2\n",
"Similarity: 0.67621344\n",
"Text: Delivery We typically expect to experience seasonal increases\n",
"in our revenue in the first and fourth quarters compared to the second\n",
"and third quarters, although the historical growth of Delivery has\n",
"masked these seasonal fluctuations. In 2021, we experienced less\n",
"seasonality as a result of the COVID-19 pandemic and related\n",
"restrictions, which ...\n",
"______________________________________________________________________\n",
"Source Node 5/10\n",
"Node ID: 885e14a5-22ee-48fb-a44c-e8ccde54f7a0\n",
"Similarity: 0.6697111793963709\n",
"Text: Additionally, we saw an increase in Delivery revenue resulting\n",
"from an increase in certain Courier payments and incentives that are\n",
"recorded in cost of revenue, where we are primarily responsible for\n",
"delivery services and pay Couriers for services provided. Mobility\n",
"Gross Bookings grew 36%, on a constant currency basis, from 2020, due\n",
"to increas...\n",
"______________________________________________________________________\n",
"Source Node 6/10\n",
"Node ID: d79b1840-9718-4d49-bf25-23b2105fe698\n",
"Similarity: 0.6695421\n",
"Text: | |Delivery Adjusted EBITDA| |$(873)|$(348)|60%| | |Adjusted\n",
"EBITDA (1), (2)| |$(2,528)|$(774)|69%| | (1) See the section titled\n",
"“Reconciliations of Non-GAAP Financial Measures” for more information\n",
"and reconciliations to the most directly comparable GAAP financial\n",
"measure. (2) See the section titled “Certain Key Metrics and Non-GAAP\n",
"Financial...\n",
"______________________________________________________________________\n",
"Source Node 7/10\n",
"Node ID: fa07fcf1-890c-40e4-994d-0f0e46d658ec\n",
"Similarity: 0.64853275\n",
"Text: became more widely distributed and more communities reopened.\n",
"Revenue in 2021 also benefited from revenues from licensing and data\n",
"access agreements, beginning in the --- ## Cost of Revenue |Year\n",
"Ended December 31|2021|2020|2019|2020 to 2021 % Change|2019 to 2020 %\n",
"Change| |---|---|---|---|---|---| |\n",
"|$1,649,532|$1,447,516|$2,176,469|14%|(33)%|...\n",
"______________________________________________________________________\n",
"Source Node 8/10\n",
"Node ID: cb0de46d-2133-48cc-94c1-a8017d720e39\n",
"Similarity: 0.64853275\n",
"Text: Revenue per Active Rider increased in each of the three months\n",
"periods ended March 31, June 30, September 30, and December 31, 2021\n",
"as compared to the same periods in 2020, primarily reflecting the\n",
"improvement in demand on our platform compared to earlier periods\n",
"during the COVID-19 pandemic, which had materially limited people's\n",
"mobility and se...\n",
"______________________________________________________________________\n",
"Source Node 9/10\n",
"Node ID: 642dde1f-c305-46f7-a867-90b5bf940825\n",
"Similarity: 0.6256318\n",
"Text: Weve made the commitment to reach 100% electric vehicles\n",
"(“EVs”) on the Lyft network by the end of 2030. We believe many users\n",
"are loyal to Lyft because of our values, brand and commitment to\n",
"social and environmental responsibility. Our values, brand and focus\n",
"on customer experience are key differentiators for our business. We\n",
"continue to beli...\n",
"______________________________________________________________________\n",
"Source Node 10/10\n",
"Node ID: 9d723fd6-38be-491d-8fb6-c2dbba7648c5\n",
"Similarity: 0.61033964\n",
"Text: We believe our transportation network offers a viable\n",
"alternative to car ownership. We generate substantially all of our\n",
"revenue from our ridesharing marketplace that connects drivers and\n",
"riders. We collect service fees and commissions from drivers for their\n",
"use of our ridesharing marketplace. As drivers accept more rider leads\n",
"and complete mor...\n"
]
}
],
"source": [
"pprint_response(response, show_source=True)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "941412b8-ee09-4ac7-ae1d-d99c387d7a76",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generated 2 sub questions.\n",
"\u001b[1;3;38;2;237;90;200m[uber_2021] Q: What were the major investments made by Uber in 2021?\n",
"\u001b[0m\u001b[1;3;38;2;237;90;200m[uber_2021] A: Based on the provided context, in 2021 Uber:\n",
"\n",
"- Divested its JUMP business and contributed JUMP assets to Lime in exchange for common stock, preferred stock, and warrants in Lime. This gave Uber an approximately 10% fully diluted ownership interest in Lime.\n",
"\n",
"- Made investments in and partnerships with platforms like Carmera and Motional to advance autonomous vehicle technology. \n",
"\n",
"- Continued expanding its Delivery business globally, which grew Gross Bookings by 66% in 2021.\n",
"\n",
"- Saw increased demand for its Mobility business as Trip volumes recovered from the impacts of COVID-19, with Mobility Gross Bookings growing 36% in 2021.\n",
"\n",
"The context indicates these were some of the major investments and strategic moves for Uber in 2021 as it continued to expand its businesses globally.\n",
"\u001b[0m\u001b[1;3;38;2;90;149;237m[lyft_2021] Q: What were the major investments made by Lyft in 2021?\n",
"\u001b[0m\u001b[1;3;38;2;90;149;237m[lyft_2021] A: Based on the context, it seems Lyft made several major investments in 2021, including:\n",
"\n",
"- Investing in research and development to launch new innovations on their platform.\n",
"\n",
"- Making strategic acquisitions to complement their business. The context does not specify what companies were acquired.\n",
"\n",
"- Investing in sales and marketing to grow their community, build their brand, and increase brand awareness. \n",
"\n",
"- Continuing to invest organically and through acquisitions for the future, even with the impact of COVID-19.\n",
"\n",
"- Investing in the expansion of their network of Light Vehicles and Lyft Autonomous to deploy and scale third-party self-driving technology.\n",
"\n",
"- Investing in their LyftUp initiative to provide affordable and reliable transportation options.\n",
"\n",
"- Committing to reach 100% electric vehicles on their platform by 2030.\n",
"\n",
"So in summary, major investments were made in R&D, acquisitions, brand building, expanding transportation offerings, self-driving technology, sustainability initiatives, and continuing to invest for the future.\n",
"\u001b[0m"
]
}
],
"source": [
"response = await query_engine.aquery('Compare the investments made by Uber and Lyft')"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "99a6afdb-ca91-4215-bdf8-17a2272fd7cf",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Final Response: Based on the provided context, here is a comparison of\n",
"the major investments made by Uber and Lyft in 2021: Uber: - Divested\n",
"its JUMP business and gained equity stake in Lime through the deal. -\n",
"Made investments in autonomous vehicle technology companies like\n",
"Carmera and Motional. - Expanded its Delivery business globally with\n",
"66% Gross Bookings growth. - Saw increased demand for Mobility\n",
"business with 36% Gross Bookings growth. Lyft: - Invested in research\n",
"and development to launch new innovations. - Made strategic\n",
"acquisitions to complement their business (unspecified companies). -\n",
"Invested in sales, marketing and brand building. - Continued investing\n",
"for future growth despite COVID-19 impacts. - Expanded network of\n",
"Light Vehicles and Lyft Autonomous for self-driving tech. - Invested\n",
"in LyftUp for affordable transportation options. - Committed to 100%\n",
"electric vehicles by 2030. In summary, both made significant\n",
"investments in 2021 - Uber in divesting assets and gaining strategic\n",
"stakes, while expanding core businesses. Lyft focused more on internal\n",
"investments in innovation, brand building, sustainability and future\n",
"growth.\n",
"______________________________________________________________________\n",
"Source Node 1/10\n",
"Node ID: 891041e2-ee37-4dfc-a2e3-321b51cfe98d\n",
"Similarity: None\n",
"Text: Sub question: What were the major investments made by Uber in\n",
"2021? Response: Based on the provided context, in 2021 Uber: -\n",
"Divested its JUMP business and contributed JUMP assets to Lime in\n",
"exchange for common stock, preferred stock, and warrants in Lime. This\n",
"gave Uber an approximately 10% fully diluted ownership interest in\n",
"Lime. - Made inv...\n",
"______________________________________________________________________\n",
"Source Node 2/10\n",
"Node ID: e6284686-3e42-4140-97e5-0257ee3501dd\n",
"Similarity: None\n",
"Text: Sub question: What were the major investments made by Lyft in\n",
"2021? Response: Based on the context, it seems Lyft made several major\n",
"investments in 2021, including: - Investing in research and\n",
"development to launch new innovations on their platform. - Making\n",
"strategic acquisitions to complement their business. The context does\n",
"not specify what...\n",
"______________________________________________________________________\n",
"Source Node 3/10\n",
"Node ID: 554b84d4-0dcb-4d8c-8794-56c2be7a6185\n",
"Similarity: 0.59476256\n",
"Text: The income tax effect of the sale was not material. The\n",
"divestiture of Uber Eats India did not represent a strategic shift\n",
"that would have had a major effect on our operations and financial\n",
"results, and therefore does not qualify for reporting as a\n",
"discontinued operation for financial statement purposes. ##\n",
"Divestiture of JUMP and Investment in...\n",
"______________________________________________________________________\n",
"Source Node 4/10\n",
"Node ID: 63dfb873-f6e6-48af-818a-a9a32aab47a4\n",
"Similarity: 0.59476256\n",
"Text: | |Delivery Adjusted EBITDA| |$(873)|$(348)|60%| | |Adjusted\n",
"EBITDA (1), (2)| |$(2,528)|$(774)|69%| | (1) See the section titled\n",
"“Reconciliations of Non-GAAP Financial Measures” for more information\n",
"and reconciliations to the most directly comparable GAAP financial\n",
"measure. (2) See the section titled “Certain Key Metrics and Non-GAAP\n",
"Financial...\n",
"______________________________________________________________________\n",
"Source Node 5/10\n",
"Node ID: 461b3944-2cef-4e62-8267-a73cbad6c4e6\n",
"Similarity: 0.58865976\n",
"Text: Delivery We typically expect to experience seasonal increases\n",
"in our revenue in the first and fourth quarters compared to the second\n",
"and third quarters, although the historical growth of Delivery has\n",
"masked these seasonal fluctuations. In 2021, we experienced less\n",
"seasonality as a result of the COVID-19 pandemic and related\n",
"restrictions, which ...\n",
"______________________________________________________________________\n",
"Source Node 6/10\n",
"Node ID: 8cc6538b-3ffd-4135-9c24-dba730e5ca9d\n",
"Similarity: 0.57530993\n",
"Text: directly comparable GAAP financial measure. (2) See the section\n",
"titled “Certain Key Metrics and Non-GAAP Financial Measures” below for\n",
"more information. (3) MAPCs presented for annual periods are MAPCs\n",
"for the fourth quarter of the year. (4) Net loss attributable to Uber\n",
"Technologies, Inc. includes stock-based compensation expense of $827\n",
"mil...\n",
"______________________________________________________________________\n",
"Source Node 7/10\n",
"Node ID: a7b223a8-c050-4dd4-ad93-6facd603c2ae\n",
"Similarity: 0.64772755\n",
"Text: As anoper step in pe shift from personal car ownership, weve\n",
"also launched Lyft Pink, our premier membership program, which offers\n",
"discounted pricing for rideshare, bikes, and scooters, in addition to\n",
"perks for car rentals. We launched our national Resilient Streets\n",
"Initiative in September 2020 and offered a vision for how cities can\n",
"safely and...\n",
"______________________________________________________________________\n",
"Source Node 8/10\n",
"Node ID: 8472f66e-7bf7-40ad-8edb-fdcf789d1a3d\n",
"Similarity: 0.64772755\n",
"Text: Together, these investments have enabled us to create a powerful\n",
"multimodal platform and scaled user network. Notwithstanding the\n",
"impact of COVID-19, we are continuing to invest in the future, both\n",
"organically and through acquisitions of complementary businesses. We\n",
"also continue to invest in the expansion of our network of Light\n",
"Vehicles and L...\n",
"______________________________________________________________________\n",
"Source Node 9/10\n",
"Node ID: 3762f669-3e9c-4a2d-85d7-4443833f1292\n",
"Similarity: 0.6312369037002221\n",
"Text: We offer drivers the flexibility to generate income on their own\n",
"schedule, so they can best prioritize what is important in their\n",
"lives. - Technology. Our predictive technology around ride volume and\n",
"demand enables us to share key information with drivers about when and\n",
"where to drive to maximize their earnings on a real-time basis. -\n",
"Insurance....\n",
"______________________________________________________________________\n",
"Source Node 10/10\n",
"Node ID: e8c29add-a03d-4158-85ad-14fca5821f62\n",
"Similarity: 0.6138469\n",
"Text: We believe our transportation network offers a viable\n",
"alternative to car ownership. We generate substantially all of our\n",
"revenue from our ridesharing marketplace that connects drivers and\n",
"riders. We collect service fees and commissions from drivers for their\n",
"use of our ridesharing marketplace. As drivers accept more rider leads\n",
"and complete mor...\n"
]
}
],
"source": [
"pprint_response(response, show_source=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ece0dde8-285b-4f01-8ed4-c51666babe93",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}