{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["\"在\n"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["# SQL自动向量查询引擎\n", "在本教程中,我们将向您展示如何使用我们的SQLAutoVectorQueryEngine。\n", "\n", "这个查询引擎允许您将结构化表格中的见解与非结构化数据相结合。\n", "它首先决定是否从您的结构化表格中查询见解。\n", "一旦这样做,它就可以推断出相应的查询,以从向量存储中获取相应的文档。\n", "\n", "**注意:** 任何文本到SQL应用程序都应该意识到执行任意SQL查询可能存在安全风险。建议采取必要的预防措施,例如使用受限角色、只读数据库、沙盒等。\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["%pip install llama-index-vector-stores-pinecone\n", "%pip install llama-index-readers-wikipedia\n", "%pip install llama-index-llms-openai"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import openai\n", "import os\n", "\n", "os.environ[\"OPENAI_API_KEY\"] = \"[You API key]\""]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### Setup\n"]}, {"cell_type": "markdown", "metadata": {}, "source": ["如果您在colab上打开这个笔记本,您可能需要安装LlamaIndex 🦙。\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["!pip install llama-index"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# 注意:这仅在jupyter笔记本中是必需的。\n", "# 详情:Jupyter在后台运行一个事件循环。\n", "# 当我们启动一个事件循环来进行异步查询时,会导致嵌套的事件循环。\n", "# 通常情况下是不允许的,我们使用nest_asyncio来允许它以方便使用。\n", "import nest_asyncio\n", "\n", "nest_asyncio.apply()\n", "\n", "import logging\n", "import sys\n", "\n", "logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n", "logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 创建常用对象\n", "\n", "这包括一个包含抽象内容(如LLM和块大小)的`ServiceContext`对象。\n", "这还包括一个包含我们的向量存储抽象的`StorageContext`对象。\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stderr", "output_type": "stream", "text": ["/Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages/pinecone/index.py:4: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from tqdm.autonotebook import tqdm\n"]}], "source": ["# 定义松果索引\n", "import pinecone\n", "import os\n", "\n", "api_key = os.environ[\"PINECONE_API_KEY\"]\n", "pinecone.init(api_key=api_key, environment=\"us-west1-gcp-free\")\n", "\n", "# 维度适用于文本嵌入-ada-002\n", "# pinecone.create_index(\"quickstart\", dimension=1536, metric=\"euclidean\", pod_type=\"p1\")\n", "pinecone_index = pinecone.Index(\"quickstart\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"data": {"text/plain": ["{}"]}, "execution_count": null, "metadata": {}, "output_type": "execute_result"}], "source": ["# 可选:删除所有\n", "pinecone_index.delete(deleteAll=True)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from llama_index.core import StorageContext\n", "from llama_index.vector_stores.pinecone import PineconeVectorStore\n", "from llama_index.core import VectorStoreIndex\n", "\n", "# 定义pinecone向量索引\n", "vector_store = PineconeVectorStore(\n", " pinecone_index=pinecone_index, namespace=\"wiki_cities\"\n", ")\n", "storage_context = StorageContext.from_defaults(vector_store=vector_store)\n", "vector_index = VectorStoreIndex([], storage_context=storage_context)"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 创建数据库架构 + 测试数据\n", "\n", "在这里,我们介绍一个玩具场景,其中有100个表(太大了,无法放入提示中)。\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from sqlalchemy import (\n", " create_engine,\n", " MetaData,\n", " Table,\n", " Column,\n", " String,\n", " Integer,\n", " select,\n", " column,\n", ")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["engine = create_engine(\"sqlite:///:memory:\", future=True)\n", "metadata_obj = MetaData()"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# 创建城市SQL表\n", "table_name = \"city_stats\"\n", "city_stats_table = Table(\n", " table_name,\n", " metadata_obj,\n", " Column(\"city_name\", String(16), primary_key=True),\n", " Column(\"population\", Integer),\n", " Column(\"country\", String(16), nullable=False),\n", ")\n", "\n", "metadata_obj.create_all(engine)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"data": {"text/plain": ["dict_keys(['city_stats'])"]}, "execution_count": null, "metadata": {}, "output_type": "execute_result"}], "source": ["# 打印表格\n", "metadata_obj.tables.keys()"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["我们向`city_stats`表中引入一些测试数据。\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from sqlalchemy import insert\n", "\n", "rows = [\n", " {\"city_name\": \"Toronto\", \"population\": 2930000, \"country\": \"Canada\"},\n", " {\"city_name\": \"Tokyo\", \"population\": 13960000, \"country\": \"Japan\"},\n", " {\"city_name\": \"Berlin\", \"population\": 3645000, \"country\": \"Germany\"},\n", "]\n", "for row in rows:\n", " stmt = insert(city_stats_table).values(**row)\n", " with engine.begin() as connection:\n", " cursor = connection.execute(stmt)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[('Toronto', 2930000, 'Canada'), ('Tokyo', 13960000, 'Japan'), ('Berlin', 3645000, 'Germany')]\n"]}], "source": ["with engine.connect() as connection:\n", " cursor = connection.exec_driver_sql(\"SELECT * FROM city_stats\")\n", " print(cursor.fetchall())"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 加载数据\n", "\n", "我们首先展示如何将一个文档转换为一组节点,并插入到文档存储中。\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Requirement already satisfied: wikipedia in /Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages (1.4.0)\n", "Requirement already satisfied: beautifulsoup4 in /Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages (from wikipedia) (4.12.2)\n", "Requirement already satisfied: requests<3.0.0,>=2.0.0 in /Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages (from wikipedia) (2.31.0)\n", "Requirement already satisfied: idna<4,>=2.5 in /Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.4)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.2.0)\n", "Requirement already satisfied: certifi>=2017.4.17 in /Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2023.5.7)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (1.26.16)\n", "Requirement already satisfied: soupsieve>1.2 in /Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages (from beautifulsoup4->wikipedia) (2.4.1)\n", "\u001b[33mWARNING: You are using pip version 21.2.4; however, version 23.2 is available.\n", "You should consider upgrading via the '/Users/loganmarkewich/llama_index/llama-index/bin/python3 -m pip install --upgrade pip' command.\u001b[0m\n"]}], "source": ["# 安装维基百科的Python包\n", "!pip install wikipedia"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from llama_index.readers.wikipedia import WikipediaReader\n", "\n", "cities = [\"Toronto\", \"Berlin\", \"Tokyo\"]\n", "wiki_docs = WikipediaReader().load_data(pages=cities)"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 创建SQL索引\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from llama_index.core import SQLDatabase\n", "\n", "sql_database = SQLDatabase(engine, include_tables=[\"city_stats\"])"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from llama_index.core.query_engine import NLSQLTableQueryEngine\n", "\n", "sql_query_engine = NLSQLTableQueryEngine(\n", " sql_database=sql_database,\n", " tables=[\"city_stats\"],\n", ")"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 构建向量索引\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stderr", "output_type": "stream", "text": ["Upserted vectors: 100%|██████████| 20/20 [00:00<00:00, 22.37it/s]\n", "Upserted vectors: 100%|██████████| 22/22 [00:00<00:00, 23.14it/s]\n", "Upserted vectors: 100%|██████████| 13/13 [00:00<00:00, 17.67it/s]\n"]}], "source": ["from llama_index.core import Settings\n", "\n", "# 将文档插入向量索引\n", "# 每个文档都附带有城市的元数据\n", "for city, wiki_doc in zip(cities, wiki_docs):\n", " nodes = Settings.node_parser.get_nodes_from_documents([wiki_doc])\n", " # 为每个节点添加元数据\n", " for node in nodes:\n", " node.metadata = {\"title\": city}\n", " vector_index.insert_nodes(nodes)"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 定义查询引擎,设置为工具\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from llama_index.llms.openai import OpenAI\n", "from llama_index.core.retrievers import VectorIndexAutoRetriever\n", "from llama_index.core.vector_stores import MetadataInfo, VectorStoreInfo\n", "from llama_index.core.query_engine import RetrieverQueryEngine\n", "\n", "\n", "vector_store_info = VectorStoreInfo(\n", " content_info=\"articles about different cities\",\n", " metadata_info=[\n", " MetadataInfo(\n", " name=\"title\", type=\"str\", description=\"The name of the city\"\n", " ),\n", " ],\n", ")\n", "vector_auto_retriever = VectorIndexAutoRetriever(\n", " vector_index, vector_store_info=vector_store_info\n", ")\n", "\n", "retriever_query_engine = RetrieverQueryEngine.from_args(\n", " vector_auto_retriever, llm=OpenAI(model=\"gpt-4\")\n", ")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from llama_index.core.tools import QueryEngineTool\n", "\n", "sql_tool = QueryEngineTool.from_defaults(\n", " query_engine=sql_query_engine,\n", " description=(\n", " \"Useful for translating a natural language query into a SQL query over\"\n", " \" a table containing: city_stats, containing the population/country of\"\n", " \" each city\"\n", " ),\n", ")\n", "vector_tool = QueryEngineTool.from_defaults(\n", " query_engine=retriever_query_engine,\n", " description=(\n", " f\"Useful for answering semantic questions about different cities\"\n", " ),\n", ")"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 定义SQLAutoVectorQueryEngine\n"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from llama_index.core.query_engine import SQLAutoVectorQueryEngine\n", "\n", "query_engine = SQLAutoVectorQueryEngine(\n", " sql_tool, vector_tool, llm=OpenAI(model=\"gpt-4\")\n", ")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\u001b[36;1m\u001b[1;3mQuerying SQL database: Useful for translating a natural language query into a SQL query over a table containing city_stats, containing the population/country of each city\n", "\u001b[0mINFO:llama_index.query_engine.sql_join_query_engine:> Querying SQL database: Useful for translating a natural language query into a SQL query over a table containing city_stats, containing the population/country of each city\n", "> Querying SQL database: Useful for translating a natural language query into a SQL query over a table containing city_stats, containing the population/country of each city\n", "INFO:llama_index.indices.struct_store.sql_query:> Table desc str: Table 'city_stats' has columns: city_name (VARCHAR(16)), population (INTEGER), country (VARCHAR(16)) and foreign keys: .\n", "> Table desc str: Table 'city_stats' has columns: city_name (VARCHAR(16)), population (INTEGER), country (VARCHAR(16)) and foreign keys: .\n", "\u001b[33;1m\u001b[1;3mSQL query: SELECT city_name, population FROM city_stats ORDER BY population DESC LIMIT 1;\n", "\u001b[0m\u001b[33;1m\u001b[1;3mSQL response: \n", "Tokyo is the city with the highest population, with 13.96 million people. It is a vibrant city with a rich culture and a wide variety of art forms. From traditional Japanese art such as calligraphy and woodblock prints to modern art galleries and museums, Tokyo has something for everyone. There are also many festivals and events throughout the year that celebrate the city's culture and art.\n", "\u001b[0m\u001b[36;1m\u001b[1;3mTransformed query given SQL response: What are some specific cultural festivals, events, and notable art galleries or museums in Tokyo?\n", "\u001b[0mINFO:llama_index.query_engine.sql_join_query_engine:> Transformed query given SQL response: What are some specific cultural festivals, events, and notable art galleries or museums in Tokyo?\n", "> Transformed query given SQL response: What are some specific cultural festivals, events, and notable art galleries or museums in Tokyo?\n", "INFO:llama_index.indices.vector_store.retrievers.auto_retriever.auto_retriever:Using query str: cultural festivals events art galleries museums Tokyo\n", "Using query str: cultural festivals events art galleries museums Tokyo\n", "INFO:llama_index.indices.vector_store.retrievers.auto_retriever.auto_retriever:Using filters: {'title': 'Tokyo'}\n", "Using filters: {'title': 'Tokyo'}\n", "INFO:llama_index.indices.vector_store.retrievers.auto_retriever.auto_retriever:Using top_k: 2\n", "Using top_k: 2\n", "\u001b[38;5;200m\u001b[1;3mquery engine response: The context information mentions the Tokyo National Museum, which houses 37% of the country's artwork national treasures. It also mentions the Studio Ghibli anime center as a subcultural attraction. However, the text does not provide information on specific cultural festivals or events in Tokyo.\n", "\u001b[0mINFO:llama_index.query_engine.sql_join_query_engine:> query engine response: The context information mentions the Tokyo National Museum, which houses 37% of the country's artwork national treasures. It also mentions the Studio Ghibli anime center as a subcultural attraction. However, the text does not provide information on specific cultural festivals or events in Tokyo.\n", "> query engine response: The context information mentions the Tokyo National Museum, which houses 37% of the country's artwork national treasures. It also mentions the Studio Ghibli anime center as a subcultural attraction. However, the text does not provide information on specific cultural festivals or events in Tokyo.\n", "\u001b[32;1m\u001b[1;3mFinal response: Tokyo, the city with the highest population of 13.96 million people, is known for its vibrant culture and diverse art forms. It is home to traditional Japanese art such as calligraphy and woodblock prints, as well as modern art galleries and museums. Notably, the Tokyo National Museum houses 37% of the country's artwork national treasures, and the Studio Ghibli anime center is a popular subcultural attraction. While there are many festivals and events throughout the year that celebrate the city's culture and art, specific examples were not provided in the available information.\n", "\u001b[0m"]}], "source": ["response = query_engine.query(\n", " \"Tell me about the arts and culture of the city with the highest\"\n", " \" population\"\n", ")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Tokyo, the city with the highest population of 13.96 million people, is known for its vibrant culture and diverse art forms. It is home to traditional Japanese art such as calligraphy and woodblock prints, as well as modern art galleries and museums. Notably, the Tokyo National Museum houses 37% of the country's artwork national treasures, and the Studio Ghibli anime center is a popular subcultural attraction. While there are many festivals and events throughout the year that celebrate the city's culture and art, specific examples were not provided in the available information.\n"]}], "source": ["print(str(response))"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\u001b[36;1m\u001b[1;3mQuerying other query engine: Useful for answering semantic questions about different cities\n", "\u001b[0mINFO:llama_index.query_engine.sql_join_query_engine:> Querying other query engine: Useful for answering semantic questions about different cities\n", "> Querying other query engine: Useful for answering semantic questions about different cities\n", "INFO:llama_index.indices.vector_store.retrievers.auto_retriever.auto_retriever:Using query str: history of Berlin\n", "Using query str: history of Berlin\n", "INFO:llama_index.indices.vector_store.retrievers.auto_retriever.auto_retriever:Using filters: {'title': 'Berlin'}\n", "Using filters: {'title': 'Berlin'}\n", "INFO:llama_index.indices.vector_store.retrievers.auto_retriever.auto_retriever:Using top_k: 2\n", "Using top_k: 2\n", "\u001b[38;5;200m\u001b[1;3mQuery Engine response: Berlin's history dates back to around 60,000 BC, with the earliest human traces found in the area. A Mesolithic deer antler mask found in Biesdorf (Berlin) was dated around 9000 BC. During Neolithic times, a large number of communities existed in the area and in the Bronze Age, up to 1000 people lived in 50 villages. Early Germanic tribes took settlement from 500 BC and Slavic settlements and castles began around 750 AD.\n", "\n", "The earliest evidence of middle age settlements in the area of today's Berlin are remnants of a house foundation dated to 1174, found in excavations in Berlin Mitte, and a wooden beam dated from approximately 1192. The first written records of towns in the area of present-day Berlin date from the late 12th century. Spandau is first mentioned in 1197 and Köpenick in 1209, although these areas did not join Berlin until 1920. \n", "\n", "The central part of Berlin can be traced back to two towns. Cölln on the Fischerinsel is first mentioned in a 1237 document, and Berlin, across the Spree in what is now called the Nikolaiviertel, is referenced in a document from 1244. 1237 is considered the founding date of the city. The two towns over time formed close economic and social ties, and profited from the staple right on the two important trade routes Via Imperii and from Bruges to Novgorod. In 1307, they formed an alliance with a common external policy, their internal administrations still being separated. In 1415, Frederick I became the elector of the Margraviate of Brandenburg, which he ruled until 1440.\n", "\n", "The name Berlin has its roots in the language of West Slavic inhabitants of the area of today's Berlin, and may be related to the Old Polabian stem berl-/birl- (\"swamp\"). or Proto-Slavic bьrlogъ, (lair, den). Since the Ber- at the beginning sounds like the German word Bär (\"bear\"), a bear appears in the coat of arms of the city. It is therefore an example of canting arms.\n", "\u001b[0m"]}], "source": ["response = query_engine.query(\"Tell me about the history of Berlin\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Berlin's history dates back to around 60,000 BC, with the earliest human traces found in the area. A Mesolithic deer antler mask found in Biesdorf (Berlin) was dated around 9000 BC. During Neolithic times, a large number of communities existed in the area and in the Bronze Age, up to 1000 people lived in 50 villages. Early Germanic tribes took settlement from 500 BC and Slavic settlements and castles began around 750 AD.\n", "\n", "The earliest evidence of middle age settlements in the area of today's Berlin are remnants of a house foundation dated to 1174, found in excavations in Berlin Mitte, and a wooden beam dated from approximately 1192. The first written records of towns in the area of present-day Berlin date from the late 12th century. Spandau is first mentioned in 1197 and Köpenick in 1209, although these areas did not join Berlin until 1920. \n", "\n", "The central part of Berlin can be traced back to two towns. Cölln on the Fischerinsel is first mentioned in a 1237 document, and Berlin, across the Spree in what is now called the Nikolaiviertel, is referenced in a document from 1244. 1237 is considered the founding date of the city. The two towns over time formed close economic and social ties, and profited from the staple right on the two important trade routes Via Imperii and from Bruges to Novgorod. In 1307, they formed an alliance with a common external policy, their internal administrations still being separated. In 1415, Frederick I became the elector of the Margraviate of Brandenburg, which he ruled until 1440.\n", "\n", "The name Berlin has its roots in the language of West Slavic inhabitants of the area of today's Berlin, and may be related to the Old Polabian stem berl-/birl- (\"swamp\"). or Proto-Slavic bьrlogъ, (lair, den). Since the Ber- at the beginning sounds like the German word Bär (\"bear\"), a bear appears in the coat of arms of the city. It is therefore an example of canting arms.\n"]}], "source": ["print(str(response))"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\u001b[36;1m\u001b[1;3mQuerying SQL database: Useful for translating a natural language query into a SQL query over a table containing: city_stats, containing the population/country of each city\n", "\u001b[0mINFO:llama_index.query_engine.sql_join_query_engine:> Querying SQL database: Useful for translating a natural language query into a SQL query over a table containing: city_stats, containing the population/country of each city\n", "> Querying SQL database: Useful for translating a natural language query into a SQL query over a table containing: city_stats, containing the population/country of each city\n", "INFO:llama_index.indices.struct_store.sql_query:> Table desc str: Table 'city_stats' has columns: city_name (VARCHAR(16)), population (INTEGER), country (VARCHAR(16)) and foreign keys: .\n", "> Table desc str: Table 'city_stats' has columns: city_name (VARCHAR(16)), population (INTEGER), country (VARCHAR(16)) and foreign keys: .\n", "\u001b[33;1m\u001b[1;3mSQL query: SELECT city_name, country FROM city_stats;\n", "\u001b[0m\u001b[33;1m\u001b[1;3mSQL response: Toronto is in Canada, Tokyo is in Japan, and Berlin is in Germany.\n", "\u001b[0m\u001b[36;1m\u001b[1;3mTransformed query given SQL response: What countries are New York, San Francisco, and other cities in?\n", "\u001b[0mINFO:llama_index.query_engine.sql_join_query_engine:> Transformed query given SQL response: What countries are New York, San Francisco, and other cities in?\n", "> Transformed query given SQL response: What countries are New York, San Francisco, and other cities in?\n", "INFO:llama_index.indices.vector_store.retrievers.auto_retriever.auto_retriever:Using query str: New York San Francisco\n", "Using query str: New York San Francisco\n", "INFO:llama_index.indices.vector_store.retrievers.auto_retriever.auto_retriever:Using filters: {'title': 'San Francisco'}\n", "Using filters: {'title': 'San Francisco'}\n", "INFO:llama_index.indices.vector_store.retrievers.auto_retriever.auto_retriever:Using top_k: 2\n", "Using top_k: 2\n", "\u001b[38;5;200m\u001b[1;3mquery engine response: None\n", "\u001b[0mINFO:llama_index.query_engine.sql_join_query_engine:> query engine response: None\n", "> query engine response: None\n", "\u001b[32;1m\u001b[1;3mFinal response: The country corresponding to each city is as follows: Toronto is in Canada, Tokyo is in Japan, and Berlin is in Germany. Unfortunately, I do not have information on the countries for New York, San Francisco, and other cities.\n", "\u001b[0m"]}], "source": ["response = query_engine.query(\n", " \"Can you give me the country corresponding to each city?\"\n", ")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["The country corresponding to each city is as follows: Toronto is in Canada, Tokyo is in Japan, and Berlin is in Germany. Unfortunately, I do not have information on the countries for New York, San Francisco, and other cities.\n"]}], "source": ["print(str(response))"]}], "metadata": {"kernelspec": {"display_name": "llama-index", "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"}}, "nbformat": 4, "nbformat_minor": 4}