From a0efd90c14ab0a3f650c446da3df5de64f8f862c Mon Sep 17 00:00:00 2001 From: charlene tau express Date: Wed, 16 Apr 2025 12:18:01 +0800 Subject: [PATCH] delete_points endpoint --- src/app.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/app.py b/src/app.py index 546b005..2aac37a 100644 --- a/src/app.py +++ b/src/app.py @@ -140,6 +140,47 @@ def add(): +@app.post("/delete_points") +def delete_points(): + if request.content_type == 'application/json': + try: + data = request.get_json(force=True) + if data is None: + raise BadRequest + except BadRequest: + return jsonify({"error": "Invalid JSON"}), 400 + else: + + data = request.form.to_dict() + + doc_uuid=data.get("doc_uuid") + if not doc_uuid: + return jsonify({"error": "Missing 'doc_uuid' in request"}), 400 + filter_condition = models.Filter( + must=[ + models.FieldCondition( + key="doc_id", + match=models.MatchValue(value=doc_uuid) + ) + ] + ) + + try: + result = Qdrant.get_client().delete( + + points_selector=models.FilterSelector( + filter=filter_condition + ), + wait=True + ) + if result and result.status == "completed": + return jsonify({"message": f"Deleted all points with doc_id = {doc_uuid}"}), 200 + else: + return jsonify({"warning": "Deletion request did not complete successfully"}), 500 + + except Exception as e: + return jsonify({"error": str(e)}), 500 + @app.post("/delete") def delete():