WeaviateEx.Types.Serializable protocol (WeaviateEx v0.7.4)
View SourceProtocol 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 timezoneDate-> ISO8601 date at midnight UTCGeoCoordinate->%{"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
Functions
Serializes a value to a Weaviate-compatible format.
Types
@type t() :: term()
All the types that implement this protocol.