diff --git a/docs/core_modules/query_modules/query_engine/modules.md b/docs/core_modules/query_modules/query_engine/modules.md index b88109483e78b41af127ffa1359168ab7aba3569..bdfabcd108e48fc74e6d19d28df3f62a851d8f0b 100644 --- a/docs/core_modules/query_modules/query_engine/modules.md +++ b/docs/core_modules/query_modules/query_engine/modules.md @@ -45,6 +45,7 @@ Retry Source Query Engine </examples/evaluation/RetryQuery.ipynb> Retry Guideline Query Engine </examples/evaluation/RetryQuery.ipynb> /examples/query_engine/citation_query_engine.ipynb /examples/query_engine/pdf_tables/recursive_retriever.ipynb +/examples/query_engine/sec_tables/tesla_10q_table.ipynb /examples/query_engine/recursive_retriever_agents.ipynb /examples/query_engine/ensemble_query_engine.ipynb ``` diff --git a/docs/examples/query_engine/sec_tables/tesla_10q_table.ipynb b/docs/examples/query_engine/sec_tables/tesla_10q_table.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..765e5296c4076418d4363c69b7527c246ce10b4b --- /dev/null +++ b/docs/examples/query_engine/sec_tables/tesla_10q_table.ipynb @@ -0,0 +1,741 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "8ea05db5-944c-4bad-80a6-54841ccc0d42", + "metadata": {}, + "source": [ + "# Joint Tabular/Semantic QA over Tesla 10Q \n", + "\n", + "In this example, we show how to ask questions over 10Q with understanding of both the unstructured text as well as embedded tables.\n", + "\n", + "We use Unstructured to parse out the tables, and use LlamaIndex recursive retrieval to index/retrieve tables if necessary given the user question." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "8f6499c7-138b-4849-9163-5fa2e3f373c7", + "metadata": {}, + "outputs": [], + "source": [ + "from pydantic import BaseModel\n", + "from unstructured.partition.html import partition_html\n", + "import pandas as pd\n", + "\n", + "pd.set_option(\"display.max_rows\", None)\n", + "pd.set_option(\"display.max_columns\", None)\n", + "pd.set_option(\"display.width\", None)\n", + "pd.set_option(\"display.max_colwidth\", None)" + ] + }, + { + "cell_type": "markdown", + "id": "2249e49b-fea3-424a-9d3a-955c968899a6", + "metadata": {}, + "source": [ + "### Extract Elements\n", + "\n", + "We use Unstructured to extract table and non-table elements from the 10-K filing." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "0834a73c-f64f-4a50-a085-dceb4526beaa", + "metadata": {}, + "outputs": [], + "source": [ + "from typing import Any, Optional\n", + "import pandas as pd\n", + "\n", + "\n", + "class Element(BaseModel):\n", + " id: str\n", + " type: str\n", + " element: Any\n", + " summary: Optional[str] = None\n", + " table: Optional[pd.DataFrame] = None\n", + "\n", + " class Config:\n", + " arbitrary_types_allowed = True" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "70b83b6b-d096-4cea-90b4-a55ba45780c9", + "metadata": {}, + "outputs": [], + "source": [ + "from lxml import html\n", + "import pandas as pd\n", + "\n", + "\n", + "def html_to_df(html_str):\n", + " # print(html_str)\n", + " tree = html.fromstring(html_str)\n", + " # print(tree.xpath('//table'))\n", + " table_element = tree.xpath(\"//table\")[0]\n", + " rows = table_element.xpath(\".//tr\")\n", + "\n", + " data = []\n", + " for row in rows:\n", + " cols = row.xpath(\".//td\")\n", + " cols = [c.text.strip() if c.text is not None else \"\" for c in cols]\n", + " data.append(cols)\n", + "\n", + " df = pd.DataFrame(data[1:], columns=data[0])\n", + " return df" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "58fd61c0-0a1d-48a4-9da3-178637364cdd", + "metadata": {}, + "outputs": [], + "source": [ + "# simple heuristic to filter the table (if there's only one row or one column)\n", + "def filter_table(table_element):\n", + " table_df = html_to_df(table_element.metadata.text_as_html)\n", + " if len(table_df) <= 1 or len(table_df.columns) <= 1:\n", + " return False\n", + " else:\n", + " return True" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "a016dbd7-2c6d-46aa-b7e4-12b273d8b4db", + "metadata": {}, + "outputs": [], + "source": [ + "def extract_elements(filename, table_filters=[]):\n", + " elements = partition_html(filename=filename)\n", + " output_els = []\n", + " for idx, element in enumerate(elements):\n", + " if \"unstructured.documents.html.HTMLTable\" in str(type(element)):\n", + " should_keep = all([tf(element) for tf in table_filters])\n", + " if should_keep:\n", + " table_df = html_to_df(str(element.metadata.text_as_html))\n", + " output_els.append(\n", + " Element(\n", + " id=f\"id_{idx}\", type=\"table\", element=element, table=table_df\n", + " )\n", + " )\n", + " else:\n", + " pass\n", + " else:\n", + " output_els.append(Element(id=f\"id_{idx}\", type=\"text\", element=element))\n", + " return output_els" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "523f02dc-967c-4b04-8594-256843c97957", + "metadata": {}, + "outputs": [], + "source": [ + "def get_table_elements(elements):\n", + " return [e for e in elements if e.type == \"table\"]\n", + "\n", + "\n", + "def get_text_elements(elements):\n", + " return [e for e in elements if e.type == \"text\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "cdd0d71a-a688-4448-8115-b65818c9fdda", + "metadata": {}, + "outputs": [], + "source": [ + "elements = extract_elements(\"tsla-20211231.htm\", table_filters=[filter_table])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "aaf6f75e-bda8-4c90-abfa-87bc9c6f0269", + "metadata": {}, + "outputs": [], + "source": [ + "table_elements = get_table_elements(elements)\n", + "text_elements = get_text_elements(elements)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "00596579-558e-4a6f-b64f-9a3ce490571f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "105" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(table_elements)" + ] + }, + { + "cell_type": "markdown", + "id": "cd9e6ff3-94db-4312-9f30-70133b70c59f", + "metadata": {}, + "source": [ + "### Summarize Tables\n", + "\n", + "We specifically go through tables and use LlamaIndex to help extract a summary." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "15fcacb5-2d06-405f-b5a5-3c1d3244ba43", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index import SummaryIndex, Document\n", + "from llama_index import ServiceContext\n", + "from llama_index.llms import OpenAI\n", + "from tqdm.notebook import tqdm\n", + "\n", + "llm = OpenAI(model=\"gpt-4\")\n", + "\n", + "system_prompt = \"\"\"\\\n", + "You are an assistant designed to extract insights from messy tables in a financial report.\n", + "\n", + "You are also designed to filter out \"tables\" that are not useful to keep. For instance, if the table \\\n", + "is a wrongfully extracted piece of text, or does not contain any useful information.\n", + "\"\"\"\n", + "\n", + "service_context = ServiceContext.from_defaults(system_prompt=system_prompt, llm=llm)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "c42b9e33-6432-4ece-94bf-c71eb6a3ce52", + "metadata": {}, + "outputs": [], + "source": [ + "class TableOutput(BaseModel):\n", + " \"\"\"Output from analyzing a table.\"\"\"\n", + "\n", + " summary: str\n", + " should_keep: bool\n", + "\n", + "\n", + "def extract_table_summaries(elements):\n", + " \"\"\"Go through elements, extract out summaries that are tables.\"\"\"\n", + " for element in tqdm(elements):\n", + " if element.type != \"table\":\n", + " continue\n", + " index = SummaryIndex.from_documents([Document(text=str(element.element))])\n", + " query_engine = index.as_query_engine(output_cls=TableOutput)\n", + " query_str = \"\"\"\\\n", + "What is this table about? Give a very concise summary (imagine you are adding a caption), \\\n", + "and also output whether or not the table should be kept.\n", + "\"\"\"\n", + " response = query_engine.query(query_str)\n", + " # print(str(response))\n", + " element.summary = response.response.summary\n", + " # print(element.summary)\n", + " # raise Exception" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "a95656b9-8cad-4167-8ac7-de7bfff83c7d", + "metadata": {}, + "outputs": [ + { + "data": { + "application/json": { + "ascii": false, + "bar_format": null, + "colour": null, + "elapsed": 0.004854917526245117, + "initial": 0, + "n": 0, + "ncols": null, + "nrows": 26, + "postfix": null, + "prefix": "", + "rate": null, + "total": 105, + "unit": "it", + "unit_divisor": 1000, + "unit_scale": false + }, + "application/vnd.jupyter.widget-view+json": { + "model_id": "cd1e34cacd7843aa9de853033363df28", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + " 0%| | 0/105 [00:00<?, ?it/s]" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "extract_table_summaries(table_elements)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "f0d47200-52d9-437c-a4a0-6421a5f1ed04", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Delaware 91-2197729'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "table_elements[0].summary" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "d1f587a2-6606-4764-aa76-c17745ebabfe", + "metadata": {}, + "outputs": [], + "source": [ + "# [optional] save\n", + "import pickle" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0e3b6cd1-181a-46c0-a451-6d3e52141a4c", + "metadata": {}, + "outputs": [], + "source": [ + "pickle.dump(elements, open(\"elements.pkl\", \"wb\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "3811e092-d639-44c1-a83a-0f15f985e38a", + "metadata": {}, + "outputs": [], + "source": [ + "# [optional] load\n", + "\n", + "elements = pickle.load(open(\"elements.pkl\", \"rb\"))" + ] + }, + { + "cell_type": "markdown", + "id": "57035fe2-0ce8-460f-8a6c-2f0bc37d71d3", + "metadata": {}, + "source": [ + "## Setup Recursive Retriever\n", + "\n", + "Now that we've extracted tables and their summaries, we can setup a recursive retriever in LlamaIndex to query these tables." + ] + }, + { + "cell_type": "markdown", + "id": "5392e764-818b-4382-b12d-803cd1aa914d", + "metadata": {}, + "source": [ + "### Create Nodes" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "1c184d7c-9ccf-40a8-8d73-f33fc371899c", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.schema import TextNode, IndexNode\n", + "from llama_index.node_parser import SimpleNodeParser" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "0c8fe5bf-d956-4fc6-a698-73ffa9947144", + "metadata": {}, + "outputs": [], + "source": [ + "# join all non-table elements into" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "429f3e50-dd38-462c-96ae-bb0ff8ecc2cd", + "metadata": {}, + "outputs": [], + "source": [ + "def _get_nodes_from_buffer(buffer, node_parser):\n", + " doc = Document(text=\"\\n\\n\".join([t for t in buffer]))\n", + " nodes = node_parser.get_nodes_from_documents([doc])\n", + " return nodes\n", + "\n", + "\n", + "def get_nodes_and_mappings(elements):\n", + " pd.options.display.max_columns = None\n", + " node_parser = SimpleNodeParser.from_defaults()\n", + "\n", + " nodes = []\n", + " node_mappings = {}\n", + " other_mappings = {}\n", + " cur_text_el_buffer = []\n", + " for element in elements:\n", + " if element.type == \"table\":\n", + " # flush text buffer\n", + " if len(cur_text_el_buffer) > 0:\n", + " cur_text_nodes = _get_nodes_from_buffer(cur_text_el_buffer, node_parser)\n", + " nodes.extend(cur_text_nodes)\n", + " cur_text_el_buffer = []\n", + "\n", + " index_node = IndexNode(\n", + " text=str(element.summary), index_id=(element.id + \"_table\")\n", + " )\n", + " # print(str(element.table))\n", + " table_df = element.table\n", + " table_str = table_df.to_string()\n", + " # node_mappings[(element.id + \"_table\")] = (TextNode(text=table_str), element.table, str(element.summary))\n", + " node_mappings[(element.id + \"_table\")] = TextNode(text=table_str)\n", + " other_mappings[(element.id + \"_table\")] = (\n", + " element.table,\n", + " str(element.summary),\n", + " )\n", + " nodes.append(index_node)\n", + " else:\n", + " cur_text_el_buffer.append(str(element.element))\n", + "\n", + " # flush text buffer\n", + " if len(cur_text_el_buffer) > 0:\n", + " cur_text_nodes = _get_nodes_from_buffer(cur_text_el_buffer, node_parser)\n", + " nodes.extend(cur_text_nodes)\n", + " cur_text_el_buffer = []\n", + "\n", + " return nodes, node_mappings, other_mappings" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "73479ec8-c4ae-4838-8446-f803b4c3a9a6", + "metadata": {}, + "outputs": [], + "source": [ + "nodes, node_mappings, other_mappings = get_nodes_and_mappings(elements)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "862fa695-8548-4ad8-9142-ea8517730b78", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "( \\\n", + "0 Year Ended December 31, \n", + "1 2021 2020 \n", + "2 United States $ 23,973 \n", + "3 China 13,844 \n", + "4 Other 16,006 \n", + "5 Total $ 53,823 \n", + "\n", + " \n", + "0 \n", + "1 2019 \n", + "2 $ 15,207 $ 12,653 \n", + "3 6,662 2,979 \n", + "4 9,667 8,946 \n", + "5 $ 31,536 $ 24,578 , 'Revenue by country for the years 2019, 2020, and 2021')\n" + ] + } + ], + "source": [ + "# # print(nodes[11].get_content())\n", + "# # # print(nodes[9].index_id)\n", + "# # print([n.get_content() if n\n", + "# tmp = str(node_mappings[\"id_1715_table\"][0].get_content())\n", + "# print(tmp)\n", + "print(other_mappings[\"id_1715_table\"])" + ] + }, + { + "cell_type": "markdown", + "id": "d2393a9e-c1f2-452c-9683-61435c848fec", + "metadata": {}, + "source": [ + "### Construct Retrievers" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "abb2a4ff-0185-47b7-b68b-d2ba32242f06", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.retrievers import RecursiveRetriever\n", + "from llama_index.query_engine import RetrieverQueryEngine\n", + "from llama_index import VectorStoreIndex" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "b7571128-c61d-42f1-af33-0aade58ee56d", + "metadata": {}, + "outputs": [], + "source": [ + "# construct top-level vector index + query engine\n", + "vector_index = VectorStoreIndex(nodes)\n", + "vector_retriever = vector_index.as_retriever(similarity_top_k=1)\n", + "vector_query_engine = vector_index.as_query_engine(similarity_top_k=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "b3b94a3e-e7de-4815-9598-a39834d40b07", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.retrievers import RecursiveRetriever\n", + "\n", + "recursive_retriever = RecursiveRetriever(\n", + " \"vector\",\n", + " retriever_dict={\"vector\": vector_retriever},\n", + " node_dict=node_mappings,\n", + " verbose=True,\n", + ")\n", + "query_engine = RetrieverQueryEngine.from_args(recursive_retriever)" + ] + }, + { + "cell_type": "markdown", + "id": "23f15269-5903-458d-8a1c-55f68a3732cb", + "metadata": {}, + "source": [ + "### Run some Queries" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "a998a0d7-be3a-4c39-ac94-43ecd070455b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1;3;34mRetrieving with query id None: What was the revenue in 2020?\n", + "\u001b[0m\u001b[1;3;38;5;200mRetrieved node with id, entering: id_1715_table\n", + "\u001b[0m\u001b[1;3;34mRetrieving with query id id_1715_table: What was the revenue in 2020?\n", + "\u001b[0mThe revenue in 2020 was $31,536.\n" + ] + } + ], + "source": [ + "response = query_engine.query(\"What was the revenue in 2020?\")\n", + "print(str(response))" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "1c285f95-3bd3-4842-aed8-4bbc731575d4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The revenue in 2020 was not provided in the context information.\n" + ] + } + ], + "source": [ + "# compare against the baseline retriever\n", + "response = vector_query_engine.query(\"What was the revenue in 2020?\")\n", + "print(str(response))" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "043c183e-2beb-46b1-909a-90e25833f276", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1;3;34mRetrieving with query id None: What were the total cash flows in 2021?\n", + "\u001b[0m\u001b[1;3;38;5;200mRetrieved node with id, entering: id_558_table\n", + "\u001b[0m\u001b[1;3;34mRetrieving with query id id_558_table: What were the total cash flows in 2021?\n", + "\u001b[0m" + ] + } + ], + "source": [ + "response = query_engine.query(\"What were the total cash flows in 2021?\")" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "77fd0d9e-8862-41b9-85c3-5bb44fd38fb5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The total cash flows in 2021 were $11,497 million.\n" + ] + } + ], + "source": [ + "print(str(response))" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "63a0472a-15d4-4bb7-b8ea-50a722c53b2a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The total cash flows in 2021 were not provided in the given context information.\n" + ] + } + ], + "source": [ + "response = vector_query_engine.query(\"What were the total cash flows in 2021?\")\n", + "print(str(response))" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "d97b5541-31af-4607-9504-474981760227", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1;3;34mRetrieving with query id None: What are the risk factors for Tesla?\n", + "\u001b[0m\u001b[1;3;38;5;200mRetrieving text node: Employees may leave Tesla or choose other employers over Tesla due to various factors, such as a very competitive labor market for talented individuals with automotive or technology experience, or any negative publicity related to us. In regions where we\n", + "\n", + "19\n", + "\n", + "have or will have operations, particularly significant engineering and manufacturing centers, there is strong competition for individuals with skillsets needed for our business, including specialized knowledge of electric vehicles, engineering and electrical and building construction expertise. Moreover, we may be impacted by perceptions relating to reductions in force that we have conducted in the past in order to optimize our organizational structure and reduce costs and the departure of certain senior personnel for various reasons. Likewise, as a result of our temporary suspension of various U.S. manufacturing operations in the first half of 2020, in April 2020, we temporarily furloughed certain hourly employees and reduced most salaried employees’ base salaries. We also compete with both mature and prosperous companies that have far greater financial resources than we do and start-ups and emerging companies that promise short-term growth opportunities.\n", + "\n", + "Finally, our compensation philosophy for all of our personnel reflects our startup origins, with an emphasis on equity-based awards and benefits in order to closely align their incentives with the long-term interests of our stockholders. We periodically seek and obtain approval from our stockholders for future increases to the number of awards available under our equity incentive and employee stock purchase plans. If we are unable to obtain the requisite stockholder approvals for such future increases, we may have to expend additional cash to compensate our employees and our ability to retain and hire qualified personnel may be harmed.\n", + "\n", + "We are highly dependent on the services of Elon Musk, Technoking of Tesla and our Chief Executive Officer.\n", + "\n", + "We are highly dependent on the services of Elon Musk, Technoking of Tesla and our Chief Executive Officer. Although Mr. Musk spends significant time with Tesla and is highly active in our management, he does not devote his full time and attention to Tesla. Mr. Musk also currently serves as Chief Executive Officer and Chief Technical Officer of Space Exploration Technologies Corp., a developer and manufacturer of space launch vehicles, and is involved in other emerging technology ventures.\n", + "\n", + "Our information technology systems or data, or those of our service providers or customers or users could be subject to cyber-attacks or other security incidents, which could result in data breaches, intellectual property theft, claims, litigation, regulatory investigations, significant liability, reputational damage and other adverse consequences.\n", + "\n", + "We continue to expand our information technology systems as our operations grow, such as product data management, procurement, inventory management, production planning and execution, sales, service and logistics, dealer management, financial, tax and regulatory compliance systems. This includes the implementation of new internally developed systems and the deployment of such systems in the U.S. and abroad. While, we maintain information technology measures designed to protect us against intellectual property theft, data breaches, sabotage and other external or internal cyber-attacks or misappropriation, our systems and those of our service providers are potentially vulnerable to malware, ransomware, viruses, denial-of-service attacks, phishing attacks, social engineering, computer hacking, unauthorized access, exploitation of bugs, defects and vulnerabilities, breakdowns, damage, interruptions, system malfunctions, power outages, terrorism, acts of vandalism, security breaches, security incidents, inadvertent or intentional actions by employees or other third parties, and other cyber-attacks.\n", + "\n", + "To the extent any security incident results in unauthorized access or damage to or acquisition, use, corruption, loss, destruction, alteration or dissemination of our data, including intellectual property and personal information, or our products or vehicles, or for it to be believed or reported that any of these occurred, it could disrupt our business, harm our reputation, compel us to comply with applicable data breach notification laws, subject us to time consuming, distracting and expensive litigation, regulatory investigation and oversight, mandatory corrective action, require us to verify the correctness of database contents, or otherwise subject us to liability under laws, regulations and contractual obligations, including those that protect the privacy and security of personal information. This could result in increased costs to us and result in significant legal and financial exposure and/or reputational harm.\n", + "\n", + "We also rely on service providers, and similar incidents relating to their information technology systems could also have a material adverse effect on our business. There have been and may continue to be significant supply chain attacks. Our service providers, including our workforce management software provider, have been subject to ransomware and other security incidents, and we cannot guarantee that our or our service providers’ systems have not been breached or that they do not contain exploitable defects, bugs, or vulnerabilities that could result in a security incident, or other disruption to, our or our service providers’ systems. Our ability to monitor our service providers’ security measures is limited, and, in any event, malicious third parties may be able to circumvent those security measures.\n", + "\u001b[0mThe risk factors for Tesla include strong competition for skilled individuals in the labor market, negative publicity, potential impacts from reductions in force and departure of senior personnel, competition from companies with greater financial resources, dependence on the services of Elon Musk, potential cyber-attacks or security incidents, and reliance on service providers who may be vulnerable to security breaches. These factors could harm Tesla's ability to retain and hire qualified personnel, disrupt its business, harm its reputation, result in legal and financial exposure, and cause other adverse consequences.\n" + ] + } + ], + "source": [ + "response = query_engine.query(\"What are the risk factors for Tesla?\")\n", + "print(str(response))" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "f0ab9657-edf9-4c4e-9cb0-b0e445cf7ea0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The risk factors for Tesla include strong competition for skilled individuals in the labor market, negative publicity, potential impacts from reductions in force and departure of senior personnel, competition from companies with greater financial resources, dependence on the services of Elon Musk, potential cyber-attacks or security incidents, and reliance on service providers who may be vulnerable to security breaches. These factors could harm Tesla's ability to retain and hire qualified personnel, disrupt its business, harm its reputation, result in legal and financial exposure, and cause other adverse consequences.\n" + ] + } + ], + "source": [ + "response = vector_query_engine.query(\"What are the risk factors for Tesla?\")\n", + "print(str(response))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "928ba3b7-c36d-4412-8521-5dc02d86f3d0", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "llama_index_v2", + "language": "python", + "name": "llama_index_v2" + }, + "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.10.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}