Add chromadb purge method

This commit is contained in:
SillyLossy
2023-05-23 00:29:56 +03:00
parent 49f119bbe7
commit 0d69fb0406
2 changed files with 24 additions and 0 deletions

View File

@@ -695,6 +695,23 @@ def chromadb_add_messages():
return jsonify({"count": len(ids)})
@app.route("/api/chromadb/purge", methods=["POST"])
@require_module("chromadb")
def chromadb_purge():
data = request.get_json()
if "chat_id" not in data or not isinstance(data["chat_id"], str):
abort(400, '"chat_id" is required')
chat_id_md5 = hashlib.md5(data["chat_id"].encode()).hexdigest()
collection = chromadb_client.get_or_create_collection(
name=f"chat-{chat_id_md5}", embedding_function=chromadb_embed_fn
)
deleted = collection.delete()
print("ChromaDB embeddings deleted", len(deleted))
return 'Ok', 200
@app.route("/api/chromadb/query", methods=["POST"])
@require_module("chromadb")
def chromadb_query():