WeaviateEx.Config.ObjectTTL (WeaviateEx v0.7.4)
View SourceObject Time-To-Live (TTL) configuration for automatic object expiration.
Weaviate 1.35+ supports automatic object expiration based on:
- Object creation time
- Object last update time
- Custom date property values
Usage
# Delete objects 24 hours after last update
ttl = WeaviateEx.Config.ObjectTTL.delete_by_update_time(86400)
# Delete objects 1 hour after creation
ttl = WeaviateEx.Config.ObjectTTL.delete_by_creation_time(3600)
# Delete objects based on a custom expiry_date property
ttl = WeaviateEx.Config.ObjectTTL.delete_by_date_property("expiry_date")
# Include in collection creation
WeaviateEx.Collections.create(client, "MyClass", %{
properties: [...],
object_ttl: ttl
})
Summary
Functions
Create TTL config that deletes objects based on their creation time.
Create TTL config that deletes objects based on a custom date property.
Create TTL config that deletes objects based on their last update time.
Create a config to disable TTL for a collection.
Creates a TTL config from a human-readable duration.
Create a TTL config from a map (e.g., from API response).
Convert a TTL config struct to a map for the Weaviate API.
Types
Functions
Create TTL config that deletes objects based on their creation time.
Parameters
time_to_live- TTL in seconds (positive integer)filter_expired_objects- If true, exclude expired but not yet deleted objects from search results (optional)
Examples
# Objects expire 1 hour after creation
WeaviateEx.Config.ObjectTTL.delete_by_creation_time(3600)
Create TTL config that deletes objects based on a custom date property.
This allows objects to expire based on any date property in the schema.
Parameters
property_name- The name of the date property to use for expirationttl_offset- Optional offset in seconds relative to the property date. Can be negative for indicating objects should expire before the date. Defaults to 0.filter_expired_objects- If true, exclude expired but not yet deleted objects from search results (optional)
Examples
# Delete when "expiry_date" property value is reached
WeaviateEx.Config.ObjectTTL.delete_by_date_property("expiry_date")
# Delete 1 hour after "event_date" property value
WeaviateEx.Config.ObjectTTL.delete_by_date_property("event_date", 3600)
# Delete 1 day before "deadline" property value
WeaviateEx.Config.ObjectTTL.delete_by_date_property("deadline", -86400)
Create TTL config that deletes objects based on their last update time.
Parameters
time_to_live- TTL in seconds (positive integer)filter_expired_objects- If true, exclude expired but not yet deleted objects from search results (optional)
Examples
# Objects expire 24 hours after last update
WeaviateEx.Config.ObjectTTL.delete_by_update_time(86400)
# With filtering of expired objects
WeaviateEx.Config.ObjectTTL.delete_by_update_time(86400, true)
@spec disable() :: t()
Create a config to disable TTL for a collection.
Use this when updating a collection to turn off automatic object expiration.
Examples
WeaviateEx.Collections.update("MyClass", %{
object_ttl: WeaviateEx.Config.ObjectTTL.disable()
})
Creates a TTL config from a human-readable duration.
This is a convenience function that creates a TTL configuration based on creation time with the specified duration.
Options
:days- Number of days:hours- Number of hours:minutes- Number of minutes:seconds- Number of seconds
Multiple units can be combined.
Examples
# Objects expire 24 hours after creation
ObjectTTL.from_duration(hours: 24)
# Objects expire 7 days after creation
ObjectTTL.from_duration(days: 7)
# Objects expire 30 minutes after creation
ObjectTTL.from_duration(minutes: 30)
# Combined: 1 day, 12 hours after creation
ObjectTTL.from_duration(days: 1, hours: 12)
Create a TTL config from a map (e.g., from API response).
Examples
iex> map = %{"enabled" => true, "deleteOn" => "_creationTimeUnix", "defaultTtl" => 3600}
iex> WeaviateEx.Config.ObjectTTL.from_map(map)
%WeaviateEx.Config.ObjectTTL{
enabled: true,
delete_on: "_creationTimeUnix",
default_ttl: 3600,
filter_expired_objects: nil
}
Convert a TTL config struct to a map for the Weaviate API.
This function handles the conversion of Elixir-style keys to the camelCase format expected by the Weaviate REST API.
Examples
iex> config = WeaviateEx.Config.ObjectTTL.delete_by_update_time(3600)
iex> WeaviateEx.Config.ObjectTTL.to_map(config)
%{
"enabled" => true,
"deleteOn" => "_lastUpdateTimeUnix",
"defaultTtl" => 3600
}