From a9f3771aa07aa66d6f9628e362bd3212dd5e9b41 Mon Sep 17 00:00:00 2001 From: Josh Wedekind Date: Thu, 19 Sep 2024 13:49:47 -0700 Subject: [PATCH] Patch: Handle collection exists --- 0-setup/setup.ipynb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/0-setup/setup.ipynb b/0-setup/setup.ipynb index 61ae4c3..c90b8ce 100644 --- a/0-setup/setup.ipynb +++ b/0-setup/setup.ipynb @@ -6,7 +6,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install weaviate-client==4.6.1 --force-reinstall -U -q" + "!pip install weaviate-client==4.6.1" ] }, { @@ -54,16 +54,19 @@ " grpc_secure=False\n", ")\n", "\n", - "collection = client.collections.create(\n", - " name=\"TestCollection\",\n", - " properties=[\n", - " wvc.config.Property(\n", - " name=\"title\",\n", - " data_type=wvc.config.DataType.TEXT\n", - " )\n", - " ]\n", - ")\n", - "print(\"Created collection.\")\n", + "collection = client.collections.get(name='TestCollection')\n", + "if collection is None:\n", + " collection = client.collections.create(\n", + " name=\"TestCollection\",\n", + " properties=[\n", + " wvc.config.Property(\n", + " name=\"title\",\n", + " data_type=wvc.config.DataType.TEXT\n", + " )\n", + " ]\n", + " )\n", + " print(\"Created collection.\")\n", + "\n", "collections = client.collections.list_all()\n", "print(collections)\n", "client.close()"