Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Feat: When Delete Chunk Will Also Delete Chunk Related Image (#7656)

Stephen Hud2b346cf9e5a
diff --git a/api/apps/chunk_app.py b/api/apps/chunk_app.py
index b9442ba86a..69b03b9ae6 100644
--- a/api/apps/chunk_app.py
+++ b/api/apps/chunk_app.py
@@ -37,6 +37,7 @@ import xxhash
import re
+
@manager.route('/list', methods=['POST']) # noqa: F821
@login_required
@validate_request("doc_id")
@@ -194,6 +195,7 @@ def switch():
@login_required
@validate_request("chunk_ids", "doc_id")
def rm():
+ from rag.utils.storage_factory import STORAGE_IMPL
req = request.json
try:
e, doc = DocumentService.get_by_id(req["doc_id"])
@@ -204,6 +206,9 @@ def rm():
deleted_chunk_ids = req["chunk_ids"]
chunk_number = len(deleted_chunk_ids)
DocumentService.decrement_chunk_num(doc.id, doc.kb_id, 1, chunk_number, 0)
+ for cid in deleted_chunk_ids:
+ if STORAGE_IMPL.obj_exist(doc.kb_id, cid):
+ STORAGE_IMPL.rm(doc.kb_id, cid)
return get_json_result(data=True)
except Exception as e:
return server_error_response(e)