WeaviateEx.Objects.Payload (WeaviateEx v0.7.4)

View Source

Utilities for preparing object payloads for Weaviate requests.

These helpers keep UUID generation, key normalization, and class assignments consistent between the high-level WeaviateEx.Objects module and the lower-level WeaviateEx.API.Data module.

Summary

Functions

Removes any existing class markers and sets the provided class on the payload.

Ensures a UUID is present on the payload. By default a new UUID is generated using Uniq.UUID. Use auto_generate_id: false to skip automatic generation.

Removes any existing id markers and sets the provided id on the payload.

Normalizes a payload by converting atom keys to strings and recursively normalizing nested maps or lists.

Prepares a payload for insertion by normalizing keys, generating an id when necessary, applying the collection class, handling vectors, and merging references.

Normalizes a payload for patch operations (class/id handled by the server).

Prepares a payload for update requests by normalizing keys, forcing the id, applying the collection class, and handling vectors.

Types

data()

@type data() :: map()

opts()

@type opts() :: keyword()

Functions

ensure_class(data, class_name)

@spec ensure_class(data(), String.t()) :: data()

Removes any existing class markers and sets the provided class on the payload.

ensure_id(data, opts \\ [])

@spec ensure_id(data(), opts()) :: data()

Ensures a UUID is present on the payload. By default a new UUID is generated using Uniq.UUID. Use auto_generate_id: false to skip automatic generation.

ensure_id_value(data, id)

@spec ensure_id_value(data(), String.t()) :: data()

Removes any existing id markers and sets the provided id on the payload.

normalize_keys(data)

@spec normalize_keys(data()) :: data()

Normalizes a payload by converting atom keys to strings and recursively normalizing nested maps or lists.

Structs are passed through unchanged (they will be serialized later by serialize_properties/1).

prepare_for_insert(data, class_name, opts \\ [])

@spec prepare_for_insert(data(), String.t(), opts()) :: data()

Prepares a payload for insertion by normalizing keys, generating an id when necessary, applying the collection class, handling vectors, and merging references.

Vector Support

Supports both single vector and named vectors (mutually exclusive):

  • :vector - Single vector for the default vector
  • :vectors - Map of named vectors (e.g., %{"title_vector" => [0.1, 0.2]})

Raises ArgumentError if both :vector and :vectors are provided.

Reference Support

Supports inline references via the :references key:

  • Single UUID: %{"hasAuthor" => "uuid-123"}
  • Multiple UUIDs: %{"hasAuthors" => ["uuid-1", "uuid-2"]}
  • Multi-target: %{"relatedTo" => %{target_collection: "Category", uuids: "cat-uuid"}}

References are converted to beacon format and merged into properties.

Property Value Serialization

Special types are automatically serialized to Weaviate-compatible formats via the WeaviateEx.Types.Serializable protocol:

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

Nested objects and arrays are recursively serialized.

prepare_for_patch(data)

@spec prepare_for_patch(data()) :: data()

Normalizes a payload for patch operations (class/id handled by the server).

prepare_for_update(data, class_name, id, opts \\ [])

@spec prepare_for_update(data(), String.t(), String.t(), opts()) :: data()

Prepares a payload for update requests by normalizing keys, forcing the id, applying the collection class, and handling vectors.

Vector Support

Supports both single vector and named vectors (mutually exclusive):

  • :vector - Single vector for the default vector
  • :vectors - Map of named vectors (e.g., %{"title_vector" => [0.1, 0.2]})

Raises ArgumentError if both :vector and :vectors are provided.