Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix document delete #2757

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions api/apps/document_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down