Browse Source

If all vector store files associated with a page are deleted, the vector store relation is also deleted.

Shun Miyazawa 1 year ago
parent
commit
c242ec0e59
1 changed files with 6 additions and 0 deletions
  1. 6 0
      apps/app/src/server/service/openai/openai.ts

+ 6 - 0
apps/app/src/server/service/openai/openai.ts

@@ -104,6 +104,12 @@ class OpenaiService implements IOpenaiService {
       }
       }
 
 
       const undeletedFileIds = vectorStoreFileRelation.fileIds.filter(fileId => !deletedFileIds.includes(fileId));
       const undeletedFileIds = vectorStoreFileRelation.fileIds.filter(fileId => !deletedFileIds.includes(fileId));
+
+      if (undeletedFileIds.length === 0) {
+        await vectorStoreFileRelation.remove();
+        return;
+      }
+
       vectorStoreFileRelation.fileIds = undeletedFileIds;
       vectorStoreFileRelation.fileIds = undeletedFileIds;
       await vectorStoreFileRelation.save();
       await vectorStoreFileRelation.save();
     }
     }