> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encord.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Metadata schema

## MetadataSchemaError Objects

```python theme={"dark"}
class MetadataSchemaError(RuntimeError)
```

Raised when an invariant is violated when mutating metadata schemas

## MetadataSchema Objects

```python theme={"dark"}
class MetadataSchema()
```

A class to manage the metadata schema for an organization.

**Methods:**

save() -> None: Saves the metadata schema to the backend if it has been modified.

#### save

```python theme={"dark"}
def save() -> None
```

Saves the metadata schema to the backend if changes have been made.

#### add\_embedding

```python theme={"dark"}
def add_embedding(k: str, *, size: int) -> None
```

Adds a new embedding to the metadata schema.

**Arguments**:

k : str: The key under which the embedding will be stored in the schema.
size : int: The size of the embedding.

**Raises**:

* `MetadataSchemaError` - If the key `k` is already defined in the schema.

#### add\_geospatial

```python theme={"dark"}
def add_geospatial(k: str) -> None
```

Adds a new geospatial type to the metadata schema.

**Arguments**:

k : str: The key under which the geospatial coordinates will be stored in the schema.

**Raises**:

* `MetadataSchemaError` - If the key `k` is already defined in the schema.

#### add\_enum

```python theme={"dark"}
def add_enum(k: str, *, values: Sequence[str]) -> None
```

Adds a new enum to the metadata schema.

**Arguments**:

k : str: The key under which the enum will be stored in the schema.
values : Sequence\[str]: The set of values for the enum (min 1, max 256).

**Raises**:

* `MetadataSchemaError` - If the key `k` is already defined in the schema.

#### add\_enum\_options

```python theme={"dark"}
def add_enum_options(k: str, *, values: Sequence[str]) -> None
```

Adds extra valid enum values to an existing enum schema.

**Arguments**:

k : str: The key referencing the enum.
values : Sequence\[str]: The set of new values to add to the enum (min 1, max 256).

**Raises**:

* `MetadataSchemaError` - If the key `k` is not defined in the schema or is not an enum.

#### add\_scalar

```python theme={"dark"}
def add_scalar(
    k: str, *, data_type: Union[
        Literal["boolean", "datetime", "number", "uuid", "varchar", "text",
                "string", "long_string"],
        MetadataSchemaScalarType,
    ]
) -> None
```

Sets a simple metadata type for a given key in the schema.

**Arguments**:

k : str: The key for which the metadata type is being set.
data\_type : Literal\["boolean", "datetime", "number", "uuid", "varchar", "text", "string", "long\_string"]
The type of metadata to be associated with the key. Must be a valid identifier.
"string" is an alias of "varchar"
"long\_string" is an alias of "text"

**Raises**:

* `MetadataSchemaError` - If the key `k` is already defined in the schema with a conflicting type.
* `ValueError` - If `data_type` is not a valid type of metadata identifier.

#### set\_scalar

```python theme={"dark"}
def set_scalar(
    k: str, *, data_type: Union[
        Literal["boolean", "datetime", "number", "uuid", "varchar", "text",
                "string", "long_string"],
        MetadataSchemaScalarType,
    ]
) -> None
```

Sets a simple metadata type for a given key in the schema.

Alias of add\_scalar

**Arguments**:

k : str: The key for which the metadata type is being set.
data\_type : Literal\["boolean", "datetime", "number", "uuid", "varchar", "text", "string", "long\_string"]
The type of metadata to be associated with the key. Must be a valid identifier.
"string" is an alias of "varchar"
"long\_string" is an alias of "text"

**Raises**:

* `MetadataSchemaError` - If the key `k` is already defined in the schema with a conflicting type.
* `ValueError` - If `data_type` is not a valid type of metadata identifier.

#### delete\_key

```python theme={"dark"}
def delete_key(k: str, *, hard: bool = False) -> None
```

Delete a metadata key from the schema.

**Arguments**:

k : str: The key for which the metadata type is being deleted.

* `hard` - bool: If the deletion should prevent indexing of this key unconditionally.
  Setting this to true prevents restoring the type definition in the future.

**Raises**:

* `MetadataSchemaError` - If the key `k` is already deleted or not present in the schema

#### restore\_key

```python theme={"dark"}
def restore_key(k: str) -> None
```

Restore a deleted metadata key to its original value.

**Arguments**:

k : str: The key for which the metadata type is to be restored.

**Raises**:

* `MetadataSchemaError` - If the key `k` is not already deleted or not present in the schema

#### keys

```python theme={"dark"}
def keys() -> Sequence[str]
```

Returns a sequence of all keys defined in the metadata schema.

**Returns**:

* `Sequence[str]` - A list of keys present in the metadata schema.

#### has\_key

```python theme={"dark"}
def has_key(k: str) -> bool
```

Check if any definition exists for a key.

**Arguments**:

k : str: The key for which the metadata type is to be retrieved.

#### is\_key\_deleted

```python theme={"dark"}
def is_key_deleted(k: str) -> bool
```

Check if the key is defined as deleted. (Tombstone type)

**Arguments**:

k : str: The key for which the metadata type is to be retrieved.

#### get\_key\_type

```python theme={"dark"}
def get_key_type(
    k: str
) -> Union[Literal["boolean", "datetime", "uuid", "number", "varchar", "text",
                   "embedding", "enum", "geospatial"], None]
```

Retrieves the metadata type associated with a given key.

**Arguments**:

k : str: The key for which the metadata type is to be retrieved.

**Returns**:

Literal\["boolean", "datetime", "uuid", "number", "varchar", "text", "embedding", "enum", "geospatial"]: The metadata type associated with the key `k`.

**Raises**:

* `MetadataSchemaError` - If the key `k` is not supported by the current SDK.

#### get\_embedding\_size

```python theme={"dark"}
def get_embedding_size(k: str) -> int
```

Retrieves size associated with a given embedding.

**Arguments**:

k : str: The key for which the metadata type is to be retrieved.

**Returns**:

* `int` - The size of the embedding

**Raises**:

* `MetadataSchemaError` - If the key `k` is not defined in the schema or is not an embedding

#### get\_enum\_options

```python theme={"dark"}
def get_enum_options(k: str) -> Sequence[str]
```

Retrieves all values associated with a given enum.

**Arguments**:

k : str: The key for which the metadata type is to be retrieved.

**Returns**:

* `Sequence[str]` - The list of all values associated with an enum type.

**Raises**:

* `MetadataSchemaError` - If the key `k` is not defined in the schema or is not an enum.
