Skip to content

fix: empty delete bug #12339

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

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
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
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
Loading