Skip to content

Metadata Properties

Metadata properties are used to define metadata fields in a dataset. Metadata fields are used to store additional information about the records in the dataset. For example, the category of a record, the price of a product, or any other information that is relevant to the record.

Usage Examples

Defining Metadata Property for a dataset

We define metadata properties via type specific classes. The following example demonstrates how to define metadata properties as either a float, integer, or terms metadata property and pass them to the Settings.

TermsMetadataProperty is used to define a metadata field with a list of options. For example, a color field with options red, blue, and green. FloatMetadataProperty and IntegerMetadataProperty is used to define a metadata field with a float value. For example, a price field with a minimum value of 0.0 and a maximum value of 100.0.

metadata_field = rg.TermsMetadataProperty(
    name="color",
    options=["red", "blue", "green"],
    title="Color",
)

float_metadata_field = rg.FloatMetadataProperty(
    name="price",
    min=0.0,
    max=100.0,
    title="Price",
)

int_metadata_field = rg.IntegerMetadataProperty(
    name="quantity",
    min=0,
    max=100,
    title="Quantity",
)

dataset = rg.Dataset(
    name="my_dataset",
    settings=rg.Settings(
        fields=[
            rg.TextField(name="text"),
        ],
        questions=[
            rg.TextQuestion(name="response"),
        ],
        metadata=[
            metadata_field,
            float_metadata_field,
            int_metadata_field,
        ],
    ),
)

dataset = rg.Dataset(
    name="my_dataset",
    settings=settings,
)

To add records with metadata, refer to the rg.Metadata class documentation.


FloatMetadataProperty

Bases: MetadataPropertyBase

Source code in src/argilla/settings/_metadata.py
class FloatMetadataProperty(MetadataPropertyBase):
    def __init__(
        self,
        name: str,
        min: Optional[float] = None,
        max: Optional[float] = None,
        title: Optional[str] = None,
        visible_for_annotators: Optional[bool] = True,
        client: Optional[Argilla] = None,
    ) -> None:
        """Create a metadata field with float settings.

        Parameters:
            name (str): The name of the metadata field
            min (Optional[float]): The minimum valid value. If none is provided, it will be computed from the values provided in the records.
            max (Optional[float]): The maximum valid value. If none is provided, it will be computed from the values provided in the records.
            title (Optional[str]): The title of the metadata to be shown in the UI
            visible_for_annotators (Optional[bool]): Whether the metadata field is visible for annotators.

        Raises:
            MetadataError: If an error occurs while defining metadata settings.
        """

        super().__init__(client=client)

        try:
            settings = FloatMetadataPropertySettings(min=min, max=max, type=MetadataPropertyType.float)
        except ValueError as e:
            raise MetadataError(f"Error defining metadata settings for {name}") from e

        self._model = MetadataFieldModel(
            name=name,
            type=MetadataPropertyType.float,
            title=title,
            settings=settings,
            visible_for_annotators=visible_for_annotators,
        )

    @property
    def min(self) -> Optional[int]:
        return self._model.settings.min

    @min.setter
    def min(self, value: Optional[int]) -> None:
        self._model.settings.min = value

    @property
    def max(self) -> Optional[int]:
        return self._model.settings.max

    @max.setter
    def max(self, value: Optional[int]) -> None:
        self._model.settings.max = value

    @classmethod
    def from_model(cls, model: MetadataFieldModel) -> "FloatMetadataProperty":
        instance = FloatMetadataProperty(name=model.name)
        instance._model = model

        return instance

__init__(name, min=None, max=None, title=None, visible_for_annotators=True, client=None)

Create a metadata field with float settings.

Parameters:

Name Type Description Default
name str

The name of the metadata field

required
min Optional[float]

The minimum valid value. If none is provided, it will be computed from the values provided in the records.

None
max Optional[float]

The maximum valid value. If none is provided, it will be computed from the values provided in the records.

None
title Optional[str]

The title of the metadata to be shown in the UI

None
visible_for_annotators Optional[bool]

Whether the metadata field is visible for annotators.

True

Raises:

Type Description
MetadataError

If an error occurs while defining metadata settings.

Source code in src/argilla/settings/_metadata.py
def __init__(
    self,
    name: str,
    min: Optional[float] = None,
    max: Optional[float] = None,
    title: Optional[str] = None,
    visible_for_annotators: Optional[bool] = True,
    client: Optional[Argilla] = None,
) -> None:
    """Create a metadata field with float settings.

    Parameters:
        name (str): The name of the metadata field
        min (Optional[float]): The minimum valid value. If none is provided, it will be computed from the values provided in the records.
        max (Optional[float]): The maximum valid value. If none is provided, it will be computed from the values provided in the records.
        title (Optional[str]): The title of the metadata to be shown in the UI
        visible_for_annotators (Optional[bool]): Whether the metadata field is visible for annotators.

    Raises:
        MetadataError: If an error occurs while defining metadata settings.
    """

    super().__init__(client=client)

    try:
        settings = FloatMetadataPropertySettings(min=min, max=max, type=MetadataPropertyType.float)
    except ValueError as e:
        raise MetadataError(f"Error defining metadata settings for {name}") from e

    self._model = MetadataFieldModel(
        name=name,
        type=MetadataPropertyType.float,
        title=title,
        settings=settings,
        visible_for_annotators=visible_for_annotators,
    )

IntegerMetadataProperty

Bases: MetadataPropertyBase

Source code in src/argilla/settings/_metadata.py
class IntegerMetadataProperty(MetadataPropertyBase):
    def __init__(
        self,
        name: str,
        min: Optional[int] = None,
        max: Optional[int] = None,
        title: Optional[str] = None,
        visible_for_annotators: Optional[bool] = True,
        client: Optional[Argilla] = None,
    ) -> None:
        """Create a metadata field with integer settings.

        Parameters:
            name (str): The name of the metadata field
            min (Optional[int]): The minimum valid value. If none is provided, it will be computed from the values provided in the records.
            max (Optional[int]): The maximum  valid value. If none is provided, it will be computed from the values provided in the records.
            title (Optional[str]): The title of the metadata to be shown in the UI
            visible_for_annotators (Optional[bool]): Whether the metadata field is visible for annotators.

        Raises:
            MetadataError: If an error occurs while defining metadata settings.
        """
        super().__init__(client=client)

        try:
            settings = IntegerMetadataPropertySettings(min=min, max=max, type=MetadataPropertyType.integer)
        except ValueError as e:
            raise MetadataError(f"Error defining metadata settings for {name}") from e

        self._model = MetadataFieldModel(
            name=name,
            type=MetadataPropertyType.integer,
            title=title,
            settings=settings,
            visible_for_annotators=visible_for_annotators,
        )

    @property
    def min(self) -> Optional[int]:
        return self._model.settings.min

    @min.setter
    def min(self, value: Optional[int]) -> None:
        self._model.settings.min = value

    @property
    def max(self) -> Optional[int]:
        return self._model.settings.max

    @max.setter
    def max(self, value: Optional[int]) -> None:
        self._model.settings.max = value

    @classmethod
    def from_model(cls, model: MetadataFieldModel) -> "IntegerMetadataProperty":
        instance = IntegerMetadataProperty(name=model.name)
        instance._model = model

        return instance

__init__(name, min=None, max=None, title=None, visible_for_annotators=True, client=None)

Create a metadata field with integer settings.

Parameters:

Name Type Description Default
name str

The name of the metadata field

required
min Optional[int]

The minimum valid value. If none is provided, it will be computed from the values provided in the records.

None
max Optional[int]

The maximum valid value. If none is provided, it will be computed from the values provided in the records.

None
title Optional[str]

The title of the metadata to be shown in the UI

None
visible_for_annotators Optional[bool]

Whether the metadata field is visible for annotators.

True

Raises:

Type Description
MetadataError

If an error occurs while defining metadata settings.

Source code in src/argilla/settings/_metadata.py
def __init__(
    self,
    name: str,
    min: Optional[int] = None,
    max: Optional[int] = None,
    title: Optional[str] = None,
    visible_for_annotators: Optional[bool] = True,
    client: Optional[Argilla] = None,
) -> None:
    """Create a metadata field with integer settings.

    Parameters:
        name (str): The name of the metadata field
        min (Optional[int]): The minimum valid value. If none is provided, it will be computed from the values provided in the records.
        max (Optional[int]): The maximum  valid value. If none is provided, it will be computed from the values provided in the records.
        title (Optional[str]): The title of the metadata to be shown in the UI
        visible_for_annotators (Optional[bool]): Whether the metadata field is visible for annotators.

    Raises:
        MetadataError: If an error occurs while defining metadata settings.
    """
    super().__init__(client=client)

    try:
        settings = IntegerMetadataPropertySettings(min=min, max=max, type=MetadataPropertyType.integer)
    except ValueError as e:
        raise MetadataError(f"Error defining metadata settings for {name}") from e

    self._model = MetadataFieldModel(
        name=name,
        type=MetadataPropertyType.integer,
        title=title,
        settings=settings,
        visible_for_annotators=visible_for_annotators,
    )

TermsMetadataProperty

Bases: MetadataPropertyBase

Source code in src/argilla/settings/_metadata.py
class TermsMetadataProperty(MetadataPropertyBase):
    def __init__(
        self,
        name: str,
        options: Optional[List[Any]] = None,
        title: Optional[str] = None,
        visible_for_annotators: Optional[bool] = True,
        client: Optional[Argilla] = None,
    ) -> None:
        """Create a metadata field with terms settings.

        Parameters:
            name (str): The name of the metadata field
            options (Optional[List[Any]]): The list of options
            title (Optional[str]): The title of the metadata to be shown in the UI
            visible_for_annotators (Optional[bool]): Whether the metadata field is visible for annotators.

        Raises:
            MetadataError: If an error occurs while defining metadata settings
        """
        super().__init__(client=client)

        try:
            settings = TermsMetadataPropertySettings(values=options, type=MetadataPropertyType.terms)
        except ValueError as e:
            raise MetadataError(f"Error defining metadata settings for {name}") from e

        self._model = MetadataFieldModel(
            name=name,
            type=MetadataPropertyType.terms,
            title=title,
            settings=settings,
            visible_for_annotators=visible_for_annotators,
        )

    @property
    def options(self) -> Optional[List[str]]:
        return self._model.settings.values

    @options.setter
    def options(self, value: list[str]) -> None:
        self._model.settings.values = value

    @classmethod
    def from_model(cls, model: MetadataFieldModel) -> "TermsMetadataProperty":
        instance = TermsMetadataProperty(name=model.name)
        instance._model = model

        return instance

__init__(name, options=None, title=None, visible_for_annotators=True, client=None)

Create a metadata field with terms settings.

Parameters:

Name Type Description Default
name str

The name of the metadata field

required
options Optional[List[Any]]

The list of options

None
title Optional[str]

The title of the metadata to be shown in the UI

None
visible_for_annotators Optional[bool]

Whether the metadata field is visible for annotators.

True

Raises:

Type Description
MetadataError

If an error occurs while defining metadata settings

Source code in src/argilla/settings/_metadata.py
def __init__(
    self,
    name: str,
    options: Optional[List[Any]] = None,
    title: Optional[str] = None,
    visible_for_annotators: Optional[bool] = True,
    client: Optional[Argilla] = None,
) -> None:
    """Create a metadata field with terms settings.

    Parameters:
        name (str): The name of the metadata field
        options (Optional[List[Any]]): The list of options
        title (Optional[str]): The title of the metadata to be shown in the UI
        visible_for_annotators (Optional[bool]): Whether the metadata field is visible for annotators.

    Raises:
        MetadataError: If an error occurs while defining metadata settings
    """
    super().__init__(client=client)

    try:
        settings = TermsMetadataPropertySettings(values=options, type=MetadataPropertyType.terms)
    except ValueError as e:
        raise MetadataError(f"Error defining metadata settings for {name}") from e

    self._model = MetadataFieldModel(
        name=name,
        type=MetadataPropertyType.terms,
        title=title,
        settings=settings,
        visible_for_annotators=visible_for_annotators,
    )