From 6ace5f223da98166a8b46992935fcc26bcf2353f Mon Sep 17 00:00:00 2001 From: craigprobus Date: Sun, 13 Apr 2025 13:48:28 -0700 Subject: [PATCH] stopping point --- week8/day2.0.ipynb | 65 +++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/week8/day2.0.ipynb b/week8/day2.0.ipynb index d709c20..1e053ab 100644 --- a/week8/day2.0.ipynb +++ b/week8/day2.0.ipynb @@ -163,21 +163,15 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 22, "id": "00e4b225-18b4-45f6-9caa-84b54694ddeb", "metadata": {}, "outputs": [ { - "ename": "NotImplementedError", - "evalue": "In Chroma v0.6.0, list_collections only returns collection names. Use Client.get_collection(products) to access name. See https://docs.trychroma.com/deployment/migration for more information.", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNotImplementedError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[21], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Check if the collection exists and delete it if it does\u001b[39;00m\n\u001b[1;32m 2\u001b[0m collection_name \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mproducts\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 3\u001b[0m existing_collection_names \u001b[38;5;241m=\u001b[39m \u001b[43m[\u001b[49m\u001b[43mcollection\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mcollection\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlist_collections\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 4\u001b[0m x \u001b[38;5;241m=\u001b[39m client\u001b[38;5;241m.\u001b[39mget_collection(collection_name)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(x)\n", - "Cell \u001b[0;32mIn[21], line 3\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Check if the collection exists and delete it if it does\u001b[39;00m\n\u001b[1;32m 2\u001b[0m collection_name \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mproducts\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 3\u001b[0m existing_collection_names \u001b[38;5;241m=\u001b[39m [\u001b[43mcollection\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m collection \u001b[38;5;129;01min\u001b[39;00m client\u001b[38;5;241m.\u001b[39mlist_collections()]\n\u001b[1;32m 4\u001b[0m x \u001b[38;5;241m=\u001b[39m client\u001b[38;5;241m.\u001b[39mget_collection(collection_name)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(x)\n", - "File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/chromadb/api/models/Collection.py:418\u001b[0m, in \u001b[0;36mCollectionName.__getattr__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 411\u001b[0m collection_attributes_and_methods \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 412\u001b[0m member\n\u001b[1;32m 413\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m member, _ \u001b[38;5;129;01min\u001b[39;00m inspect\u001b[38;5;241m.\u001b[39mgetmembers(Collection)\n\u001b[1;32m 414\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m member\u001b[38;5;241m.\u001b[39mstartswith(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 415\u001b[0m ]\n\u001b[1;32m 417\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m collection_attributes_and_methods:\n\u001b[0;32m--> 418\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mNotImplementedError\u001b[39;00m(\n\u001b[1;32m 419\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIn Chroma v0.6.0, list_collections only returns collection names. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 420\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUse Client.get_collection(\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mstr\u001b[39m(\u001b[38;5;28mself\u001b[39m)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m) to access \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mitem\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 421\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSee https://docs.trychroma.com/deployment/migration for more information.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 422\u001b[0m )\n\u001b[1;32m 424\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mCollectionName\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m object has no attribute \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mitem\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", - "\u001b[0;31mNotImplementedError\u001b[0m: In Chroma v0.6.0, list_collections only returns collection names. Use Client.get_collection(products) to access name. See https://docs.trychroma.com/deployment/migration for more information." + "name": "stdout", + "output_type": "stream", + "text": [ + "['products']\n" ] } ], @@ -190,21 +184,15 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 23, "id": "5f95dafd-ab80-464e-ba8a-dec7a2424780", "metadata": {}, "outputs": [ { - "ename": "NotImplementedError", - "evalue": "In Chroma v0.6.0, list_collections only returns collection names. Use Client.get_collection(products) to access name. See https://docs.trychroma.com/deployment/migration for more information.", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNotImplementedError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[12], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Check if the collection exists and delete it if it does\u001b[39;00m\n\u001b[1;32m 2\u001b[0m collection_name \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mproducts\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 3\u001b[0m existing_collection_names \u001b[38;5;241m=\u001b[39m \u001b[43m[\u001b[49m\u001b[43mcollection\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mcollection\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlist_collections\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mexisting_collection_names <\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mexisting_collection_names\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m collection_name \u001b[38;5;129;01min\u001b[39;00m existing_collection_names:\n", - "Cell \u001b[0;32mIn[12], line 3\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Check if the collection exists and delete it if it does\u001b[39;00m\n\u001b[1;32m 2\u001b[0m collection_name \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mproducts\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 3\u001b[0m existing_collection_names \u001b[38;5;241m=\u001b[39m [\u001b[43mcollection\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m collection \u001b[38;5;129;01min\u001b[39;00m client\u001b[38;5;241m.\u001b[39mlist_collections()]\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mexisting_collection_names <\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mexisting_collection_names\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m collection_name \u001b[38;5;129;01min\u001b[39;00m existing_collection_names:\n", - "File \u001b[0;32m/opt/anaconda3/envs/llms/lib/python3.11/site-packages/chromadb/api/models/Collection.py:418\u001b[0m, in \u001b[0;36mCollectionName.__getattr__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 411\u001b[0m collection_attributes_and_methods \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 412\u001b[0m member\n\u001b[1;32m 413\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m member, _ \u001b[38;5;129;01min\u001b[39;00m inspect\u001b[38;5;241m.\u001b[39mgetmembers(Collection)\n\u001b[1;32m 414\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m member\u001b[38;5;241m.\u001b[39mstartswith(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 415\u001b[0m ]\n\u001b[1;32m 417\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m collection_attributes_and_methods:\n\u001b[0;32m--> 418\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mNotImplementedError\u001b[39;00m(\n\u001b[1;32m 419\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIn Chroma v0.6.0, list_collections only returns collection names. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 420\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUse Client.get_collection(\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mstr\u001b[39m(\u001b[38;5;28mself\u001b[39m)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m) to access \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mitem\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 421\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSee https://docs.trychroma.com/deployment/migration for more information.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 422\u001b[0m )\n\u001b[1;32m 424\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mCollectionName\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m object has no attribute \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mitem\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", - "\u001b[0;31mNotImplementedError\u001b[0m: In Chroma v0.6.0, list_collections only returns collection names. Use Client.get_collection(products) to access name. See https://docs.trychroma.com/deployment/migration for more information." + "name": "stdout", + "output_type": "stream", + "text": [ + "Deleted existing collection: products\n" ] } ], @@ -237,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "a87db200-d19d-44bf-acbd-15c45c70f5c9", "metadata": {}, "outputs": [], @@ -247,14 +235,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "9b23a025-4c35-4d3a-96ad-b956cad37b0a", "metadata": {}, "outputs": [], "source": [ "# Pass in a list of texts, get back a numpy array of vectors\n", "\n", - "vector = model.encode([\"Well hi there\"])[0]" + "vector = model.encode([\"You can be right, or you can be in a relationship\"])[0]" ] }, { @@ -264,12 +252,12 @@ "metadata": {}, "outputs": [], "source": [ - "vector" + "len(vector)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "id": "38de1bf8-c9b5-45b4-9f4b-86af93b3f80d", "metadata": {}, "outputs": [], @@ -281,10 +269,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "id": "8c1205bd-4692-44ef-8ea4-69f255354537", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Delphi FG0166 Fuel Pump Module\\nDelphi brings 80 years of OE Heritage into each Delphi pump, ensuring quality and fitment for each Delphi part. Part is validated, tested and matched to the right vehicle application Delphi brings 80 years of OE Heritage into each Delphi assembly, ensuring quality and fitment for each Delphi part Always be sure to check and clean fuel tank to avoid unnecessary returns Rigorous OE-testing ensures the pump can withstand extreme temperatures Brand Delphi, Fit Type Vehicle Specific Fit, Dimensions LxWxH 19.7 x 7.7 x 5.1 inches, Weight 2.2 Pounds, Auto Part Position Unknown, Operation Mode Mechanical, Manufacturer Delphi, Model FUEL PUMP, Dimensions 19.7'" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "description(train[0])" ] @@ -308,6 +307,14 @@ " metadatas=metadatas\n", " )" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd055d5c-091b-43f8-89f3-3ffb74c62cf6", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {