From 90806538338602f6392cdce66627da3949198d6a Mon Sep 17 00:00:00 2001 From: sdiazlor Date: Fri, 7 Jun 2024 17:29:21 +0200 Subject: [PATCH] docs: add delete method --- .../docs/guides/how_to_guides/record.md | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/argilla-sdk/docs/guides/how_to_guides/record.md b/argilla-sdk/docs/guides/how_to_guides/record.md index f6fe826867..1f9f0d6c26 100644 --- a/argilla-sdk/docs/guides/how_to_guides/record.md +++ b/argilla-sdk/docs/guides/how_to_guides/record.md @@ -396,8 +396,6 @@ If your dataset includes some annotations, you can add those to the records as y dataset.records.log(data, user_id=user.id) ``` - - ## List records To list records in a dataset, you can use the `records` method on the `Dataset` object. This method returns a list of `Record` objects that can be iterated over to access the record properties. @@ -422,7 +420,7 @@ for record in dataset.records( ## Update records -You can update records in a dataset calling the `update` method on the `Dataset` object. To update a record, you need to provide the record `id` and the new data to be updated. +You can update records in a dataset calling the `log` method on the `Dataset` object. To update a record, you need to provide the record `id` and the new data to be updated. ```python data = dataset.records.to_list(flatten=True) @@ -436,8 +434,8 @@ updated_data = [ for sample in data ] dataset.records.log(records=updated_data) - ``` + !!! note "Update the metadata" The `metadata` of `Record` object is a python dictionary. So to update the metadata of a record, you can iterate over the records and update the metadata by key or using `metadata.update`. After that, you should update the records in the dataset. @@ -452,4 +450,32 @@ dataset.records.log(records=updated_data) updated_records.append(record) dataset.records.log(records=updated_records) - ``` \ No newline at end of file + ``` + +## Delete records + +You can delete records in a dataset calling the `delete` method on the `Dataset` object. To delete a record, you need to retrieve them from the server and get a list with those that you want to delete. + +```python +# Delete a single record +record_to_delete = [list(dataset.records)[0]] +dataset.records.delete(records=record_to_delete) + +# Delete multiple records +records_to_delete = list(dataset.records)[:5] +dataset.records.delete(records=records_to_delete) +``` + +!!! tip "Delete records based on a query" + It can be very useful to avoid eliminating records with answers. + + > For more information about the query syntax, check this [how-to guide](query_export.md). + + ```python + status_filter = rg.Query( + filter = rg.Filter(("status", "==", "pending")) + ) + records_to_delete = list(dataset.records(status_filter)) + + dataset.records.delete(records_to_delete) + ```