Skip to content

Commit

Permalink
fix: empty delete bug (#12339)
Browse files Browse the repository at this point in the history
Co-authored-by: huangzhuo <[email protected]>
  • Loading branch information
huangzhuo1949 and huangzhuo authored Jan 3, 2025
1 parent 6df17a3 commit 7069802
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/core/rag/datasource/vdb/baidu/baidu_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def text_exists(self, id: str) -> bool:
return False

def delete_by_ids(self, ids: list[str]) -> None:
if not ids:
return
quoted_ids = [f"'{id}'" for id in ids]
self._db.table(self._collection_name).delete(filter=f"id IN({', '.join(quoted_ids)})")

Expand Down
2 changes: 2 additions & 0 deletions api/core/rag/datasource/vdb/chroma/chroma_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def delete(self):
self._client.delete_collection(self._collection_name)

def delete_by_ids(self, ids: list[str]) -> None:
if not ids:
return
collection = self._client.get_or_create_collection(self._collection_name)
collection.delete(ids=ids)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def text_exists(self, id: str) -> bool:
return bool(self._client.exists(index=self._collection_name, id=id))

def delete_by_ids(self, ids: list[str]) -> None:
if not ids:
return
for id in ids:
self._client.delete(index=self._collection_name, id=id)

Expand Down
2 changes: 2 additions & 0 deletions api/core/rag/datasource/vdb/myscale/myscale_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def text_exists(self, id: str) -> bool:
return results.row_count > 0

def delete_by_ids(self, ids: list[str]) -> None:
if not ids:
return
self._client.command(
f"DELETE FROM {self._config.database}.{self._collection_name} WHERE id IN {str(tuple(ids))}"
)
Expand Down
2 changes: 2 additions & 0 deletions api/core/rag/datasource/vdb/oceanbase/oceanbase_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def text_exists(self, id: str) -> bool:
return bool(cur.rowcount != 0)

def delete_by_ids(self, ids: list[str]) -> None:
if not ids:
return
self._client.delete(table_name=self._collection_name, ids=ids)

def get_ids_by_metadata_field(self, key: str, value: str) -> list[str]:
Expand Down
2 changes: 2 additions & 0 deletions api/core/rag/datasource/vdb/oracle/oraclevector.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def get_by_ids(self, ids: list[str]) -> list[Document]:
return docs

def delete_by_ids(self, ids: list[str]) -> None:
if not ids:
return
with self._get_cursor() as cur:
cur.execute(f"DELETE FROM {self.table_name} WHERE id IN %s" % (tuple(ids),))

Expand Down
5 changes: 5 additions & 0 deletions api/core/rag/datasource/vdb/pgvector/pgvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ def get_by_ids(self, ids: list[str]) -> list[Document]:
return docs

def delete_by_ids(self, ids: list[str]) -> None:
# Avoiding crashes caused by performing delete operations on empty lists in certain scenarios
# Scenario 1: extract a document fails, resulting in a table not being created.
# Then clicking the retry button triggers a delete operation on an empty list.
if not ids:
return
with self._get_cursor() as cur:
cur.execute(f"DELETE FROM {self.table_name} WHERE id IN %s", (tuple(ids),))

Expand Down
2 changes: 2 additions & 0 deletions api/core/rag/datasource/vdb/tencent/tencent_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def text_exists(self, id: str) -> bool:
return False

def delete_by_ids(self, ids: list[str]) -> None:
if not ids:
return
self._db.collection(self._collection_name).delete(document_ids=ids)

def delete_by_metadata_field(self, key: str, value: str) -> None:
Expand Down

0 comments on commit 7069802

Please sign in to comment.