# `Zvex.Types`
[🔗](https://github.com/edlontech/zvex/blob/main/lib/zvex/types.ex#L1)

Type conversion utilities for zvec data types, index types, and metric types.

Converts between the atoms used in the Elixir API and human-readable strings
matching the zvec C API's `zvec_*_to_string` functions.

# `data_type`

```elixir
@type data_type() ::
  :string
  | :int32
  | :int64
  | :uint32
  | :uint64
  | :float
  | :double
  | :bool
  | :binary
  | :vector_fp32
  | :vector_fp16
  | :vector_fp64
  | :vector_int4
  | :vector_int8
  | :vector_int16
  | :vector_binary32
  | :vector_binary64
  | :sparse_vector_fp16
  | :sparse_vector_fp32
  | :array_string
  | :array_int32
  | :array_int64
  | :array_uint32
  | :array_uint64
  | :array_float
  | :array_double
  | :array_bool
  | :array_binary
```

# `index_type`

```elixir
@type index_type() :: :hnsw | :ivf | :flat | :invert
```

# `metric_type`

```elixir
@type metric_type() :: :l2 | :ip | :cosine | :mipsl2
```

# `data_type_to_string`

```elixir
@spec data_type_to_string(data_type()) :: {:ok, String.t()} | :error
```

Converts a data type atom to its string representation.

## Examples

    iex> Zvex.Types.data_type_to_string(:vector_fp32)
    {:ok, "VECTOR_FP32"}

    iex> Zvex.Types.data_type_to_string(:nope)
    :error

# `data_types`

```elixir
@spec data_types() :: [data_type()]
```

Returns the list of all known data type atoms.

# `index_type_to_string`

```elixir
@spec index_type_to_string(index_type()) :: {:ok, String.t()} | :error
```

Converts an index type atom to its string representation.

## Examples

    iex> Zvex.Types.index_type_to_string(:hnsw)
    {:ok, "HNSW"}

    iex> Zvex.Types.index_type_to_string(:nope)
    :error

# `index_types`

```elixir
@spec index_types() :: [index_type()]
```

Returns the list of all known index type atoms.

# `metric_type_to_string`

```elixir
@spec metric_type_to_string(metric_type()) :: {:ok, String.t()} | :error
```

Converts a metric type atom to its string representation.

## Examples

    iex> Zvex.Types.metric_type_to_string(:cosine)
    {:ok, "COSINE"}

    iex> Zvex.Types.metric_type_to_string(:nope)
    :error

# `metric_types`

```elixir
@spec metric_types() :: [metric_type()]
```

Returns the list of all known metric type atoms.

# `string_to_data_type`

```elixir
@spec string_to_data_type(String.t()) :: {:ok, data_type()} | :error
```

Converts a string to its data type atom.

## Examples

    iex> Zvex.Types.string_to_data_type("VECTOR_FP32")
    {:ok, :vector_fp32}

    iex> Zvex.Types.string_to_data_type("NOPE")
    :error

# `string_to_index_type`

```elixir
@spec string_to_index_type(String.t()) :: {:ok, index_type()} | :error
```

Converts a string to its index type atom.

## Examples

    iex> Zvex.Types.string_to_index_type("HNSW")
    {:ok, :hnsw}

    iex> Zvex.Types.string_to_index_type("NOPE")
    :error

# `string_to_metric_type`

```elixir
@spec string_to_metric_type(String.t()) :: {:ok, metric_type()} | :error
```

Converts a string to its metric type atom.

## Examples

    iex> Zvex.Types.string_to_metric_type("COSINE")
    {:ok, :cosine}

    iex> Zvex.Types.string_to_metric_type("NOPE")
    :error

---

*Consult [api-reference.md](api-reference.md) for complete listing*
