File size: 54,630 Bytes
5449492 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 |
{
"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
}
|