rg.Record
¶
The Record
object is used to represent a single record in Argilla. It contains fields, suggestions, responses, metadata, and vectors.
Usage Examples¶
Creating a Record¶
To create records, you can use the Record
class and pass it to the Dataset.records.log
method. The Record
class requires a fields
parameter, which is a dictionary of field names and values. The field names must match the field names in the dataset's Settings
object to be accepted.
dataset.records.log(
records=[
rg.Record(
fields={"text": "Hello World, how are you?"},
),
]
) # (1)
- The Argilla dataset contains a field named
text
matching the key here.
To create records with image fields, pass the image to the record object as either a remote url, local path to an image file, or a PIL object. The field names must be defined as an rg.ImageField
in the dataset's Settings
object to be accepted. Images will be stored in the Argilla database and returned as rescaled PIL objects.
dataset.records.log(
records=[
rg.Record(
fields={"image": "https://example.com/image.jpg"}, # (1)
),
]
)
- The image can be referenced as either a remote url, a local file path, or a PIL object.
Note
The image will be stored in the Argilla database and can impact the dataset's storage usage. Images should be less than 5mb in size and datasets should contain less than 10,000 images.
Accessing Record Attributes¶
The Record
object has suggestions, responses, metadata, and vectors attributes that can be accessed directly whilst iterating over records in a dataset.
for record in dataset.records(
with_suggestions=True,
with_responses=True,
with_metadata=True,
with_vectors=True
):
print(record.suggestions)
print(record.responses)
print(record.metadata)
print(record.vectors)
Record properties can also be updated whilst iterating over records in a dataset.
For changes to take effect, the user must call the update
method on the Dataset
object, or pass the updated records to Dataset.records.log
. All core record atttributes can be updated in this way. Check their respective documentation for more information: Suggestions, Responses, Metadata, Vectors.
Record
¶
Bases: Resource
The class for interacting with Argilla Records. A Record
is a single sample
in a dataset. Records receives feedback in the form of responses and suggestions.
Records contain fields, metadata, and vectors.
Attributes:
Name | Type | Description |
---|---|---|
id |
Union[str, UUID]
|
The id of the record. |
fields |
RecordFields
|
The fields of the record. |
metadata |
RecordMetadata
|
The metadata of the record. |
vectors |
RecordVectors
|
The vectors of the record. |
responses |
RecordResponses
|
The responses of the record. |
suggestions |
RecordSuggestions
|
The suggestions of the record. |
dataset |
Dataset
|
The dataset to which the record belongs. |
_server_id |
UUID
|
An id for the record generated by the Argilla server. |
Source code in src/argilla/records/_resource.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
__init__(id=None, fields=None, metadata=None, vectors=None, responses=None, suggestions=None, _server_id=None, _dataset=None)
¶
Initializes a Record with fields, metadata, vectors, responses, suggestions, external_id, and id. Records are typically defined as flat dictionary objects with fields, metadata, vectors, responses, and suggestions and passed to Dataset.DatasetRecords.add() as a list of dictionaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id |
Optional[Union[UUID, str]]
|
An id for the record. If not provided, a UUID will be generated. |
None
|
fields |
Optional[Dict[str, FieldValue]]
|
A dictionary of fields for the record. |
None
|
metadata |
Optional[Dict[str, Any]]
|
A dictionary of metadata for the record. |
None
|
vectors |
Optional[Dict[str, VectorValue]]
|
A dictionary of vectors for the record. |
None
|
responses |
Optional[List[Response]]
|
A list of Response objects for the record. |
None
|
suggestions |
Optional[List[Suggestion]]
|
A list of Suggestion objects for the record. |
None
|
_server_id |
Optional[UUID]
|
An id for the record. (Read-only and set by the server) |
None
|
_dataset |
Optional[Dataset]
|
The dataset object to which the record belongs. |
None
|
Source code in src/argilla/records/_resource.py
get()
¶
Retrieves the record from the server.
Source code in src/argilla/records/_resource.py
serialize()
¶
Serializes the Record to a dictionary for interaction with the API
Source code in src/argilla/records/_resource.py
to_dict()
¶
Converts a Record object to a dictionary for export. Returns: A dictionary representing the record where the keys are "fields", "metadata", "suggestions", and "responses". Each field and question is represented as a key-value pair in the dictionary of the respective key. i.e. `{"fields": {"prompt": "...", "response": "..."}, "responses": {"rating": "..."},
Source code in src/argilla/records/_resource.py
from_dict(data, dataset=None)
classmethod
¶
Converts a dictionary to a Record object. Args: data: A dictionary representing the record. dataset: The dataset object to which the record belongs. Returns: A Record object.
Source code in src/argilla/records/_resource.py
from_model(model, dataset)
classmethod
¶
Converts a RecordModel object to a Record object. Args: model: A RecordModel object. dataset: The dataset object to which the record belongs. Returns: A Record object.