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:

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.

import argilla_sdk as rg

# Define metadata properties as terms
metadata_field = rg.TermsMetadataProperty(
    name="color",
    options=["red", "blue", "green"],
    title="Color",
)

# Define metadata properties as float
float_ metadata_field = rg.FloatMetadataProperty(
    name="price",
    min=0.0,
    max=100.0,
    title="Price",
)

# Define metadata properties as integer
int_metadata_field = rg.IntegerMetadataProperty(
    name="quantity",
    min=0,
    max=100,
    title="Quantity",
)

Metadata properties can be added to a dataset settings object:

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

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


Class References

rg.FloatMetadataProperty

Bases: MetadataPropertyBase

Source code in src/argilla_sdk/settings/_metadata.py
class FloatMetadataProperty(MetadataPropertyBase):
    def __init__(
        self,
        name: str,
        min: Optional[float] = None,
        max: Optional[float] = None,
        title: Optional[str] = None,
        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 value
            max (Optional[float]): The maximum value
            title (Optional[str]): The title of the metadata field
            client (Optional[Argilla]): The client to use for API requests
        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,
        )

    @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, 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 value

None
max Optional[float]

The maximum value

None
title Optional[str]

The title of the metadata field

None
client Optional[Argilla]

The client to use for API requests

None

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

Source code in src/argilla_sdk/settings/_metadata.py
def __init__(
    self,
    name: str,
    min: Optional[float] = None,
    max: Optional[float] = None,
    title: Optional[str] = None,
    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 value
        max (Optional[float]): The maximum value
        title (Optional[str]): The title of the metadata field
        client (Optional[Argilla]): The client to use for API requests
    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,
    )

rg.IntegerMetadataProperty

Bases: MetadataPropertyBase

Source code in src/argilla_sdk/settings/_metadata.py
class IntegerMetadataProperty(MetadataPropertyBase):
    def __init__(
        self,
        name: str,
        min: Optional[int] = None,
        max: Optional[int] = None,
        title: Optional[str] = None,
        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 value
            max (Optional[int]): The maximum value
            title (Optional[str]): The title of the metadata field
        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,
        )

    @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, 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 value

None
max Optional[int]

The maximum value

None
title Optional[str]

The title of the metadata field

None

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

Source code in src/argilla_sdk/settings/_metadata.py
def __init__(
    self,
    name: str,
    min: Optional[int] = None,
    max: Optional[int] = None,
    title: Optional[str] = None,
    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 value
        max (Optional[int]): The maximum value
        title (Optional[str]): The title of the metadata field
    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,
    )

rg.TermsMetadataProperty

Bases: MetadataPropertyBase

Source code in src/argilla_sdk/settings/_metadata.py
class TermsMetadataProperty(MetadataPropertyBase):
    def __init__(
        self,
        name: str,
        options: Optional[List[str]] = 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[str]]): The list of options
            title (Optional[str]): The title of the metadata field
            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[str]]

The list of options

None
title Optional[str]

The title of the metadata field

None
visible_for_annotators Optional[bool]

Whether the metadata field is visible for annotators

True

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

Source code in src/argilla_sdk/settings/_metadata.py
def __init__(
    self,
    name: str,
    options: Optional[List[str]] = 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[str]]): The list of options
        title (Optional[str]): The title of the metadata field
        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,
    )