From fb6982e08cfd03c31c911d8d27b37db75f6271df Mon Sep 17 00:00:00 2001 From: lidp <43509927+guoyuhao2330@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:40:57 +0800 Subject: [PATCH] Update document_app.py --- api/apps/document_app.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/api/apps/document_app.py b/api/apps/document_app.py index 0f69dc5ee..f7306a221 100644 --- a/api/apps/document_app.py +++ b/api/apps/document_app.py @@ -46,7 +46,7 @@ from api.utils import get_uuid from api.db import FileType, TaskStatus, ParserType, FileSource, LLMType from api.db.services.document_service import DocumentService, doc_upload_and_parse -from api.settings import RetCode, stat_logger +from api.settings import RetCode, stat_logger, retrievaler from api.utils.api_utils import get_json_result from rag.utils.storage_factory import STORAGE_IMPL from api.utils.file_utils import filename_type, thumbnail, get_project_base_directory @@ -223,7 +223,7 @@ def docinfos(): @manager.route('/thumbnails', methods=['GET']) -#@login_required +# @login_required def thumbnails(): doc_ids = request.args.get("doc_ids").split(",") if not doc_ids: @@ -299,6 +299,15 @@ def rm(): if not tenant_id: return get_data_error_result(retmsg="Tenant not found!") + query = {"doc_ids": [doc_id], "question": "", "sort": True} + sres = retrievaler.search(query, search.index_name(tenant_id), highlight=True) + chunk_ids = [id for id in sres.ids] + + if not ELASTICSEARCH.deleteByQuery( + Q("ids", values=chunk_ids), search.index_name(tenant_id)): + return get_data_error_result(retmsg="Index updating failure") + DocumentService.decrement_chunk_num(doc.id, doc.kb_id, 1, len(chunk_ids), 0) + b, n = File2DocumentService.get_storage_address(doc_id=doc_id) if not DocumentService.remove_document(doc, tenant_id):