From b2a2cfcb406191efa81137514c5d5050c14b10e5 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 12 Apr 2024 09:55:30 -0700 Subject: [PATCH] fix: you can only delete something that might exist Signed-off-by: Matt Williams --- 2024-04-04-build-rag-with-python/import.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/2024-04-04-build-rag-with-python/import.py b/2024-04-04-build-rag-with-python/import.py index bf55051..3319bab 100644 --- a/2024-04-04-build-rag-with-python/import.py +++ b/2024-04-04-build-rag-with-python/import.py @@ -2,9 +2,13 @@ import ollama, chromadb, time from utilities import readtext, getconfig from mattsollamatools import chunker, chunk_text_by_sentences +collectionname="buildragwithpython" chroma = chromadb.HttpClient(host="localhost", port=8000) -chroma.delete_collection("buildragwithpython") +print(chroma.list_collections()) +if any(collection.name == collectionname for collection in chroma.list_collections()): + print('deleting collection') + chroma.delete_collection("buildragwithpython") collection = chroma.get_or_create_collection(name="buildragwithpython", metadata={"hnsw:space": "cosine"}) embedmodel = getconfig()["embedmodel"]