Time to live (TTL)
v1.36Time-to-live (TTL) allows you to set an expiration time for objects in a collection.
Expired objects are periodically removed from the collection by Weaviate's background processes, helping you manage data lifecycle and storage.
TTLs are currently defined at the collection level. They can be set relative to an object's creation time, the last update time, or a specific DATE property within the object.
With all TTL definitions, you can optionally set whether to exclude expired, but not yet deleted, objects from query results. This can prevent erroneous data retrieval before the background deletion process runs.
TTL requires the OBJECTS_TTL_DELETE_SCHEDULE environment variable to be set on the Weaviate instance. This variable defines the cron schedule for the background deletion process. If it is not set, expired objects will not be deleted.
The minimum TTL value is 60 seconds.
Relative to a creation time
Set a TTL to count forward from the object's creation time metadata. The value must be positive.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
from weaviate.classes.config import Configure, Property, DataType
import datetime
client.collections.create(
name="CollectionWithTTL",
properties=[
Property(name="referenceDate", data_type=DataType.DATE),
],
object_ttl_config=Configure.ObjectTTL.delete_by_creation_time(
time_to_live=datetime.timedelta(hours=1), # Or set 3600 for seconds
filter_expired_objects=True, # Optional: automatically filter out expired objects from queries
),
)
Relative to a last update time
Set a TTL to count forward from the object's last updated time metadata. The value must be positive.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
from weaviate.classes.config import Configure, Property, DataType
import datetime
client.collections.create(
name="CollectionWithTTL",
properties=[
Property(name="referenceDate", data_type=DataType.DATE),
],
object_ttl_config=Configure.ObjectTTL.delete_by_update_time(
time_to_live=datetime.timedelta(days=10), # Or set 864000 for seconds
filter_expired_objects=True, # Optional: automatically filter out expired objects from queries
),
)
Relative to a specific DATE property
Set a TTL to a relative value from a specific DATE property within the object. The value can be positive or negative.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
from weaviate.classes.config import Configure, Property, DataType
import datetime
client.collections.create(
name="CollectionWithTTL",
properties=[
Property(name="referenceDate", data_type=DataType.DATE),
],
object_ttl_config=Configure.ObjectTTL.delete_by_date_property(
property_name="referenceDate",
ttl_offset=datetime.timedelta(minutes=5),
),
)
Further resources
Questions and feedback
If you have any questions or feedback, let us know in the user forum.
