Skip to content

Commit

Permalink
delete document record in case of unique constraint failing
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyongchao committed Dec 17, 2024
1 parent 075c658 commit 7bdeed6
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lazyllm/tools/rag/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from lazyllm.common.queue import sqlite3_check_threadsafety
import sqlalchemy
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy import Column, insert, update, select
from sqlalchemy import Column, insert, update, select, delete

import pydantic
import sqlite3
Expand All @@ -23,7 +23,6 @@

import lazyllm
from lazyllm import config
import uuid

# min(32, (os.cpu_count() or 1) + 4) is the default number of workers for ThreadPoolExecutor
config.add(
Expand Down Expand Up @@ -436,12 +435,11 @@ def update_file_status(self, file_ids: List[str], status: str, batch_size: int =
updated_files = []
with self._db_lock, self._engine.connect() as conn:
for i in range(0, len(file_ids), batch_size):
ids = file_ids[i : i + batch_size]
ids = file_ids[i: i + batch_size]
if status == "deleted":
stmt = (
update(KBDocument)
delete(KBDocument)
.where(KBDocument.doc_id.in_(ids))
.values(status=status, doc_id="deleted_doc")
.returning(KBDocument.doc_id, KBDocument.path)
)
else:
Expand Down

0 comments on commit 7bdeed6

Please sign in to comment.