Browse Source

When disabling the "Annotation Reply" button, the backend reports an error. #2904 (#2933)

Co-authored-by: colvin <colvin.zhang@boaocloud.com>
colvin777 1 year ago
parent
commit
c60749678b
1 changed files with 5 additions and 4 deletions
  1. 5 4
      api/tasks/annotation/disable_annotation_reply_task.py

+ 5 - 4
api/tasks/annotation/disable_annotation_reply_task.py

@@ -9,7 +9,7 @@ from core.rag.datasource.vdb.vector_factory import Vector
 from extensions.ext_database import db
 from extensions.ext_redis import redis_client
 from models.dataset import Dataset
-from models.model import App, AppAnnotationSetting
+from models.model import App, AppAnnotationSetting, MessageAnnotation
 
 
 @shared_task(queue='dataset')
@@ -25,7 +25,7 @@ def disable_annotation_reply_task(job_id: str, app_id: str, tenant_id: str):
         App.tenant_id == tenant_id,
         App.status == 'normal'
     ).first()
-
+    annotations_count = db.session.query(MessageAnnotation).filter(MessageAnnotation.app_id == app_id).count()
     if not app:
         raise NotFound("App not found")
 
@@ -49,8 +49,9 @@ def disable_annotation_reply_task(job_id: str, app_id: str, tenant_id: str):
         )
 
         try:
-            vector = Vector(dataset, attributes=['doc_id', 'annotation_id', 'app_id'])
-            vector.delete_by_metadata_field('app_id', app_id)
+            if annotations_count > 0:
+                vector = Vector(dataset, attributes=['doc_id', 'annotation_id', 'app_id'])
+                vector.delete_by_metadata_field('app_id', app_id)
         except Exception:
             logging.exception("Delete annotation index failed when annotation deleted.")
         redis_client.setex(disable_app_annotation_job_key, 600, 'completed')