{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Notebook for ingesting & processing Meta's 2023 10K\n", "\n", "- Google Doc with [instructions](https://docs.google.com/forms/d/e/1FAIpQLSfRHORtHFiPUGCiYNt2NfapWtgUQWbv5V75kUPwUAkx20r9Eg/viewform)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Setup" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import nest_asyncio\n", "\n", "nest_asyncio.apply()\n", "\n", "import logging\n", "import sys\n", "import os\n", "from dotenv import find_dotenv, load_dotenv\n", "\n", "load_dotenv(find_dotenv())\n", "logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n", "logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import llama_index\n", "# from llama_index.core import set_global_handler\n", "\n", "# os.environ[\"WANDB_NOTEBOOK_NAME\"] = \"Process Meta 10K.ipynb\"\n", "# set_global_handler(\"wandb\", run_args={\"project\": \"meta-10k\"})\n", "# wandb_callback = llama_index.core.global_handler" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "from llama_index.llms.openai import OpenAI\n", "from llama_index.embeddings.openai import OpenAIEmbedding\n", "from llama_index.core import Settings\n", "\n", "GPT4_MODEL_NAME = \"gpt-4-turbo-2024-04-09\"\n", "GPT35_MODEL_NAME = \"gpt-3.5-turbo-1106\"\n", "\n", "gpt35_model = OpenAI(model=GPT35_MODEL_NAME, temperature=0.0)\n", "gpt4_model = OpenAI(model=GPT4_MODEL_NAME, temperature=0.0)\n", "\n", "Settings.llm = OpenAI(model=GPT35_MODEL_NAME)\n", "Settings.embed_model = OpenAIEmbedding(model=\"text-embedding-3-small\")\n", "\n", "DEFAULT_QUESTION1 = \"What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\"\n", "DEFAULT_QUESTION2 = \"Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Ingest Document" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Started parsing the file under job_id fa8037ef-65ef-40e0-a756-a09f00a05502\n", "1\n" ] } ], "source": [ "from llama_parse import LlamaParse\n", "from llama_index.core import SimpleDirectoryReader\n", "\n", "# assumes that the env has the key LLAMA_CLOUD_API_KEY\n", "parser = LlamaParse(\n", " result_type=\"markdown\",\n", " verbose=True\n", ")\n", "\n", "file_extractor = {\".pdf\": parser}\n", "documents = SimpleDirectoryReader(\n", " input_dir=\"../data\", \n", " file_extractor=file_extractor\n", ").load_data(num_workers=10)\n", "\n", "print(len(documents))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "## SECURITIES AND EXCHANGE COMMISSION UNITED STATES Washington, D.C. 20549\n", "\n", "## FORM 10-K\n", "\n", "(Mark One)\n", "\n", "☒ ANNUAL REPORT PURSUANT TO SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934\n", "\n", "For the fiscal year ended December or 31, 2023\n", "\n", "☐ TRANSITION REPORT PURSUANT TO SECTION 13 OR 15(d) OF THE SECURITIES EXCHANGE ACT OF 1934\n", "\n", "For the transition period from to\n", "\n", "Commission File Number: 001-35551\n", "\n", "Meta Platforms, Inc. Meta\n", "\n", "(Exact name of registrant as specified in its charter)\n", "\n", "Delaware 20-1665019\n", "\n", "(State or other jurisdiction of incorporation or organization) 1 Meta Way, Menlo Park, California 94025 (I.R.S. Employer Identification Number)\n", "\n", "(Address of principal executive offices and Zip Code)\n", "\n", "(650) 543-4800\n", "\n", "(Registrant's telephone number, including area code)\n", "\n", "Securities registered pursuant to Section 12(b) of the Act:\n", "\n", "|Title of each class|Trading symbol(s)|Name of each exchange on which registered|\n", "|---|---|---|\n", "|Class A Common Stock, $0.000006 par value|META|The Nasdaq Stock Mark...\n" ] } ], "source": [ "# let's check to make sure that this is a 10-K file\n", "print(documents[0].text[:1000] + \"...\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Indexing " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from llama_index.core.node_parser import MarkdownElementNodeParser\n", "from llama_index.core import VectorStoreIndex\n", "\n", "node_parser = MarkdownElementNodeParser(\n", " llm=gpt35_model,\n", " num_workers=10\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nodes = node_parser.get_nodes_from_documents(documents=documents)\n", "base_nodes, objects = node_parser.get_nodes_and_objects(nodes=nodes)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n" ] } ], "source": [ "recursive_index = VectorStoreIndex(nodes=base_nodes + objects)\n", "raw_index = VectorStoreIndex.from_documents(documents=documents)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Raw Query Engine" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "from llama_index.postprocessor.cohere_rerank import CohereRerank\n", "reranker = CohereRerank(top_n=6)\n", "\n", "raw_query_engine = recursive_index.as_query_engine(\n", " llm=gpt4_model,\n", " similarity_top_k=15,\n", " node_postprocessors=[reranker],\n", " verbose = True\n", ")" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 7873de31-b332-4365-bd65-0a4b84f47da6: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 4e8c6d95-87fd-423a-84ca-06c2d21c427e: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering c7ec1eec-24ee-4c3e-81ba-ca81d1a91389: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 99462df3-001a-458a-97ef-89bd51518f88: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 580282f7-7c4e-4ba5-a559-636959b71ec8: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering f333c293-2f5b-4a99-a1e8-4bc9a22a1508: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 4044f21f-899a-4fcc-8caa-3b6f8fc4e92c: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 3bdc6a30-8c4e-41d0-935f-78cb3888a00c: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 94beb3bf-edb3-42d1-a7fe-9b7691f219ca: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering caf09ded-aadb-479d-a589-28f16b4e9a93: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 20b634e2-27ce-4343-ae60-3694cc2c276d: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 3ead0e8d-0e03-4a0c-9908-ea1e3f9375be: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 7873de31-b332-4365-bd65-0a4b84f47da6: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 4e8c6d95-87fd-423a-84ca-06c2d21c427e: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering c7ec1eec-24ee-4c3e-81ba-ca81d1a91389: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 99462df3-001a-458a-97ef-89bd51518f88: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 580282f7-7c4e-4ba5-a559-636959b71ec8: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering f333c293-2f5b-4a99-a1e8-4bc9a22a1508: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 4044f21f-899a-4fcc-8caa-3b6f8fc4e92c: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 3bdc6a30-8c4e-41d0-935f-78cb3888a00c: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 94beb3bf-edb3-42d1-a7fe-9b7691f219ca: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering caf09ded-aadb-479d-a589-28f16b4e9a93: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 20b634e2-27ce-4343-ae60-3694cc2c276d: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 3ead0e8d-0e03-4a0c-9908-ea1e3f9375be: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] } ], "source": [ "raw_response1 = recursive_query_engine.query(DEFAULT_QUESTION1)\n", "raw_response2 = recursive_query_engine.query(DEFAULT_QUESTION2)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "**********RAW**********\n", "raw_response1: The total value of 'Cash and cash equivalents' as of December 31, 2023, was $41,862 million.\n", "raw_response2: The provided text does not specify the names or identities of the members of Meta Platforms, Inc.'s Board of Directors. Therefore, I cannot provide the names of the directors based on the information available.\n" ] } ], "source": [ "print(\"**********RAW**********\")\n", "print(f\"raw_response1: {raw_response1}\")\n", "print(f\"raw_response2: {raw_response2}\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5. Recursive Query Engine" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "recursive_query_engine = recursive_index.as_query_engine(\n", " llm=gpt4_model,\n", " similarity_top_k=15,\n", " node_postprocessors=[reranker],\n", " verbose = True\n", ")" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 7873de31-b332-4365-bd65-0a4b84f47da6: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 4e8c6d95-87fd-423a-84ca-06c2d21c427e: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering c7ec1eec-24ee-4c3e-81ba-ca81d1a91389: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 99462df3-001a-458a-97ef-89bd51518f88: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 580282f7-7c4e-4ba5-a559-636959b71ec8: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering f333c293-2f5b-4a99-a1e8-4bc9a22a1508: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 4044f21f-899a-4fcc-8caa-3b6f8fc4e92c: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 3bdc6a30-8c4e-41d0-935f-78cb3888a00c: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 94beb3bf-edb3-42d1-a7fe-9b7691f219ca: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering caf09ded-aadb-479d-a589-28f16b4e9a93: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 20b634e2-27ce-4343-ae60-3694cc2c276d: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 3ead0e8d-0e03-4a0c-9908-ea1e3f9375be: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] } ], "source": [ "recursive_response1 = recursive_query_engine.query(DEFAULT_QUESTION1)\n", "recursive_response2 = recursive_query_engine.query(DEFAULT_QUESTION2)" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "**********RECURSIVE**********\n", "recursive_response1: The total value of 'Cash and cash equivalents' as of December 31, 2023, was $41,862 million.\n", "recursive_response2: The provided text does not specify the names or identities of the members of Meta Platforms, Inc.'s Board of Directors.\n" ] } ], "source": [ "print(\"**********RECURSIVE**********\")\n", "print(f\"recursive_response1: {recursive_response1}\")\n", "print(f\"recursive_response2: {recursive_response2}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 6. Subquestion Query Engine" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "from llama_index.core.indices.query.query_transform.base import (\n", " StepDecomposeQueryTransform,\n", ")\n", "\n", "# gpt-4\n", "step_decompose_transform = StepDecomposeQueryTransform(llm=gpt4_model, verbose=True)" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [], "source": [ "from llama_index.core.query_engine import MultiStepQueryEngine\n", "index_summary = \"Used to answer questions about Meta's 10-K and financial performance during 2023\"\n", "\n", "subquestion_query_engine = MultiStepQueryEngine(\n", " query_engine=recursive_query_engine,\n", " query_transform=step_decompose_transform,\n", " index_summary=index_summary,\n", ")" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: What was the total value of 'Cash and cash equivalents' reported in Meta's 10-K for the year ending December 31, 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 7873de31-b332-4365-bd65-0a4b84f47da6: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' reported in Meta's 10-K for the year ending December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 4e8c6d95-87fd-423a-84ca-06c2d21c427e: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' reported in Meta's 10-K for the year ending December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 580282f7-7c4e-4ba5-a559-636959b71ec8: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' reported in Meta's 10-K for the year ending December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 37f1e0f8-73cb-4de9-975d-460bd6a51249: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' reported in Meta's 10-K for the year ending December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering e61666fc-2ca4-4544-af68-66fe2b85b442: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' reported in Meta's 10-K for the year ending December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 99462df3-001a-458a-97ef-89bd51518f88: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' reported in Meta's 10-K for the year ending December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering eef206a0-f79f-4e6e-a3fe-fd72010be2b7: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' reported in Meta's 10-K for the year ending December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering f333c293-2f5b-4a99-a1e8-4bc9a22a1508: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' reported in Meta's 10-K for the year ending December 31, 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: None\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 94beb3bf-edb3-42d1-a7fe-9b7691f219ca: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 20b634e2-27ce-4343-ae60-3694cc2c276d: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 3bdc6a30-8c4e-41d0-935f-78cb3888a00c: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 0bd582c3-c59b-48a3-a988-8042937c7d7d: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering caf09ded-aadb-479d-a589-28f16b4e9a93: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering e61666fc-2ca4-4544-af68-66fe2b85b442: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering bef70b75-d90b-48f7-9c87-ce32b2b091d0: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: None\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] } ], "source": [ "sq_response1 = subquestion_query_engine.query(DEFAULT_QUESTION1)\n", "sq_response2 = subquestion_query_engine.query(DEFAULT_QUESTION2)" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "**********RECURSIVE**********\n", "sq_response1: The total value of 'Cash and cash equivalents' as of December 31, 2023, was $41,862 million.\n", "sq_response2: I'm sorry, I cannot provide the information you requested.\n" ] } ], "source": [ "print(\"**********RECURSIVE**********\")\n", "print(f\"sq_response1: {sq_response1}\")\n", "print(f\"sq_response2: {sq_response2}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 7. Multi-Step Query Engine" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [], "source": [ "\n", "from llama_index.core.indices.query.query_transform.base import (\n", " StepDecomposeQueryTransform,\n", ")\n", "\n", "# gpt-4\n", "step_decompose_transform = StepDecomposeQueryTransform(llm=gpt4_model, verbose=True)\n" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [], "source": [ "mstep_query_engine = MultiStepQueryEngine(\n", " query_engine=recursive_query_engine,\n", " query_transform=step_decompose_transform,\n", " index_summary=index_summary,\n", ")" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 7873de31-b332-4365-bd65-0a4b84f47da6: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 4e8c6d95-87fd-423a-84ca-06c2d21c427e: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 580282f7-7c4e-4ba5-a559-636959b71ec8: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 37f1e0f8-73cb-4de9-975d-460bd6a51249: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering e61666fc-2ca4-4544-af68-66fe2b85b442: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 99462df3-001a-458a-97ef-89bd51518f88: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering f333c293-2f5b-4a99-a1e8-4bc9a22a1508: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering eef206a0-f79f-4e6e-a3fe-fd72010be2b7: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering c7ec1eec-24ee-4c3e-81ba-ca81d1a91389: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What was the total value of 'Cash and cash equivalents' for Meta as of December 31, 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: What was the total value of 'Cash and cash equivalents' as of December 31, 2023?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: None\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering 94beb3bf-edb3-42d1-a7fe-9b7691f219ca: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 20b634e2-27ce-4343-ae60-3694cc2c276d: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 3bdc6a30-8c4e-41d0-935f-78cb3888a00c: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 0bd582c3-c59b-48a3-a988-8042937c7d7d: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering caf09ded-aadb-479d-a589-28f16b4e9a93: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering e61666fc-2ca4-4544-af68-66fe2b85b442: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering bef70b75-d90b-48f7-9c87-ce32b2b091d0: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query Who are the members of Meta's Board of Directors as listed in their 2023 10-K report?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: Who are Meta's 'Directors' (i.e., members of the Board of Directors)?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: None\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n" ] } ], "source": [ "mstep_response1 = mstep_query_engine.query(DEFAULT_QUESTION1)\n", "mstep_response2 = mstep_query_engine.query(DEFAULT_QUESTION2)" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "**********RECURSIVE**********\n", "mstep_response1: The total value of 'Cash and cash equivalents' as of December 31, 2023, was $41,862 million.\n", "mstep_response2: I'm sorry, I cannot provide the information you requested.\n" ] } ], "source": [ "print(\"**********RECURSIVE**********\")\n", "print(f\"mstep_response1: {mstep_response1}\")\n", "print(f\"mstep_response2: {mstep_response2}\")" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: How is the metaverse investment doing?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: What is the financial performance of Meta in 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering e61666fc-2ca4-4544-af68-66fe2b85b442: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What is the financial performance of Meta in 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 580282f7-7c4e-4ba5-a559-636959b71ec8: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What is the financial performance of Meta in 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering b1ecd789-6349-4192-a7fd-bdad5c340daf: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What is the financial performance of Meta in 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering eef206a0-f79f-4e6e-a3fe-fd72010be2b7: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What is the financial performance of Meta in 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 37f1e0f8-73cb-4de9-975d-460bd6a51249: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What is the financial performance of Meta in 2023?\n", "\u001b[0m\u001b[1;3;38;2;11;159;203mRetrieval entering 021c3a54-74cd-4cb3-8608-48d611bd4646: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query What is the financial performance of Meta in 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: How is the metaverse investment doing?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: How has the investment in Reality Labs affected Meta's overall financial performance in 2023?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;33m> Current query: How is the metaverse investment doing?\n", "\u001b[0m\u001b[1;3;38;5;200m> New query: How has the performance of Reality Labs influenced the overall valuation of Meta's investments in the metaverse?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n", "\u001b[1;3;38;2;11;159;203mRetrieval entering eef206a0-f79f-4e6e-a3fe-fd72010be2b7: TextNode\n", "\u001b[0m\u001b[1;3;38;2;237;90;200mRetrieving from object TextNode with query How has the performance of Reality Labs influenced the overall valuation of Meta's investments in the metaverse?\n", "\u001b[0mINFO:httpx:HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.cohere.ai/v1/rerank \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n", "The metaverse investment is facing financial challenges due to the substantial operating losses incurred by Reality Labs. These losses have significantly impacted Meta's overall operating profit in 2023 and are expected to increase further in 2024. Despite these financial setbacks, Meta continues to invest in Reality Labs as part of a long-term strategy to develop the metaverse, which is considered the next chapter of the internet with potential future monetization opportunities. However, the current financial performance of Reality Labs is reducing Meta's operating margin and profitability, which could affect the company's overall financial health if these investments do not yield successful outcomes in the longer term.\n" ] } ], "source": [ "print(subquestion_query_engine.query(\"How is the metaverse investment doing?\"))" ] } ], "metadata": { "kernelspec": { "display_name": "llmops", "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.8" } }, "nbformat": 4, "nbformat_minor": 2 }