From 19ca0672601b69a47b7e95c15d35e557c6ac8a80 Mon Sep 17 00:00:00 2001 From: Siraj R Aizlewood Date: Wed, 9 Jul 2025 10:52:45 +0400 Subject: [PATCH] fix: Updated to Work with Modern LangChain Approaches Including LCEL --- .../08-langchain-retrieval-agent.ipynb | 950 +++++++++++------- 1 file changed, 571 insertions(+), 379 deletions(-) diff --git a/learn/generation/langchain/handbook/08-langchain-retrieval-agent.ipynb b/learn/generation/langchain/handbook/08-langchain-retrieval-agent.ipynb index fefea3b1..20ae28bc 100644 --- a/learn/generation/langchain/handbook/08-langchain-retrieval-agent.ipynb +++ b/learn/generation/langchain/handbook/08-langchain-retrieval-agent.ipynb @@ -17,11 +17,11 @@ "id": "bhWwrfbbVGOA" }, "source": [ - "#### [LangChain Handbook](https://pinecone.io/learn/langchain)\n", + "#### [LangChain Handbook](https://www.pinecone.io/learn/series/langchain/)\n", "\n", "# Retrieval Agents\n", "\n", - "We've seen in previous chapters how powerful [retrieval augmentation](https://www.pinecone.io/learn/langchain-retrieval-augmentation/) and [conversational agents](https://www.pinecone.io/learn/langchain-agents/) can be. They become even more impressive when we begin using them together.\n", + "We've seen in previous chapters how powerful [retrieval augmentation](https://www.pinecone.io/learn/series/langchain/langchain-retrieval-augmentation/) and [conversational agents](https://www.pinecone.io/learn/series/langchain/langchain-agents/) can be. They become even more impressive when we begin using them together.\n", "\n", "Conversational agents can struggle with data freshness, knowledge about specific domains, or accessing internal documentation. By coupling agents with retrieval augmentation tools we no longer have these problems.\n", "\n", @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -42,15 +42,24 @@ "id": "pva9ehKXUpU2", "outputId": "3bbcf2dd-1889-412f-d45a-f56945ac4f2f" }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "[notice] A new release of pip is available: 23.1.2 -> 25.1.1\n", + "[notice] To update, run: python.exe -m pip install --upgrade pip\n" + ] + } + ], "source": [ "!pip install -qU \\\n", - " openai==1.6.1 \\\n", - " pinecone-client==3.1.0 \\\n", - " langchain==0.1.1 \\\n", - " langchain-community==0.0.13 \\\n", - " tiktoken==0.5.2 \\\n", - " datasets==2.12.0" + " pinecone==7.3.0 \\\n", + " langchain==0.3.25 \\\n", + " langchain-openai==0.3.22 \\\n", + " tiktoken==0.9.0 \\\n", + " datasets==3.6.0" ] }, { @@ -75,7 +84,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -84,104 +93,6 @@ "outputId": "5272df99-eb4b-4ec2-c513-504e067be2b6" }, "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "79d95a944b44423d9a2dd0082cdd80b0", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Downloading readme: 0%| | 0.00/7.83k [00:00 \u001b[39m\u001b[32m24\u001b[39m \u001b[43mindex\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupsert\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvectors\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mzip\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mids\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43membeds\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadatas\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\utils\\error_handling.py:30\u001b[39m, in \u001b[36mvalidate_and_convert_errors..inner_func\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 29\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m30\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\utils\\error_handling.py:15\u001b[39m, in \u001b[36mvalidate_and_convert_errors..inner_func\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 14\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m15\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 16\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 17\u001b[39m \u001b[38;5;66;03m# Lazy import of urllib3 exceptions\u001b[39;00m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\db_data\\index.py:212\u001b[39m, in \u001b[36mIndex.upsert\u001b[39m\u001b[34m(self, vectors, namespace, batch_size, show_progress, **kwargs)\u001b[39m\n\u001b[32m 211\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m batch_size \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m212\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_upsert_batch\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvectors\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespace\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 214\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(batch_size, \u001b[38;5;28mint\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m batch_size <= \u001b[32m0\u001b[39m:\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\db_data\\index.py:238\u001b[39m, in \u001b[36mIndex._upsert_batch\u001b[39m\u001b[34m(self, vectors, namespace, _check_type, **kwargs)\u001b[39m\n\u001b[32m 229\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m_upsert_batch\u001b[39m(\n\u001b[32m 230\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 231\u001b[39m vectors: Union[\n\u001b[32m (...)\u001b[39m\u001b[32m 236\u001b[39m **kwargs,\n\u001b[32m 237\u001b[39m ) -> UpsertResponse:\n\u001b[32m--> \u001b[39m\u001b[32m238\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_vector_api\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupsert_vectors\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 239\u001b[39m \u001b[43m \u001b[49m\u001b[43mIndexRequestFactory\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupsert_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvectors\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespace\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 240\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_openapi_kwargs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 241\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\endpoint.py:102\u001b[39m, in \u001b[36mEndpoint.__call__\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m 92\u001b[39m \u001b[38;5;250m\u001b[39m\u001b[33;03m\"\"\"This method is invoked when endpoints are called\u001b[39;00m\n\u001b[32m 93\u001b[39m \u001b[33;03mExample:\u001b[39;00m\n\u001b[32m 94\u001b[39m \n\u001b[32m (...)\u001b[39m\u001b[32m 100\u001b[39m \n\u001b[32m 101\u001b[39m \u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m102\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcallable\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\core\\openapi\\db_data\\api\\vector_operations_api.py:675\u001b[39m, in \u001b[36mVectorOperationsApi.__init__..__upsert_vectors\u001b[39m\u001b[34m(self, upsert_request, **kwargs)\u001b[39m\n\u001b[32m 674\u001b[39m kwargs[\u001b[33m\"\u001b[39m\u001b[33mupsert_request\u001b[39m\u001b[33m\"\u001b[39m] = upsert_request\n\u001b[32m--> \u001b[39m\u001b[32m675\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcall_with_http_info\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\endpoint.py:134\u001b[39m, in \u001b[36mEndpoint.call_with_http_info\u001b[39m\u001b[34m(self, **kwargs)\u001b[39m\n\u001b[32m 132\u001b[39m HeaderUtil.prepare_headers(headers_map=\u001b[38;5;28mself\u001b[39m.headers_map, params=params)\n\u001b[32m--> \u001b[39m\u001b[32m134\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mapi_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcall_api\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 135\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mendpoint_path\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 136\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mhttp_method\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 137\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mpath\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 138\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mquery\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 139\u001b[39m \u001b[43m \u001b[49m\u001b[43mheader_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mheader\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 140\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mbody\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 141\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mform\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 142\u001b[39m \u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfile\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 143\u001b[39m \u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mresponse_type\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 144\u001b[39m \u001b[43m \u001b[49m\u001b[43mauth_settings\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mauth\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 145\u001b[39m \u001b[43m \u001b[49m\u001b[43masync_req\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43masync_req\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 146\u001b[39m \u001b[43m \u001b[49m\u001b[43masync_threadpool_executor\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43masync_threadpool_executor\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 147\u001b[39m \u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_check_return_type\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 148\u001b[39m \u001b[43m \u001b[49m\u001b[43m_return_http_data_only\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_return_http_data_only\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 149\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_preload_content\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 150\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_request_timeout\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 151\u001b[39m \u001b[43m \u001b[49m\u001b[43m_host\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_host\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 152\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_formats\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mcollection_format\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 153\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:306\u001b[39m, in \u001b[36mApiClient.call_api\u001b[39m\u001b[34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, async_req, async_threadpool_executor, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)\u001b[39m\n\u001b[32m 305\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m async_req:\n\u001b[32m--> \u001b[39m\u001b[32m306\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m__call_api\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 307\u001b[39m \u001b[43m \u001b[49m\u001b[43mresource_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 308\u001b[39m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 309\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 310\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 311\u001b[39m \u001b[43m \u001b[49m\u001b[43mheader_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 312\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 313\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 314\u001b[39m \u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 315\u001b[39m \u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 316\u001b[39m \u001b[43m \u001b[49m\u001b[43mauth_settings\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 317\u001b[39m \u001b[43m \u001b[49m\u001b[43m_return_http_data_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 318\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_formats\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 319\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 320\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 321\u001b[39m \u001b[43m \u001b[49m\u001b[43m_host\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 322\u001b[39m \u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 323\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 325\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.pool.apply_async(\n\u001b[32m 326\u001b[39m \u001b[38;5;28mself\u001b[39m.__call_api,\n\u001b[32m 327\u001b[39m (\n\u001b[32m (...)\u001b[39m\u001b[32m 344\u001b[39m ),\n\u001b[32m 345\u001b[39m )\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:182\u001b[39m, in \u001b[36mApiClient.__call_api\u001b[39m\u001b[34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)\u001b[39m\n\u001b[32m 181\u001b[39m e.body = e.body.decode(\u001b[33m\"\u001b[39m\u001b[33mutf-8\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m--> \u001b[39m\u001b[32m182\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[32m 184\u001b[39m \u001b[38;5;28mself\u001b[39m.last_response = response_data\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:170\u001b[39m, in \u001b[36mApiClient.__call_api\u001b[39m\u001b[34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)\u001b[39m\n\u001b[32m 168\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m 169\u001b[39m \u001b[38;5;66;03m# perform request and return response\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m170\u001b[39m response_data = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 171\u001b[39m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 172\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 173\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mprocessed_query_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 174\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders_tuple\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 175\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mprocessed_post_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 176\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 177\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 178\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 179\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 180\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m PineconeApiException \u001b[38;5;28;01mas\u001b[39;00m e:\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:386\u001b[39m, in \u001b[36mApiClient.request\u001b[39m\u001b[34m(self, method, url, query_params, headers, post_params, body, _preload_content, _request_timeout)\u001b[39m\n\u001b[32m 385\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m method == \u001b[33m\"\u001b[39m\u001b[33mPOST\u001b[39m\u001b[33m\"\u001b[39m:\n\u001b[32m--> \u001b[39m\u001b[32m386\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrest_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43mPOST\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 387\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 388\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 389\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 390\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 391\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 392\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 393\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 394\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 395\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m method == \u001b[33m\"\u001b[39m\u001b[33mPUT\u001b[39m\u001b[33m\"\u001b[39m:\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\rest_utils.py:146\u001b[39m, in \u001b[36mRestClientInterface.POST\u001b[39m\u001b[34m(self, url, headers, query_params, post_params, body, _preload_content, _request_timeout)\u001b[39m\n\u001b[32m 136\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mPOST\u001b[39m(\n\u001b[32m 137\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 138\u001b[39m url,\n\u001b[32m (...)\u001b[39m\u001b[32m 144\u001b[39m _request_timeout=\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[32m 145\u001b[39m ):\n\u001b[32m--> \u001b[39m\u001b[32m146\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 147\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mPOST\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 148\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 149\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 150\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 151\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 152\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 153\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 154\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 155\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\rest_urllib3.py:267\u001b[39m, in \u001b[36mUrllib3RestClient.request\u001b[39m\u001b[34m(self, method, url, query_params, headers, body, post_params, _preload_content, _request_timeout)\u001b[39m\n\u001b[32m 265\u001b[39m logger.debug(\u001b[33m\"\u001b[39m\u001b[33mresponse body: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[33m\"\u001b[39m, r.data)\n\u001b[32m--> \u001b[39m\u001b[32m267\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mraise_exceptions_or_return\u001b[49m\u001b[43m(\u001b[49m\u001b[43mr\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\rest_utils.py:49\u001b[39m, in \u001b[36mraise_exceptions_or_return\u001b[39m\u001b[34m(r)\u001b[39m\n\u001b[32m 47\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m ServiceException(http_resp=r)\n\u001b[32m---> \u001b[39m\u001b[32m49\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m PineconeApiException(http_resp=r)\n\u001b[32m 51\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m r\n", + "\u001b[31mPineconeApiException\u001b[39m: (429)\nReason: Too Many Requests\nHTTP response headers: HTTPHeaderDict({'Date': 'Wed, 09 Jul 2025 06:44:29 GMT', 'Content-Type': 'application/json', 'Content-Length': '166', 'Connection': 'keep-alive', 'x-pinecone-request-latency-ms': '701', 'x-pinecone-request-id': '3900709124805469048', 'x-envoy-upstream-service-time': '5', 'server': 'envoy'})\nHTTP response body: {\"code\":8,\"message\":\"Request failed. You've reached your write unit limit for the current month (2000000). To continue writing data, upgrade your plan.\",\"details\":[]}\n", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[31mPineconeApiException\u001b[39m Traceback (most recent call last)", + " \u001b[31m[... skipping hidden 1 frame]\u001b[39m\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[10]\u001b[39m\u001b[32m, line 24\u001b[39m\n\u001b[32m 23\u001b[39m \u001b[38;5;66;03m# add everything to pinecone\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m24\u001b[39m \u001b[43mindex\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupsert\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvectors\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mzip\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mids\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43membeds\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadatas\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\utils\\error_handling.py:30\u001b[39m, in \u001b[36mvalidate_and_convert_errors..inner_func\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 29\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m30\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\utils\\error_handling.py:15\u001b[39m, in \u001b[36mvalidate_and_convert_errors..inner_func\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 14\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m15\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 16\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 17\u001b[39m \u001b[38;5;66;03m# Lazy import of urllib3 exceptions\u001b[39;00m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\db_data\\index.py:212\u001b[39m, in \u001b[36mIndex.upsert\u001b[39m\u001b[34m(self, vectors, namespace, batch_size, show_progress, **kwargs)\u001b[39m\n\u001b[32m 211\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m batch_size \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m212\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_upsert_batch\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvectors\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespace\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 214\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(batch_size, \u001b[38;5;28mint\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m batch_size <= \u001b[32m0\u001b[39m:\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\db_data\\index.py:238\u001b[39m, in \u001b[36mIndex._upsert_batch\u001b[39m\u001b[34m(self, vectors, namespace, _check_type, **kwargs)\u001b[39m\n\u001b[32m 229\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m_upsert_batch\u001b[39m(\n\u001b[32m 230\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 231\u001b[39m vectors: Union[\n\u001b[32m (...)\u001b[39m\u001b[32m 236\u001b[39m **kwargs,\n\u001b[32m 237\u001b[39m ) -> UpsertResponse:\n\u001b[32m--> \u001b[39m\u001b[32m238\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_vector_api\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupsert_vectors\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 239\u001b[39m \u001b[43m \u001b[49m\u001b[43mIndexRequestFactory\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupsert_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvectors\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespace\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 240\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_openapi_kwargs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 241\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\endpoint.py:102\u001b[39m, in \u001b[36mEndpoint.__call__\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m 92\u001b[39m \u001b[38;5;250m\u001b[39m\u001b[33;03m\"\"\"This method is invoked when endpoints are called\u001b[39;00m\n\u001b[32m 93\u001b[39m \u001b[33;03mExample:\u001b[39;00m\n\u001b[32m 94\u001b[39m \n\u001b[32m (...)\u001b[39m\u001b[32m 100\u001b[39m \n\u001b[32m 101\u001b[39m \u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m102\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcallable\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\core\\openapi\\db_data\\api\\vector_operations_api.py:675\u001b[39m, in \u001b[36mVectorOperationsApi.__init__..__upsert_vectors\u001b[39m\u001b[34m(self, upsert_request, **kwargs)\u001b[39m\n\u001b[32m 674\u001b[39m kwargs[\u001b[33m\"\u001b[39m\u001b[33mupsert_request\u001b[39m\u001b[33m\"\u001b[39m] = upsert_request\n\u001b[32m--> \u001b[39m\u001b[32m675\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcall_with_http_info\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\endpoint.py:134\u001b[39m, in \u001b[36mEndpoint.call_with_http_info\u001b[39m\u001b[34m(self, **kwargs)\u001b[39m\n\u001b[32m 132\u001b[39m HeaderUtil.prepare_headers(headers_map=\u001b[38;5;28mself\u001b[39m.headers_map, params=params)\n\u001b[32m--> \u001b[39m\u001b[32m134\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mapi_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcall_api\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 135\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mendpoint_path\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 136\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mhttp_method\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 137\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mpath\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 138\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mquery\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 139\u001b[39m \u001b[43m \u001b[49m\u001b[43mheader_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mheader\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 140\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mbody\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 141\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mform\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 142\u001b[39m \u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfile\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 143\u001b[39m \u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mresponse_type\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 144\u001b[39m \u001b[43m \u001b[49m\u001b[43mauth_settings\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mauth\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 145\u001b[39m \u001b[43m \u001b[49m\u001b[43masync_req\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43masync_req\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 146\u001b[39m \u001b[43m \u001b[49m\u001b[43masync_threadpool_executor\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43masync_threadpool_executor\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 147\u001b[39m \u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_check_return_type\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 148\u001b[39m \u001b[43m \u001b[49m\u001b[43m_return_http_data_only\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_return_http_data_only\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 149\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_preload_content\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 150\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_request_timeout\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 151\u001b[39m \u001b[43m \u001b[49m\u001b[43m_host\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_host\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 152\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_formats\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mcollection_format\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 153\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:306\u001b[39m, in \u001b[36mApiClient.call_api\u001b[39m\u001b[34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, async_req, async_threadpool_executor, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)\u001b[39m\n\u001b[32m 305\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m async_req:\n\u001b[32m--> \u001b[39m\u001b[32m306\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m__call_api\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 307\u001b[39m \u001b[43m \u001b[49m\u001b[43mresource_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 308\u001b[39m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 309\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 310\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 311\u001b[39m \u001b[43m \u001b[49m\u001b[43mheader_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 312\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 313\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 314\u001b[39m \u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 315\u001b[39m \u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 316\u001b[39m \u001b[43m \u001b[49m\u001b[43mauth_settings\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 317\u001b[39m \u001b[43m \u001b[49m\u001b[43m_return_http_data_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 318\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_formats\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 319\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 320\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 321\u001b[39m \u001b[43m \u001b[49m\u001b[43m_host\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 322\u001b[39m \u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 323\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 325\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.pool.apply_async(\n\u001b[32m 326\u001b[39m \u001b[38;5;28mself\u001b[39m.__call_api,\n\u001b[32m 327\u001b[39m (\n\u001b[32m (...)\u001b[39m\u001b[32m 344\u001b[39m ),\n\u001b[32m 345\u001b[39m )\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:182\u001b[39m, in \u001b[36mApiClient.__call_api\u001b[39m\u001b[34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)\u001b[39m\n\u001b[32m 181\u001b[39m e.body = e.body.decode(\u001b[33m\"\u001b[39m\u001b[33mutf-8\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m--> \u001b[39m\u001b[32m182\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[32m 184\u001b[39m \u001b[38;5;28mself\u001b[39m.last_response = response_data\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:170\u001b[39m, in \u001b[36mApiClient.__call_api\u001b[39m\u001b[34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)\u001b[39m\n\u001b[32m 168\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m 169\u001b[39m \u001b[38;5;66;03m# perform request and return response\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m170\u001b[39m response_data = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 171\u001b[39m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 172\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 173\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mprocessed_query_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 174\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders_tuple\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 175\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mprocessed_post_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 176\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 177\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 178\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 179\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 180\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m PineconeApiException \u001b[38;5;28;01mas\u001b[39;00m e:\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:386\u001b[39m, in \u001b[36mApiClient.request\u001b[39m\u001b[34m(self, method, url, query_params, headers, post_params, body, _preload_content, _request_timeout)\u001b[39m\n\u001b[32m 385\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m method == \u001b[33m\"\u001b[39m\u001b[33mPOST\u001b[39m\u001b[33m\"\u001b[39m:\n\u001b[32m--> \u001b[39m\u001b[32m386\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrest_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43mPOST\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 387\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 388\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 389\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 390\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 391\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 392\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 393\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 394\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 395\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m method == \u001b[33m\"\u001b[39m\u001b[33mPUT\u001b[39m\u001b[33m\"\u001b[39m:\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\rest_utils.py:146\u001b[39m, in \u001b[36mRestClientInterface.POST\u001b[39m\u001b[34m(self, url, headers, query_params, post_params, body, _preload_content, _request_timeout)\u001b[39m\n\u001b[32m 136\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mPOST\u001b[39m(\n\u001b[32m 137\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 138\u001b[39m url,\n\u001b[32m (...)\u001b[39m\u001b[32m 144\u001b[39m _request_timeout=\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[32m 145\u001b[39m ):\n\u001b[32m--> \u001b[39m\u001b[32m146\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 147\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mPOST\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 148\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 149\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 150\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 151\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 152\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 153\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 154\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 155\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\rest_urllib3.py:267\u001b[39m, in \u001b[36mUrllib3RestClient.request\u001b[39m\u001b[34m(self, method, url, query_params, headers, body, post_params, _preload_content, _request_timeout)\u001b[39m\n\u001b[32m 265\u001b[39m logger.debug(\u001b[33m\"\u001b[39m\u001b[33mresponse body: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[33m\"\u001b[39m, r.data)\n\u001b[32m--> \u001b[39m\u001b[32m267\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mraise_exceptions_or_return\u001b[49m\u001b[43m(\u001b[49m\u001b[43mr\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\rest_utils.py:49\u001b[39m, in \u001b[36mraise_exceptions_or_return\u001b[39m\u001b[34m(r)\u001b[39m\n\u001b[32m 47\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m ServiceException(http_resp=r)\n\u001b[32m---> \u001b[39m\u001b[32m49\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m PineconeApiException(http_resp=r)\n\u001b[32m 51\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m r\n", + "\u001b[31mPineconeApiException\u001b[39m: (429)\nReason: Too Many Requests\nHTTP response headers: HTTPHeaderDict({'Date': 'Wed, 09 Jul 2025 06:44:29 GMT', 'Content-Type': 'application/json', 'Content-Length': '166', 'Connection': 'keep-alive', 'x-pinecone-request-latency-ms': '701', 'x-pinecone-request-id': '3900709124805469048', 'x-envoy-upstream-service-time': '5', 'server': 'envoy'})\nHTTP response body: {\"code\":8,\"message\":\"Request failed. You've reached your write unit limit for the current month (2000000). To continue writing data, upgrade your plan.\",\"details\":[]}\n", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[31mPineconeApiException\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[10]\u001b[39m\u001b[32m, line 24\u001b[39m\n\u001b[32m 22\u001b[39m ids = batch[\u001b[33m'\u001b[39m\u001b[33mid\u001b[39m\u001b[33m'\u001b[39m]\n\u001b[32m 23\u001b[39m \u001b[38;5;66;03m# add everything to pinecone\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m24\u001b[39m \u001b[43mindex\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupsert\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvectors\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mzip\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mids\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43membeds\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadatas\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\utils\\error_handling.py:30\u001b[39m, in \u001b[36mvalidate_and_convert_errors..inner_func\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 26\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m ProtocolError(\n\u001b[32m 27\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mConnection failed. Please verify that the index host is correct and accessible.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 28\u001b[39m ) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n\u001b[32m 29\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m30\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\utils\\error_handling.py:15\u001b[39m, in \u001b[36mvalidate_and_convert_errors..inner_func\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 12\u001b[39m \u001b[38;5;129m@wraps\u001b[39m(func)\n\u001b[32m 13\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34minner_func\u001b[39m(*args, **kwargs):\n\u001b[32m 14\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m15\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 16\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 17\u001b[39m \u001b[38;5;66;03m# Lazy import of urllib3 exceptions\u001b[39;00m\n\u001b[32m 18\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01murllib3\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mexceptions\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m MaxRetryError, ProtocolError \u001b[38;5;28;01mas\u001b[39;00m Urllib3ProtocolError\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\db_data\\index.py:212\u001b[39m, in \u001b[36mIndex.upsert\u001b[39m\u001b[34m(self, vectors, namespace, batch_size, show_progress, **kwargs)\u001b[39m\n\u001b[32m 205\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[32m 206\u001b[39m \u001b[33m\"\u001b[39m\u001b[33masync_req is not supported when batch_size is provided.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 207\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mTo upsert in parallel, please follow: \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 208\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mhttps://docs.pinecone.io/docs/insert-data#sending-upserts-in-parallel\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 209\u001b[39m )\n\u001b[32m 211\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m batch_size \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m212\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_upsert_batch\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvectors\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespace\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 214\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(batch_size, \u001b[38;5;28mint\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m batch_size <= \u001b[32m0\u001b[39m:\n\u001b[32m 215\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[33m\"\u001b[39m\u001b[33mbatch_size must be a positive integer\u001b[39m\u001b[33m\"\u001b[39m)\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\db_data\\index.py:238\u001b[39m, in \u001b[36mIndex._upsert_batch\u001b[39m\u001b[34m(self, vectors, namespace, _check_type, **kwargs)\u001b[39m\n\u001b[32m 229\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m_upsert_batch\u001b[39m(\n\u001b[32m 230\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 231\u001b[39m vectors: Union[\n\u001b[32m (...)\u001b[39m\u001b[32m 236\u001b[39m **kwargs,\n\u001b[32m 237\u001b[39m ) -> UpsertResponse:\n\u001b[32m--> \u001b[39m\u001b[32m238\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_vector_api\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupsert_vectors\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 239\u001b[39m \u001b[43m \u001b[49m\u001b[43mIndexRequestFactory\u001b[49m\u001b[43m.\u001b[49m\u001b[43mupsert_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvectors\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespace\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 240\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_openapi_kwargs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 241\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\endpoint.py:102\u001b[39m, in \u001b[36mEndpoint.__call__\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m 91\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, *args, **kwargs):\n\u001b[32m 92\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"This method is invoked when endpoints are called\u001b[39;00m\n\u001b[32m 93\u001b[39m \u001b[33;03m Example:\u001b[39;00m\n\u001b[32m 94\u001b[39m \n\u001b[32m (...)\u001b[39m\u001b[32m 100\u001b[39m \n\u001b[32m 101\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m102\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcallable\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\core\\openapi\\db_data\\api\\vector_operations_api.py:675\u001b[39m, in \u001b[36mVectorOperationsApi.__init__..__upsert_vectors\u001b[39m\u001b[34m(self, upsert_request, **kwargs)\u001b[39m\n\u001b[32m 673\u001b[39m kwargs = \u001b[38;5;28mself\u001b[39m._process_openapi_kwargs(kwargs)\n\u001b[32m 674\u001b[39m kwargs[\u001b[33m\"\u001b[39m\u001b[33mupsert_request\u001b[39m\u001b[33m\"\u001b[39m] = upsert_request\n\u001b[32m--> \u001b[39m\u001b[32m675\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcall_with_http_info\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\endpoint.py:134\u001b[39m, in \u001b[36mEndpoint.call_with_http_info\u001b[39m\u001b[34m(self, **kwargs)\u001b[39m\n\u001b[32m 124\u001b[39m params = EndpointUtils.gather_params(\n\u001b[32m 125\u001b[39m attribute_map=\u001b[38;5;28mself\u001b[39m.attribute_map,\n\u001b[32m 126\u001b[39m location_map=\u001b[38;5;28mself\u001b[39m.location_map,\n\u001b[32m (...)\u001b[39m\u001b[32m 129\u001b[39m kwargs=kwargs,\n\u001b[32m 130\u001b[39m )\n\u001b[32m 132\u001b[39m HeaderUtil.prepare_headers(headers_map=\u001b[38;5;28mself\u001b[39m.headers_map, params=params)\n\u001b[32m--> \u001b[39m\u001b[32m134\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mapi_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcall_api\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 135\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mendpoint_path\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 136\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mhttp_method\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 137\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mpath\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 138\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mquery\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 139\u001b[39m \u001b[43m \u001b[49m\u001b[43mheader_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mheader\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 140\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mbody\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 141\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mform\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 142\u001b[39m \u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfile\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 143\u001b[39m \u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mresponse_type\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 144\u001b[39m \u001b[43m \u001b[49m\u001b[43mauth_settings\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msettings\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mauth\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 145\u001b[39m \u001b[43m \u001b[49m\u001b[43masync_req\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43masync_req\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 146\u001b[39m \u001b[43m \u001b[49m\u001b[43masync_threadpool_executor\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43masync_threadpool_executor\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 147\u001b[39m \u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_check_return_type\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 148\u001b[39m \u001b[43m \u001b[49m\u001b[43m_return_http_data_only\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_return_http_data_only\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 149\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_preload_content\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 150\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m_request_timeout\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 151\u001b[39m \u001b[43m \u001b[49m\u001b[43m_host\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_host\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 152\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_formats\u001b[49m\u001b[43m=\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mcollection_format\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 153\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:306\u001b[39m, in \u001b[36mApiClient.call_api\u001b[39m\u001b[34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, async_req, async_threadpool_executor, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)\u001b[39m\n\u001b[32m 285\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.threadpool_executor.submit(\n\u001b[32m 286\u001b[39m \u001b[38;5;28mself\u001b[39m.__call_api,\n\u001b[32m 287\u001b[39m resource_path,\n\u001b[32m (...)\u001b[39m\u001b[32m 302\u001b[39m _check_type,\n\u001b[32m 303\u001b[39m )\n\u001b[32m 305\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m async_req:\n\u001b[32m--> \u001b[39m\u001b[32m306\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m__call_api\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 307\u001b[39m \u001b[43m \u001b[49m\u001b[43mresource_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 308\u001b[39m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 309\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 310\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 311\u001b[39m \u001b[43m \u001b[49m\u001b[43mheader_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 312\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 313\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 314\u001b[39m \u001b[43m \u001b[49m\u001b[43mfiles\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 315\u001b[39m \u001b[43m \u001b[49m\u001b[43mresponse_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 316\u001b[39m \u001b[43m \u001b[49m\u001b[43mauth_settings\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 317\u001b[39m \u001b[43m \u001b[49m\u001b[43m_return_http_data_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 318\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_formats\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 319\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 320\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 321\u001b[39m \u001b[43m \u001b[49m\u001b[43m_host\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 322\u001b[39m \u001b[43m \u001b[49m\u001b[43m_check_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 323\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 325\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.pool.apply_async(\n\u001b[32m 326\u001b[39m \u001b[38;5;28mself\u001b[39m.__call_api,\n\u001b[32m 327\u001b[39m (\n\u001b[32m (...)\u001b[39m\u001b[32m 344\u001b[39m ),\n\u001b[32m 345\u001b[39m )\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:182\u001b[39m, in \u001b[36mApiClient.__call_api\u001b[39m\u001b[34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)\u001b[39m\n\u001b[32m 180\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m PineconeApiException \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 181\u001b[39m e.body = e.body.decode(\u001b[33m\"\u001b[39m\u001b[33mutf-8\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m--> \u001b[39m\u001b[32m182\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[32m 184\u001b[39m \u001b[38;5;28mself\u001b[39m.last_response = response_data\n\u001b[32m 186\u001b[39m return_data = response_data\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:170\u001b[39m, in \u001b[36mApiClient.__call_api\u001b[39m\u001b[34m(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host, _check_type)\u001b[39m\n\u001b[32m 161\u001b[39m url = build_request_url(\n\u001b[32m 162\u001b[39m config=config,\n\u001b[32m 163\u001b[39m processed_path_params=path_params_tuple,\n\u001b[32m 164\u001b[39m resource_path=resource_path,\n\u001b[32m 165\u001b[39m _host=_host,\n\u001b[32m 166\u001b[39m )\n\u001b[32m 168\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m 169\u001b[39m \u001b[38;5;66;03m# perform request and return response\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m170\u001b[39m response_data = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 171\u001b[39m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 172\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 173\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mprocessed_query_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 174\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders_tuple\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 175\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mprocessed_post_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 176\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 177\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 178\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 179\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 180\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m PineconeApiException \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 181\u001b[39m e.body = e.body.decode(\u001b[33m\"\u001b[39m\u001b[33mutf-8\u001b[39m\u001b[33m\"\u001b[39m)\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\api_client.py:386\u001b[39m, in \u001b[36mApiClient.request\u001b[39m\u001b[34m(self, method, url, query_params, headers, post_params, body, _preload_content, _request_timeout)\u001b[39m\n\u001b[32m 376\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.rest_client.OPTIONS(\n\u001b[32m 377\u001b[39m url,\n\u001b[32m 378\u001b[39m query_params=query_params,\n\u001b[32m (...)\u001b[39m\u001b[32m 383\u001b[39m body=body,\n\u001b[32m 384\u001b[39m )\n\u001b[32m 385\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m method == \u001b[33m\"\u001b[39m\u001b[33mPOST\u001b[39m\u001b[33m\"\u001b[39m:\n\u001b[32m--> \u001b[39m\u001b[32m386\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrest_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43mPOST\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 387\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 388\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 389\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 390\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 391\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 392\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 393\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 394\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 395\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m method == \u001b[33m\"\u001b[39m\u001b[33mPUT\u001b[39m\u001b[33m\"\u001b[39m:\n\u001b[32m 396\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.rest_client.PUT(\n\u001b[32m 397\u001b[39m url,\n\u001b[32m 398\u001b[39m query_params=query_params,\n\u001b[32m (...)\u001b[39m\u001b[32m 403\u001b[39m body=body,\n\u001b[32m 404\u001b[39m )\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\rest_utils.py:146\u001b[39m, in \u001b[36mRestClientInterface.POST\u001b[39m\u001b[34m(self, url, headers, query_params, post_params, body, _preload_content, _request_timeout)\u001b[39m\n\u001b[32m 136\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mPOST\u001b[39m(\n\u001b[32m 137\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 138\u001b[39m url,\n\u001b[32m (...)\u001b[39m\u001b[32m 144\u001b[39m _request_timeout=\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[32m 145\u001b[39m ):\n\u001b[32m--> \u001b[39m\u001b[32m146\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 147\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mPOST\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 148\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 149\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 150\u001b[39m \u001b[43m \u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mquery_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 151\u001b[39m \u001b[43m \u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpost_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 152\u001b[39m \u001b[43m \u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_preload_content\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 153\u001b[39m \u001b[43m \u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43m_request_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 154\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 155\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\rest_urllib3.py:267\u001b[39m, in \u001b[36mUrllib3RestClient.request\u001b[39m\u001b[34m(self, method, url, query_params, headers, body, post_params, _preload_content, _request_timeout)\u001b[39m\n\u001b[32m 264\u001b[39m \u001b[38;5;66;03m# log response body\u001b[39;00m\n\u001b[32m 265\u001b[39m logger.debug(\u001b[33m\"\u001b[39m\u001b[33mresponse body: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[33m\"\u001b[39m, r.data)\n\u001b[32m--> \u001b[39m\u001b[32m267\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mraise_exceptions_or_return\u001b[49m\u001b[43m(\u001b[49m\u001b[43mr\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\Siraj\\Documents\\Pinecone\\venvs\\pinecone1\\Lib\\site-packages\\pinecone\\openapi_support\\rest_utils.py:49\u001b[39m, in \u001b[36mraise_exceptions_or_return\u001b[39m\u001b[34m(r)\u001b[39m\n\u001b[32m 46\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[32m500\u001b[39m <= r.status <= \u001b[32m599\u001b[39m:\n\u001b[32m 47\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m ServiceException(http_resp=r)\n\u001b[32m---> \u001b[39m\u001b[32m49\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m PineconeApiException(http_resp=r)\n\u001b[32m 51\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m r\n", + "\u001b[31mPineconeApiException\u001b[39m: (429)\nReason: Too Many Requests\nHTTP response headers: HTTPHeaderDict({'Date': 'Wed, 09 Jul 2025 06:44:29 GMT', 'Content-Type': 'application/json', 'Content-Length': '166', 'Connection': 'keep-alive', 'x-pinecone-request-latency-ms': '701', 'x-pinecone-request-id': '3900709124805469048', 'x-envoy-upstream-service-time': '5', 'server': 'envoy'})\nHTTP response body: {\"code\":8,\"message\":\"Request failed. You've reached your write unit limit for the current month (2000000). To continue writing data, upgrade your plan.\",\"details\":[]}\n" + ] } ], "source": [ @@ -709,7 +706,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -723,11 +720,13 @@ "text/plain": [ "{'dimension': 1536,\n", " 'index_fullness': 0.0,\n", + " 'metric': 'dotproduct',\n", " 'namespaces': {'': {'vector_count': 18891}},\n", - " 'total_vector_count': 18891}" + " 'total_vector_count': 18891,\n", + " 'vector_type': 'dense'}" ] }, - "execution_count": 10, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -758,29 +757,16 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": { "id": "0MBJ477-cFNw" }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/jamesbriggs/opt/anaconda3/envs/ml/lib/python3.9/site-packages/langchain_community/vectorstores/pinecone.py:74: UserWarning: Passing in `embedding` as a Callable is deprecated. Please pass in an Embeddings object instead.\n", - " warnings.warn(\n" - ] - } - ], + "outputs": [], "source": [ - "from langchain.vectorstores import Pinecone\n", - "\n", - "text_field = \"text\" # the metadata field that contains our text\n", + "from langchain_pinecone import PineconeVectorStore\n", "\n", "# initialize the vector store object\n", - "vectorstore = Pinecone(\n", - " index, embed.embed_query, text_field\n", - ")" + "vectorstore = PineconeVectorStore(index=index, embedding=embed)" ] }, { @@ -795,7 +781,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -807,12 +793,12 @@ { "data": { "text/plain": [ - "[Document(page_content=\"In 1919 Father James Burns became president of Notre Dame, and in three years he produced an academic revolution that brought the school up to national standards by adopting the elective system and moving away from the university's traditional scholastic and classical emphasis. By contrast, the Jesuit colleges, bastions of academic conservatism, were reluctant to move to a system of electives. Their graduates were shut out of Harvard Law School for that reason. Notre Dame continued to grow over the years, adding more colleges, programs, and sports teams. By 1921, with the addition of the College of Commerce, Notre Dame had grown from a small college to a university with five colleges and a professional law school. The university continued to expand and add new residence halls and buildings with each subsequent president.\", metadata={'title': 'University_of_Notre_Dame'}),\n", - " Document(page_content='The College of Engineering was established in 1920, however, early courses in civil and mechanical engineering were a part of the College of Science since the 1870s. Today the college, housed in the Fitzpatrick, Cushing, and Stinson-Remick Halls of Engineering, includes five departments of study \u2013 aerospace and mechanical engineering, chemical and biomolecular engineering, civil engineering and geological sciences, computer science and engineering, and electrical engineering \u2013 with eight B.S. degrees offered. Additionally, the college offers five-year dual degree programs with the Colleges of Arts and Letters and of Business awarding additional B.A. and Master of Business Administration (MBA) degrees, respectively.', metadata={'title': 'University_of_Notre_Dame'}),\n", - " Document(page_content='Since 2005, Notre Dame has been led by John I. Jenkins, C.S.C., the 17th president of the university. Jenkins took over the position from Malloy on July 1, 2005. In his inaugural address, Jenkins described his goals of making the university a leader in research that recognizes ethics and building the connection between faith and studies. During his tenure, Notre Dame has increased its endowment, enlarged its student body, and undergone many construction projects on campus, including Compton Family Ice Arena, a new architecture hall, additional residence halls, and the Campus Crossroads, a $400m enhancement and expansion of Notre Dame Stadium.', metadata={'title': 'University_of_Notre_Dame'})]" + "[Document(id='57338724d058e614000b5c9f', metadata={'title': 'University_of_Notre_Dame'}, page_content=\"In 1919 Father James Burns became president of Notre Dame, and in three years he produced an academic revolution that brought the school up to national standards by adopting the elective system and moving away from the university's traditional scholastic and classical emphasis. By contrast, the Jesuit colleges, bastions of academic conservatism, were reluctant to move to a system of electives. Their graduates were shut out of Harvard Law School for that reason. Notre Dame continued to grow over the years, adding more colleges, programs, and sports teams. By 1921, with the addition of the College of Commerce, Notre Dame had grown from a small college to a university with five colleges and a professional law school. The university continued to expand and add new residence halls and buildings with each subsequent president.\"),\n", + " Document(id='573393e1d058e614000b5dc2', metadata={'title': 'University_of_Notre_Dame'}, page_content='Hesburgh is also credited with transforming the face of Notre Dame by making it a coeducational institution. In the mid-1960s Notre Dame and Saint Mary\\'s College developed a co-exchange program whereby several hundred students took classes not offered at their home institution, an arrangement that added undergraduate women to a campus that already had a few women in the graduate schools. After extensive debate, merging with St. Mary\\'s was rejected, primarily because of the differential in faculty qualifications and pay scales. \"In American college education,\" explained the Rev. Charles E. Sheedy, C.S.C., Notre Dame\\'s Dean of Arts and Letters, \"certain features formerly considered advantageous and enviable are now seen as anachronistic and out of place.... In this environment of diversity, the integration of the sexes is a normal and expected aspect, replacing separatism.\" Thomas Blantz, C.S.C., Notre Dame\\'s Vice President of Student Affairs, added that coeducation \"opened up a whole other pool of very bright students.\" Two of the male residence halls were converted for the newly admitted female students that first year, while two others were converted for the next school year. In 1971 Mary Ann Proctor became the first female undergraduate; she transferred from St. Mary\\'s College. In 1972 the first woman to graduate was Angela Sienko, who earned a bachelor\\'s degree in marketing.'),\n", + " Document(id='5733a6424776f41900660f51', metadata={'title': 'University_of_Notre_Dame'}, page_content='The College of Engineering was established in 1920, however, early courses in civil and mechanical engineering were a part of the College of Science since the 1870s. Today the college, housed in the Fitzpatrick, Cushing, and Stinson-Remick Halls of Engineering, includes five departments of study – aerospace and mechanical engineering, chemical and biomolecular engineering, civil engineering and geological sciences, computer science and engineering, and electrical engineering – with eight B.S. degrees offered. Additionally, the college offers five-year dual degree programs with the Colleges of Arts and Letters and of Business awarding additional B.A. and Master of Business Administration (MBA) degrees, respectively.')]" ] }, - "execution_count": 12, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -833,7 +819,14 @@ "id": "-zGF6YsgczqT" }, "source": [ - "Looks like we're getting good results. Let's take a look at how we can begin integrating this into a conversational agent." + "Looks like we're getting good results. \n", + "\n", + "Let's keep this exact sentence in mind for future reference:\n", + "\n", + "> In 1919 Father James Burns became president of Notre Dame, and in three years he produced an academic revolution that brought the school up to national standards by adopting the elective system and moving away from the university's traditional scholastic and classical emphasis.\n", + "\n", + "\n", + "Let's take a look at how we can begin integrating this into a conversational agent." ] }, { @@ -853,38 +846,46 @@ "id": "XMv6TXWkdfNR" }, "source": [ - "Our conversational agent needs a Chat LLM, conversational memory, and a `RetrievalQA` chain to initialize. We create these using:" + "Our conversational agent needs several components:\n", + "1. A Chat LLM for generating responses\n", + "2. A QA chain for retrieving and processing information\n", + "3. A chat history manager for maintaining conversation context\n", + "Let's create these using modern LangChain Expression Language (LCEL):" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": { "id": "zMRs9Klic5-Y" }, "outputs": [], "source": [ - "from langchain.chat_models import ChatOpenAI\n", - "from langchain.chains.conversation.memory import ConversationBufferWindowMemory\n", - "from langchain.chains import RetrievalQA\n", + "from langchain_openai import ChatOpenAI\n", + "from langchain_core.prompts import ChatPromptTemplate\n", + "from langchain_core.runnables import RunnableSerializable\n", "\n", - "# chat completion llm\n", "llm = ChatOpenAI(\n", " openai_api_key=OPENAI_API_KEY,\n", - " model_name='gpt-3.5-turbo',\n", - " temperature=0.0\n", - ")\n", - "# conversational memory\n", - "conversational_memory = ConversationBufferWindowMemory(\n", - " memory_key='chat_history',\n", - " k=5,\n", - " return_messages=True\n", + " model_name=\"gpt-4o-mini\",\n", + " temperature=0.0,\n", ")\n", - "# retrieval qa chain\n", - "qa = RetrievalQA.from_chain_type(\n", - " llm=llm,\n", - " chain_type=\"stuff\",\n", - " retriever=vectorstore.as_retriever()\n", + "\n", + "# First create the basic QA chain\n", + "qa_prompt = ChatPromptTemplate.from_messages([\n", + " (\"system\", \"Answer the question based on the following context:\"),\n", + " (\"system\", \"{context}\"),\n", + " (\"human\", \"{question}\")\n", + "])\n", + "\n", + "# Create the QA chain\n", + "qa: RunnableSerializable = (\n", + " {\n", + " \"context\": lambda x: x[\"context\"],\n", + " \"question\": lambda x: x[\"question\"]\n", + " }\n", + " | qa_prompt\n", + " | llm\n", ")" ] }, @@ -900,7 +901,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -911,18 +912,22 @@ }, "outputs": [ { - "data": { - "text/plain": [ - "'The College of Engineering at the University of Notre Dame was established in 1920.'" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "QA Chain Response: The College of Engineering at Notre Dame was established in 1920.\n" + ] } ], "source": [ - "qa.run(query)" + "qa_response = qa.invoke({\n", + " \"question\": \"When was Notre Dame's College of Engineering established?\",\n", + " \"context\": vectorstore.similarity_search(\n", + " \"When was Notre Dame's College of Engineering established?\",\n", + " k=3\n", + " )\n", + "})\n", + "print(\"QA Chain Response:\", qa_response.content)" ] }, { @@ -937,296 +942,476 @@ }, { "cell_type": "code", - "execution_count": 15, - "metadata": { - "id": "FwCYrS4duqBW" - }, + "execution_count": 17, + "metadata": {}, "outputs": [], "source": [ - "from langchain.agents import Tool\n", + "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", + "from langchain_openai import ChatOpenAI\n", + "from langchain_core.tools import tool\n", + "from langchain_core.messages import BaseMessage, HumanMessage, AIMessage, ToolMessage\n", + "from langchain_core.runnables.base import RunnableSerializable\n", + "import json\n", "\n", - "tools = [\n", - " Tool(\n", - " name='Knowledge Base',\n", - " func=qa.run,\n", - " description=(\n", - " 'use this tool when answering general knowledge queries to get '\n", - " 'more information about the topic'\n", - " )\n", - " )\n", - "]" + "# Your existing knowledge_base tool\n", + "@tool\n", + "def knowledge_base(query: str) -> str:\n", + " \"\"\"Search the knowledge base for information about Notre Dame University.\n", + " Use this tool when users ask questions about Notre Dame University.\n", + " \n", + " Args:\n", + " query: The search query about Notre Dame University\n", + " \n", + " Returns:\n", + " Relevant information from the knowledge base\n", + " \"\"\"\n", + " try:\n", + " # Your existing vectorstore search logic\n", + " results = vectorstore.similarity_search(query, k=5)\n", + " if results:\n", + " context = \"\\n\".join([doc.page_content for doc in results])\n", + " return f\"Based on the knowledge base: {context}\"\n", + " else:\n", + " return \"No relevant information found in the knowledge base.\"\n", + " except Exception as e:\n", + " return f\"Error searching knowledge base: {str(e)}\"\n", + "\n", + "class BufferWindowMessageHistory:\n", + " def __init__(self, k: int = 5):\n", + " self.k = k\n", + " self.messages = []\n", + " \n", + " def add_message(self, message: BaseMessage):\n", + " self.messages.append(message)\n", + " if len(self.messages) > self.k:\n", + " self.messages = self.messages[-self.k:]\n", + " \n", + " def get_messages(self) -> list[BaseMessage]:\n", + " return self.messages\n", + "\n", + "# Create conversation memory\n", + "memory = BufferWindowMessageHistory(k=5)\n", + "\n", + "# Enhanced prompt that enforces memory usage and autonomous tool decisions\n", + "prompt = ChatPromptTemplate.from_messages([\n", + " (\"system\", \"\"\"You are a helpful assistant with access to a knowledge base about Notre Dame University.\n", + "\n", + "CRITICAL REQUIREMENTS:\n", + "1. ALWAYS review the conversation history and use it to inform your responses\n", + "2. ALWAYS provide a complete, non-empty response to the user\n", + "3. You may choose to use the knowledge_base tool if the user asks about Notre Dame University\n", + "4. If you use the knowledge_base tool, incorporate the retrieved information into your response\n", + "5. If you don't use the knowledge_base tool, respond normally using your knowledge and conversation history\n", + "6. Remember details from previous conversations and reference them when relevant\n", + "\n", + "Your response must NEVER be empty. Always provide meaningful, complete answers.\"\"\"),\n", + " MessagesPlaceholder(variable_name=\"chat_history\"),\n", + " (\"human\", \"{input}\"),\n", + " MessagesPlaceholder(variable_name=\"agent_scratchpad\"),\n", + "])\n", + "\n", + "# Create tools list (only knowledge_base, no final_answer tool)\n", + "tools = [knowledge_base]\n", + "\n", + "\n" ] }, { - "attachments": {}, "cell_type": "markdown", - "metadata": { - "id": "wXi_0ipTvM_l" - }, + "metadata": {}, "source": [ "Now we can initialize the agent like so:" ] }, { "cell_type": "code", - "execution_count": 16, - "metadata": { - "id": "JaKTzPUEvOoy" - }, + "execution_count": 18, + "metadata": {}, "outputs": [], "source": [ - "from langchain.agents import initialize_agent\n", + "# Create the agent\n", + "agent: RunnableSerializable = (\n", + " {\n", + " \"input\": lambda x: x[\"input\"],\n", + " \"chat_history\": lambda x: x[\"chat_history\"],\n", + " \"agent_scratchpad\": lambda x: x.get(\"agent_scratchpad\", [])\n", + " }\n", + " | prompt\n", + " | llm.bind_tools(tools, tool_choice=\"auto\") # Let LLM decide when to use tools\n", + " )\n", + "\n", + "# Enhanced AgentExecutor with explicit memory management\n", + "class AgentExecutor:\n", + " def __init__(self, agent, tools, memory, max_iterations: int = 3):\n", + " self.agent = agent\n", + " self.tools = tools\n", + " self.memory = memory\n", + " self.max_iterations = max_iterations\n", + " self.name2tool = {tool.name: tool.func for tool in tools}\n", + " \n", + " def invoke(self, input_text: str) -> dict:\n", + " \"\"\"Execute the agent with conversation memory\"\"\"\n", + " count = 0\n", + " agent_scratchpad = []\n", + " final_response = \"\"\n", + " tools_used = [] # Track which tools were used\n", "\n", - "agent = initialize_agent(\n", - " agent='chat-conversational-react-description',\n", + " chat_history_used = list(self.memory.get_messages()) \n", + " \n", + " while count < self.max_iterations:\n", + " # Get current chat history\n", + " chat_history = self.memory.get_messages()\n", + " \n", + " # Invoke the agent\n", + " response = self.agent.invoke({\n", + " \"input\": input_text,\n", + " \"chat_history\": chat_history,\n", + " \"agent_scratchpad\": agent_scratchpad\n", + " })\n", + " \n", + " # Check if the response contains tool calls\n", + " if response.tool_calls:\n", + " # Add the tool call to scratchpad\n", + " agent_scratchpad.append(response)\n", + " \n", + " # Execute each tool call\n", + " for tool_call in response.tool_calls:\n", + " tool_name = tool_call[\"name\"]\n", + " tool_args = tool_call[\"args\"]\n", + " tool_call_id = tool_call[\"id\"]\n", + " \n", + " # Execute the tool\n", + " tool_output = self.name2tool[tool_name](**tool_args)\n", + " \n", + " # Track tool usage\n", + " tools_used.append({\n", + " \"tool_name\": tool_name,\n", + " \"tool_args\": tool_args,\n", + " \"step\": count + 1\n", + " })\n", + " \n", + " # Create tool message\n", + " tool_message = ToolMessage(\n", + " content=str(tool_output),\n", + " tool_call_id=tool_call_id\n", + " )\n", + " agent_scratchpad.append(tool_message)\n", + " \n", + " print(f\"Step {count + 1}: Used {tool_name}({tool_args})\")\n", + " print(f\"\\nTool result: {tool_output}\\n\")\n", + " \n", + " count += 1\n", + " \n", + " # Continue to get the final response after tool usage\n", + " continue\n", + " else:\n", + " # No tool calls, this is the final response\n", + " final_response = response.content\n", + " break\n", + " \n", + " # If we've exhausted iterations and still have no final response, \n", + " # make one more call to get the final answer\n", + " if not final_response:\n", + " chat_history = self.memory.get_messages()\n", + " response = self.agent.invoke({\n", + " \"input\": input_text,\n", + " \"chat_history\": chat_history,\n", + " \"agent_scratchpad\": agent_scratchpad\n", + " })\n", + " final_response = response.content\n", + " \n", + " # Ensure response is not empty\n", + " if not final_response or final_response.strip() == \"\":\n", + " final_response = \"I apologize, but I wasn't able to generate a proper response. Please try asking your question again.\"\n", + "\n", + " # Add messages to memory\n", + " self.memory.add_message(HumanMessage(content=input_text))\n", + " self.memory.add_message(AIMessage(content=final_response))\n", + " \n", + " return {\n", + " \"input\": input_text,\n", + " \"output\": final_response,\n", + " \"tools_used\": tools_used, # Include which tools were used\n", + " \"chat_history_used\": chat_history_used,\n", + " \"chat_history_final\": self.memory.get_messages()\n", + " }\n", + "\n", + "# Create the executor\n", + "agent_executor = AgentExecutor(\n", + " agent=agent,\n", " tools=tools,\n", - " llm=llm,\n", - " verbose=True,\n", - " max_iterations=3,\n", - " early_stopping_method='generate',\n", - " memory=conversational_memory\n", + " memory=memory,\n", + " max_iterations=3\n", ")" ] }, { - "attachments": {}, "cell_type": "markdown", - "metadata": { - "id": "WbXl-AzVvszB" - }, + "metadata": {}, "source": [ - "With that our retrieval augmented conversational agent is ready and we can begin using it." + "### Using the Conversational Agent" ] }, { - "attachments": {}, "cell_type": "markdown", - "metadata": { - "id": "IlxUBWKcvzeP" - }, + "metadata": {}, "source": [ - "### Using the Conversational Agent" + "#### 1. Small Talk\n", + "\n", + "Let's use the agent with simple statement that shouldn't result in usage of the `knowledge_base` and which won't have any memory as it's the first message with that agent." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "ANSWER: Hi Sarah! It's great to meet you. As a prospective student, do you have any specific questions about Notre Dame University or anything in particular you're interested in learning about? \n", + "\n" + ] + } + ], + "source": [ + "result1 = agent_executor.invoke(\"Hi, my name is Sarah and I'm a prospective student.\")\n", + "\n", + "\n", + "print('\\nANSWER:', result1['output'], '\\n')" ] }, { - "attachments": {}, "cell_type": "markdown", - "metadata": { - "id": "ZZapCP4Pv2kz" - }, + "metadata": {}, "source": [ - "To make queries we simply call the `agent` directly." + "Let's see what was used in formulating the response." ] }, { "cell_type": "code", - "execution_count": 17, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "RJoAhy76vzAB", - "outputId": "31ae7589-e66a-4835-d1d8-555bb59c962c" - }, + "execution_count": 20, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n", - "\n", - "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3m{\n", - " \"action\": \"Knowledge Base\",\n", - " \"action_input\": \"When was the College of Engineering in the University of Notre Dame established?\"\n", - "}\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3mThe College of Engineering at the University of Notre Dame was established in 1920.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m{\n", - " \"action\": \"Final Answer\",\n", - " \"action_input\": \"The College of Engineering at the University of Notre Dame was established in 1920.\"\n", - "}\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" + "Tools used: []\n", + "Chat History Used: []\n", + "Chat History Final: [HumanMessage(content=\"Hi, my name is Sarah and I'm a prospective student.\", additional_kwargs={}, response_metadata={}), AIMessage(content=\"Hi Sarah! It's great to meet you. As a prospective student, do you have any specific questions about Notre Dame University or anything in particular you're interested in learning about?\", additional_kwargs={}, response_metadata={})]\n" ] - }, - { - "data": { - "text/plain": [ - "{'input': 'when was the college of engineering in the University of Notre Dame established?',\n", - " 'chat_history': [],\n", - " 'output': 'The College of Engineering at the University of Notre Dame was established in 1920.'}" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ - "agent(query)" + "print('Tools used:', result1['tools_used'])\n", + "print('Chat History Used:', result1['chat_history_used'])\n", + "print('Chat History Final:', result1['chat_history_final'])" ] }, { - "attachments": {}, "cell_type": "markdown", - "metadata": { - "id": "YcMqa9Va2hU6" - }, + "metadata": {}, + "source": [ + "As we can see, there is no tool usage and no chat_history that was used in formulating the response." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, "source": [ - "Looks great, now what if we ask it a non-general knowledge question?" + "#### 2. Knowledge Base Specific Query\n", + "\n", + "Now let's ask it something that should trigger the `knowledge_base`." ] }, { "cell_type": "code", - "execution_count": 18, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "85vipqC02deV", - "outputId": "345c724e-eaea-4a20-9445-99794bc743fe" - }, + "execution_count": 21, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "Step 1: Used knowledge_base({'query': 'programs offered at Notre Dame University'})\n", + "\n", + "Tool result: Based on the knowledge base: Besides its prominence in sports, Notre Dame is also a large, four-year, highly residential research University, and is consistently ranked among the top twenty universities in the United States and as a major global university. The undergraduate component of the university is organized into four colleges (Arts and Letters, Science, Engineering, Business) and the Architecture School. The latter is known for teaching New Classical Architecture and for awarding the globally renowned annual Driehaus Architecture Prize. Notre Dame's graduate program has more than 50 master's, doctoral and professional degree programs offered by the five schools, with the addition of the Notre Dame Law School and a MD-PhD program offered in combination with IU medical School. It maintains a system of libraries, cultural venues, artistic and scientific museums, including Hesburgh Library and the Snite Museum of Art. Over 80% of the university's 8,000 undergraduates live on campus in one of 29 single-sex residence halls, each with its own traditions, legacies, events and intramural sports teams. The university counts approximately 120,000 alumni, considered among the strongest alumni networks among U.S. colleges.\n", + "Notre Dame is known for its competitive admissions, with the incoming class enrolling in fall 2015 admitting 3,577 from a pool of 18,156 (19.7%). The academic profile of the enrolled class continues to rate among the top 10 to 15 in the nation for national research universities. The university practices a non-restrictive early action policy that allows admitted students to consider admission to Notre Dame as well as any other colleges to which they were accepted. 1,400 of the 3,577 (39.1%) were admitted under the early action plan. Admitted students came from 1,311 high schools and the average student traveled more than 750 miles to Notre Dame, making it arguably the most representative university in the United States. While all entering students begin in the College of the First Year of Studies, 25% have indicated they plan to study in the liberal arts or social sciences, 24% in engineering, 24% in business, 24% in science, and 3% in architecture.\n", + "The University of Notre Dame has made being a sustainability leader an integral part of its mission, creating the Office of Sustainability in 2008 to achieve a number of goals in the areas of power generation, design and construction, waste reduction, procurement, food services, transportation, and water.As of 2012[update] four building construction projects were pursuing LEED-Certified status and three were pursuing LEED Silver. Notre Dame's dining services sources 40% of its food locally and offers sustainably caught seafood as well as many organic, fair-trade, and vegan options. On the Sustainable Endowments Institute's College Sustainability Report Card 2010, University of Notre Dame received a \"B\" grade. The university also houses the Kroc Institute for International Peace Studies. Father Gustavo Gutierrez, the founder of Liberation Theology is a current faculty member.\n", + "As of 2012[update] research continued in many fields. The university president, John Jenkins, described his hope that Notre Dame would become \"one of the pre–eminent research institutions in the world\" in his inaugural address. The university has many multi-disciplinary institutes devoted to research in varying fields, including the Medieval Institute, the Kellogg Institute for International Studies, the Kroc Institute for International Peace studies, and the Center for Social Concerns. Recent research includes work on family conflict and child development, genome mapping, the increasing trade deficit of the United States with China, studies in fluid mechanics, computational science and engineering, and marketing trends on the Internet. As of 2013, the university is home to the Notre Dame Global Adaptation Index which ranks countries annually based on how vulnerable they are to climate change and how prepared they are to adapt.\n", + "In 2015-2016, Notre Dame ranked 18th overall among \"national universities\" in the United States in U.S. News & World Report's Best Colleges 2016. In 2014, USA Today ranked Notre Dame 10th overall for American universities based on data from College Factual. Forbes.com's America's Best Colleges ranks Notre Dame 13th among colleges in the United States in 2015, 8th among Research Universities, and 1st in the Midwest. U.S. News & World Report also lists Notre Dame Law School as 22nd overall. BusinessWeek ranks Mendoza College of Business undergraduate school as 1st overall. It ranks the MBA program as 20th overall. The Philosophical Gourmet Report ranks Notre Dame's graduate philosophy program as 15th nationally, while ARCHITECT Magazine ranked the undergraduate architecture program as 12th nationally. Additionally, the study abroad program ranks sixth in highest participation percentage in the nation, with 57.6% of students choosing to study abroad in 17 countries. According to payscale.com, undergraduate alumni of University of Notre Dame have a mid-career median salary $110,000, making it the 24th highest among colleges and universities in the United States. The median starting salary of $55,300 ranked 58th in the same peer group.\n", + "\n", "\n", + "ANSWER: Notre Dame University offers a wide range of programs across various fields of study. The undergraduate component is organized into four main colleges:\n", "\n", - "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3m{\n", - " \"action\": \"Final Answer\",\n", - " \"action_input\": \"The product of 2 multiplied by 7 is 14.\"\n", - "}\u001b[0m\n", + "1. **College of Arts and Letters** - This college offers programs in the humanities, social sciences, and fine arts.\n", + "2. **College of Science** - Focused on the natural sciences, this college provides programs in disciplines such as biology, chemistry, and physics.\n", + "3. **College of Engineering** - This college offers engineering programs in various specializations, preparing students for careers in technology and innovation.\n", + "4. **Mendoza College of Business** - Known for its strong business programs, this college offers undergraduate and graduate degrees in business administration and related fields.\n", + "5. **School of Architecture** - This school is recognized for its focus on New Classical Architecture and offers a unique architecture program.\n", "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" + "In addition to undergraduate programs, Notre Dame has a robust graduate program with over 50 master's, doctoral, and professional degree programs offered by its five schools, including the Notre Dame Law School and a combined MD-PhD program with the Indiana University School of Medicine.\n", + "\n", + "If you have a specific area of interest or a particular program in mind, feel free to ask for more detailed information! \n", + "\n" ] - }, + } + ], + "source": [ + "result2 = agent_executor.invoke(\"What programs does Notre Dame offer?\")\n", + "print('\\nANSWER:', result2['output'], '\\n')" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ { - "data": { - "text/plain": [ - "{'input': 'what is 2 * 7?',\n", - " 'chat_history': [HumanMessage(content='when was the college of engineering in the University of Notre Dame established?'),\n", - " AIMessage(content='The College of Engineering at the University of Notre Dame was established in 1920.')],\n", - " 'output': 'The product of 2 multiplied by 7 is 14.'}" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "Tools used: [{'tool_name': 'knowledge_base', 'tool_args': {'query': 'programs offered at Notre Dame University'}, 'step': 1}]\n", + "Chat History Used: [HumanMessage(content=\"Hi, my name is Sarah and I'm a prospective student.\", additional_kwargs={}, response_metadata={}), AIMessage(content=\"Hi Sarah! It's great to meet you. As a prospective student, do you have any specific questions about Notre Dame University or anything in particular you're interested in learning about?\", additional_kwargs={}, response_metadata={})]\n", + "Chat History Final: [HumanMessage(content=\"Hi, my name is Sarah and I'm a prospective student.\", additional_kwargs={}, response_metadata={}), AIMessage(content=\"Hi Sarah! It's great to meet you. As a prospective student, do you have any specific questions about Notre Dame University or anything in particular you're interested in learning about?\", additional_kwargs={}, response_metadata={}), HumanMessage(content='What programs does Notre Dame offer?', additional_kwargs={}, response_metadata={}), AIMessage(content=\"Notre Dame University offers a wide range of programs across various fields of study. The undergraduate component is organized into four main colleges:\\n\\n1. **College of Arts and Letters** - This college offers programs in the humanities, social sciences, and fine arts.\\n2. **College of Science** - Focused on the natural sciences, this college provides programs in disciplines such as biology, chemistry, and physics.\\n3. **College of Engineering** - This college offers engineering programs in various specializations, preparing students for careers in technology and innovation.\\n4. **Mendoza College of Business** - Known for its strong business programs, this college offers undergraduate and graduate degrees in business administration and related fields.\\n5. **School of Architecture** - This school is recognized for its focus on New Classical Architecture and offers a unique architecture program.\\n\\nIn addition to undergraduate programs, Notre Dame has a robust graduate program with over 50 master's, doctoral, and professional degree programs offered by its five schools, including the Notre Dame Law School and a combined MD-PhD program with the Indiana University School of Medicine.\\n\\nIf you have a specific area of interest or a particular program in mind, feel free to ask for more detailed information!\", additional_kwargs={}, response_metadata={})]\n" + ] } ], "source": [ - "agent(\"what is 2 * 7?\")" + "print('Tools used:', result2['tools_used'])\n", + "print('Chat History Used:', result2['chat_history_used'])\n", + "print('Chat History Final:', result2['chat_history_final'])" ] }, { - "attachments": {}, "cell_type": "markdown", - "metadata": { - "id": "gR_b0IN32rQ9" - }, + "metadata": {}, "source": [ - "Perfect, the agent is able to recognize that it doesn't need to refer to it's general knowledge tool for that question. Let's try some more questions." + "This is exactly what we needed, the previous interaction was used as part of the Chat History that provided the agent with context when formulating a response, and the `knowledge_base` tool was used in formulating a response. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3. Testing Memory\n", + "\n", + "Let's also double check that the memory is actually used by the agent." ] }, { "cell_type": "code", - "execution_count": 19, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "mQeicHTj2pmY", - "outputId": "9810647d-0846-4ca8-ae2e-1b249ca4ad3d" - }, + "execution_count": 23, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", - "\n", - "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3m{\n", - " \"action\": \"Knowledge Base\",\n", - " \"action_input\": \"University of Notre Dame\"\n", - "}\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3mThe University of Notre Dame is a Catholic research university located in South Bend, Indiana, in the United States. It is known for its strong academic programs, including undergraduate colleges in Arts and Letters, Science, Engineering, Business, and the Architecture School. The university also has a graduate program with over 50 master's, doctoral, and professional degree programs. Notre Dame is recognized as one of the top universities in the United States and has a strong alumni network. It is also known for its iconic landmarks, such as the Golden Dome and the Basilica. The university is committed to research and has various institutes dedicated to different fields of study. Notre Dame is also home to the Notre Dame Global Adaptation Index, which ranks countries based on their vulnerability to climate change.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m{\n", - " \"action\": \"Final Answer\",\n", - " \"action_input\": \"The University of Notre Dame is a Catholic research university located in South Bend, Indiana. It offers strong academic programs in various fields, including Arts and Letters, Science, Engineering, Business, and Architecture. Notre Dame is known for its academic excellence, iconic landmarks like the Golden Dome and the Basilica, and its commitment to research. It is also home to the Notre Dame Global Adaptation Index, which ranks countries based on their vulnerability to climate change.\"\n", - "}\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" + "ANSWER: In your previous messages, you introduced yourself as Sarah, a prospective student, and then you asked about the programs offered at Notre Dame University. If you have any more questions or need further information, feel free to ask! \n", + "\n" ] - }, + } + ], + "source": [ + "result3 = agent_executor.invoke(\"I sent you two messages previously, what were they?\")\n", + "print('\\nANSWER:', result3['output'], '\\n')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Excellent it works as expected!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4. Ensuring that the Agent is Actually Using the `knowledge_base` Tool for Retrieval and Context\n", + "\n", + "Let's ask the agent to quote the knowledge base, to ensure it's using it (rather than simply drawing upon the LLM's own knowledge of Notre Dame University)." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ { - "data": { - "text/plain": [ - "{'input': 'can you tell me some facts about the University of Notre Dame?',\n", - " 'chat_history': [HumanMessage(content='when was the college of engineering in the University of Notre Dame established?'),\n", - " AIMessage(content='The College of Engineering at the University of Notre Dame was established in 1920.'),\n", - " HumanMessage(content='what is 2 * 7?'),\n", - " AIMessage(content='The product of 2 multiplied by 7 is 14.')],\n", - " 'output': 'The University of Notre Dame is a Catholic research university located in South Bend, Indiana. It offers strong academic programs in various fields, including Arts and Letters, Science, Engineering, Business, and Architecture. Notre Dame is known for its academic excellence, iconic landmarks like the Golden Dome and the Basilica, and its commitment to research. It is also home to the Notre Dame Global Adaptation Index, which ranks countries based on their vulnerability to climate change.'}" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "Step 1: Used knowledge_base({'query': 'In 1919 Father James Burns became president of Notre Dame, and in three years he produced'})\n", + "\n", + "Tool result: Based on the knowledge base: In 1919 Father James Burns became president of Notre Dame, and in three years he produced an academic revolution that brought the school up to national standards by adopting the elective system and moving away from the university's traditional scholastic and classical emphasis. By contrast, the Jesuit colleges, bastions of academic conservatism, were reluctant to move to a system of electives. Their graduates were shut out of Harvard Law School for that reason. Notre Dame continued to grow over the years, adding more colleges, programs, and sports teams. By 1921, with the addition of the College of Commerce, Notre Dame had grown from a small college to a university with five colleges and a professional law school. The university continued to expand and add new residence halls and buildings with each subsequent president.\n", + "Since 2005, Notre Dame has been led by John I. Jenkins, C.S.C., the 17th president of the university. Jenkins took over the position from Malloy on July 1, 2005. In his inaugural address, Jenkins described his goals of making the university a leader in research that recognizes ethics and building the connection between faith and studies. During his tenure, Notre Dame has increased its endowment, enlarged its student body, and undergone many construction projects on campus, including Compton Family Ice Arena, a new architecture hall, additional residence halls, and the Campus Crossroads, a $400m enhancement and expansion of Notre Dame Stadium.\n", + "In the 18 years under the presidency of Edward Malloy, C.S.C., (1987–2005), there was a rapid growth in the school's reputation, faculty, and resources. He increased the faculty by more than 500 professors; the academic quality of the student body has improved dramatically, with the average SAT score rising from 1240 to 1360; the number of minority students more than doubled; the endowment grew from $350 million to more than $3 billion; the annual operating budget rose from $177 million to more than $650 million; and annual research funding improved from $15 million to more than $70 million. Notre Dame's most recent[when?] capital campaign raised $1.1 billion, far exceeding its goal of $767 million, and is the largest in the history of Catholic higher education.\n", + "The Rev. John J. Cavanaugh, C.S.C. served as president from 1946 to 1952. Cavanaugh's legacy at Notre Dame in the post-war years was devoted to raising academic standards and reshaping the university administration to suit it to an enlarged educational mission and an expanded student body and stressing advanced studies and research at a time when Notre Dame quadrupled in student census, undergraduate enrollment increased by more than half, and graduate student enrollment grew fivefold. Cavanaugh also established the Lobund Institute for Animal Studies and Notre Dame's Medieval Institute. Cavanaugh also presided over the construction of the Nieuwland Science Hall, Fisher Hall, and the Morris Inn, as well as the Hall of Liberal Arts (now O'Shaughnessy Hall), made possible by a donation from I.A. O'Shaughnessy, at the time the largest ever made to an American Catholic university. Cavanaugh also established a system of advisory councils at the university, which continue today and are vital to the university's governance and development\n", + "Hesburgh is also credited with transforming the face of Notre Dame by making it a coeducational institution. In the mid-1960s Notre Dame and Saint Mary's College developed a co-exchange program whereby several hundred students took classes not offered at their home institution, an arrangement that added undergraduate women to a campus that already had a few women in the graduate schools. After extensive debate, merging with St. Mary's was rejected, primarily because of the differential in faculty qualifications and pay scales. \"In American college education,\" explained the Rev. Charles E. Sheedy, C.S.C., Notre Dame's Dean of Arts and Letters, \"certain features formerly considered advantageous and enviable are now seen as anachronistic and out of place.... In this environment of diversity, the integration of the sexes is a normal and expected aspect, replacing separatism.\" Thomas Blantz, C.S.C., Notre Dame's Vice President of Student Affairs, added that coeducation \"opened up a whole other pool of very bright students.\" Two of the male residence halls were converted for the newly admitted female students that first year, while two others were converted for the next school year. In 1971 Mary Ann Proctor became the first female undergraduate; she transferred from St. Mary's College. In 1972 the first woman to graduate was Angela Sienko, who earned a bachelor's degree in marketing.\n", + "\n" + ] } ], "source": [ - "agent(\"can you tell me some facts about the University of Notre Dame?\")" + "query = \"\"\"\n", + "There is a specific sentence in the knowledge_base tool that starts with: \n", + "'In 1919 Father James Burns became president of Notre Dame, and in three years he produced...' \n", + "Retrieve the full sentence from the knowledge_base tool, then quote the full sentence back to me.\"\n", + "\"\"\"\n", + "\n", + "result4 = agent_executor.invoke(query)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Remember the quote we want is\n", + "\n", + "> In 1919 Father James Burns became president of Notre Dame, and in three years he produced an academic revolution that brought the school up to national standards by adopting the elective system and moving away from the university's traditional scholastic and classical emphasis." ] }, { "cell_type": "code", - "execution_count": 20, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "G93vLXso3B5Z", - "outputId": "cb345147-5630-4a5a-bb9f-242ad91d9968" - }, + "execution_count": 25, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", + "ANSWER: The full sentence you requested from the knowledge base is: \n", "\n", - "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", - "\u001b[32;1m\u001b[1;3m{\n", - " \"action\": \"Final Answer\",\n", - " \"action_input\": \"The University of Notre Dame is a Catholic research university located in South Bend, Indiana. It offers strong academic programs and is known for its iconic landmarks and commitment to research.\"\n", - "}\u001b[0m\n", + "\"In 1919 Father James Burns became president of Notre Dame, and in three years he produced an academic revolution that brought the school up to national standards by adopting the elective system and moving away from the university's traditional scholastic and classical emphasis.\" \n", "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" + "If you have any more questions or need further information, feel free to ask! \n", + "\n" ] - }, - { - "data": { - "text/plain": [ - "{'input': 'can you summarize these facts in two short sentences',\n", - " 'chat_history': [HumanMessage(content='when was the college of engineering in the University of Notre Dame established?'),\n", - " AIMessage(content='The College of Engineering at the University of Notre Dame was established in 1920.'),\n", - " HumanMessage(content='what is 2 * 7?'),\n", - " AIMessage(content='The product of 2 multiplied by 7 is 14.'),\n", - " HumanMessage(content='can you tell me some facts about the University of Notre Dame?'),\n", - " AIMessage(content='The University of Notre Dame is a Catholic research university located in South Bend, Indiana. It offers strong academic programs in various fields, including Arts and Letters, Science, Engineering, Business, and Architecture. Notre Dame is known for its academic excellence, iconic landmarks like the Golden Dome and the Basilica, and its commitment to research. It is also home to the Notre Dame Global Adaptation Index, which ranks countries based on their vulnerability to climate change.')],\n", - " 'output': 'The University of Notre Dame is a Catholic research university located in South Bend, Indiana. It offers strong academic programs and is known for its iconic landmarks and commitment to research.'}" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ - "agent(\"can you summarize these facts in two short sentences\")" + "print('\\nANSWER:', result4['output'], '\\n')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Amazing, this confirms that the agent is actually using the `knowledge_base` retrieval, rather than simply drawing upon it's own, trained knowledge." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Concluding Remarks" ] }, { @@ -1236,7 +1421,13 @@ "id": "PWivmw9F3bCw" }, "source": [ - "Looks great! We're also able to ask questions that refer to previous interactions in the conversation and the agent is able to refer to the conversation history to as a source of information.\n", + "We've successfully built an agent that:\n", + "- Will choose for itself whether the `knowledge_base` tool is relevant to the question.\n", + " - If it is deemed relevant, then the semantic similarity is used to extract text from the vector db - which should be relevant to the user's input utterance. This text is then used by the LLM as additional context when formulating a response.\n", + " - If it is not deemed relevant, then the `knowledge_base` tool is not used, and the LLM formulates a response as normal.\n", + "- In all cases, the chat history is used as additional context when generating a response. \n", + "\n", + "See notebook: `learn\\generation\\langchain\\handbook\\03-langchain-conversational-memory.ipynb` for other ways in which the memory could have been implemented.\n", "\n", "That's all for this example of building a retrieval augmented conversational agent with OpenAI and Pinecone (the OP stack) and LangChain.\n", "\n", @@ -1245,7 +1436,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 26, "metadata": { "id": "Pa1whr8V3Wfm" }, @@ -1270,7 +1461,8 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "pinecone1", + "language": "python", "name": "python3" }, "language_info": { @@ -1283,9 +1475,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}