WeaviateEx.Types.Serializable protocol (WeaviateEx v0.7.4)

View Source

Protocol for serializing Elixir types to Weaviate-compatible values.

This protocol enables automatic serialization of complex Elixir types when creating or updating objects in Weaviate. Types implementing this protocol will be automatically converted to the appropriate format.

Built-in Implementations

  • DateTime -> ISO8601 string with timezone (RFC3339)
  • NaiveDateTime -> ISO8601 string without timezone
  • Date -> ISO8601 date at midnight UTC
  • GeoCoordinate -> %{"latitude" => lat, "longitude" => lon}
  • PhoneNumber -> %{"input" => number, "defaultCountry" => country}
  • Blob -> Base64-encoded string

Examples

# DateTime serialization
iex> Serializable.serialize(~U[2024-01-01 00:00:00Z])
"2024-01-01T00:00:00Z"

# GeoCoordinate serialization
iex> {:ok, geo} = WeaviateEx.Types.GeoCoordinate.new(52.37, 4.90)
iex> Serializable.serialize(geo)
%{"latitude" => 52.37, "longitude" => 4.90}

Custom Types

You can implement this protocol for your own types:

defimpl WeaviateEx.Types.Serializable, for: MyApp.CustomType do
  def serialize(%MyApp.CustomType{value: v}), do: v
end

Summary

Types

t()

All the types that implement this protocol.

Functions

Serializes a value to a Weaviate-compatible format.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

serialize(value)

@spec serialize(t()) :: any()

Serializes a value to a Weaviate-compatible format.

Returns the serialized value suitable for the Weaviate API.