Zvex.Types (zvex v0.4.0)

Copy Markdown View Source

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.

Summary

Functions

Converts a data type atom to its string representation.

Returns the list of all known data type atoms.

Converts an index type atom to its string representation.

Returns the list of all known index type atoms.

Converts a metric type atom to its string representation.

Returns the list of all known metric type atoms.

Converts a string to its data type atom.

Converts a string to its index type atom.

Converts a string to its metric type atom.

Types

data_type()

@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()

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

metric_type()

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

Functions

data_type_to_string(atom)

@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()

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

Returns the list of all known data type atoms.

index_type_to_string(atom)

@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()

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

Returns the list of all known index type atoms.

metric_type_to_string(atom)

@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()

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

Returns the list of all known metric type atoms.

string_to_data_type(string)

@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(string)

@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(string)

@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