From 1ab171cf2ee001c8acfdba41fe507fc4ae941a5e Mon Sep 17 00:00:00 2001 From: Paco Aranda Date: Wed, 19 Jun 2024 11:03:33 +0200 Subject: [PATCH] [ENHANCEMENT] docs: Add howto update record vectors (#5052) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR adds how to update record vectors in how-to guides. Since the fields cannot be updated, the how-to guides skip them for now. **How Has This Been Tested** (Please describe the tests that you ran to verify your changes.) - [ ] `sphinx-autobuild` (read [Developer Documentation](https://docs.argilla.io/en/latest/community/developer_docs.html#building-the-documentation) for more details) **Checklist** - [ ] I added relevant documentation - [ ] I followed the style guidelines of this project - [ ] I did a self-review of my code - [ ] I made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK) (see text above) - [ ] I have added relevant notes to the `CHANGELOG.md` file (See https://keepachangelog.com/) --- argilla/docs/how_to_guides/record.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/argilla/docs/how_to_guides/record.md b/argilla/docs/how_to_guides/record.md index b5077a7048..bd7bcf794c 100644 --- a/argilla/docs/how_to_guides/record.md +++ b/argilla/docs/how_to_guides/record.md @@ -436,7 +436,7 @@ updated_data = [ dataset.records.log(records=updated_data) ``` -!!! note "Update the metadata" +=== "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. ```python @@ -452,6 +452,22 @@ dataset.records.log(records=updated_data) dataset.records.log(records=updated_records) ``` +=== "Update vectors" + When a new vector field is added to the dataset settings, or some value for the existing record vectors must updated, you can iterate over the records and update the vectors in the same way as the metadata. + + ```python + updated_records = [] + + for record in dataset.records(): + + record.vectors["new_vector"] = [...] + record.vector["v"] = [...] + + updated_records.append(record) + + dataset.records.log(records=updated_records) + ``` + ## Delete records You can delete records in a dataset calling the `delete` method on the `Dataset` object. To delete records, you need to retrieve them from the server and get a list with those that you want to delete.