Time to live (TTL)
v1.35.0 as a technical previewTime to live (TTL) was introduced in Weaviate v1.35.0 as a technical preview feature.
TTL is not available in Weaviate Cloud instances at this time.
Time-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.
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
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.
