Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions integration/test_collection_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ def test_object_ttl_creation(collection_factory: CollectionFactory) -> None:
collection = collection_factory(
object_ttl=Configure.ObjectTTL.delete_by_creation_time(
time_to_live=datetime.timedelta(days=30),
post_search_filter=True,
filter_expired_objects=True,
),
inverted_index_config=Configure.inverted_index(index_timestamps=True),
)
Expand All @@ -1861,15 +1861,15 @@ def test_object_ttl_update(collection_factory: CollectionFactory) -> None:
collection = collection_factory(
object_ttl=Configure.ObjectTTL.delete_by_update_time(
time_to_live=datetime.timedelta(days=30),
post_search_filter=True,
filter_expired_objects=True,
),
inverted_index_config=Configure.inverted_index(index_timestamps=True),
)

config = collection.config.get()
assert config.object_ttl_config is not None
assert config.object_ttl_config.delete_on == "updateTime"
assert config.object_ttl_config.post_search_filter
assert config.object_ttl_config.filter_expired_objects
assert config.object_ttl_config.time_to_live == datetime.timedelta(days=30)


Expand All @@ -1881,7 +1881,7 @@ def test_object_ttl_custom(collection_factory: CollectionFactory) -> None:
collection = collection_factory(
properties=[wvc.config.Property(name="customDate", data_type=DataType.DATE)],
object_ttl=Configure.ObjectTTL.delete_by_date_property(
date_property="customDate", post_search_filter=False, time_to_live_after_date=-1
property_name="customDate", filter_expired_objects=False, ttl_offset=-1
),
inverted_index_config=Configure.inverted_index(index_timestamps=True),
)
Expand All @@ -1890,4 +1890,4 @@ def test_object_ttl_custom(collection_factory: CollectionFactory) -> None:
assert config.object_ttl_config is not None
assert config.object_ttl_config.delete_on == "customDate"
assert config.object_ttl_config.time_to_live == datetime.timedelta(seconds=-1)
assert not config.object_ttl_config.post_search_filter
assert not config.object_ttl_config.filter_expired_objects
2 changes: 1 addition & 1 deletion weaviate/collections/classes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ def to_dict(self) -> Dict:
class _ObjectTTLConfig(_ConfigBase):
enabled: bool
time_to_live: Optional[datetime.timedelta]
post_search_filter: bool
filter_expired_objects: bool
delete_on: Union[str, Literal["updateTime"], Literal["creationTime"]]


Expand Down
2 changes: 1 addition & 1 deletion weaviate/collections/classes/config_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def _get_object_ttl_config(schema: Dict[str, Any]) -> Optional[_ObjectTTLConfig]
return _ObjectTTLConfig(
enabled=True,
delete_on=delete_on,
post_search_filter=schema["objectTtlConfig"]["postSearchFilter"],
filter_expired_objects=schema["objectTtlConfig"]["filterExpiredObjects"],
time_to_live=time_to_live,
)
else:
Expand Down
44 changes: 22 additions & 22 deletions weaviate/collections/classes/config_object_ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class _ObjectTTLCreate(_ConfigCreateModel):
enabled: bool = True
postSearchFilter: Optional[bool]
filterExpiredObjects: Optional[bool]
deleteOn: Optional[str]
defaultTtl: Optional[int]

Expand All @@ -17,60 +17,60 @@ class _ObjectTTL:
@staticmethod
def delete_by_update_time(
time_to_live: int | datetime.timedelta,
post_search_filter: Optional[bool] = None,
filter_expired_objects: Optional[bool] = None,
) -> _ObjectTTLCreate:
"""Create an `ObjectTimeToLiveConfig` object to be used when defining the object time-to-live configuration of Weaviate.

Args:
time_to_live: The time-to-live for objects in seconds.
post_search_filter: If enabled search results will be filtered to remove expired objects that have not yet been deleted.
time_to_live: The time-to-live for objects in relation to their last update time (seconds). Must be positive.
filter_expired_objects: If enabled, exclude expired but not deleted objects from search results.
"""
if isinstance(time_to_live, datetime.timedelta):
time_to_live = int(time_to_live.total_seconds())
return _ObjectTTLCreate(
deleteOn="_lastUpdateTimeUnix",
postSearchFilter=post_search_filter,
filterExpiredObjects=filter_expired_objects,
defaultTtl=time_to_live,
)

@staticmethod
def delete_by_creation_time(
time_to_live: int | datetime.timedelta,
post_search_filter: Optional[bool] = None,
filter_expired_objects: Optional[bool] = None,
) -> _ObjectTTLCreate:
"""Create an `ObjectTimeToLiveConfig` object to be used when defining the object time-to-live configuration of Weaviate.

Args:
time_to_live: The time-to-live for objects in seconds. Must be a positive value.
post_search_filter: If enabled search results will be filtered to remove expired objects that have not yet been deleted.
time_to_live: The time-to-live for objects in relation to their creation time (seconds). Must be positive.
filter_expired_objects: If enabled, exclude expired but not deleted objects from search results.
"""
if isinstance(time_to_live, datetime.timedelta):
time_to_live = int(time_to_live.total_seconds())
return _ObjectTTLCreate(
deleteOn="_creationTimeUnix",
postSearchFilter=post_search_filter,
filterExpiredObjects=filter_expired_objects,
defaultTtl=time_to_live,
)

@staticmethod
def delete_by_date_property(
date_property: str,
time_to_live_after_date: Optional[int | datetime.timedelta] = None,
post_search_filter: Optional[bool] = None,
property_name: str,
ttl_offset: Optional[int | datetime.timedelta] = None,
filter_expired_objects: Optional[bool] = None,
) -> _ObjectTTLCreate:
"""Create an Object ttl config for a custom date property.

Args:
date_property: The name of the date property to use for object expiration.
time_to_live_after_date: The time-to-live for objects in seconds after the date property value. Can be negative
post_search_filter: If enabled search results will be filtered to remove expired objects that have not yet been deleted.
property_name: The name of the date property to use for object expiration.
ttl_offset: The time-to-live for objects relative to the date (seconds if integer). Can be negative for indicating that objects should expire before the date property value.
filter_expired_objects: If enabled, exclude expired but not deleted objects from search results.
"""
if isinstance(time_to_live_after_date, datetime.timedelta):
time_to_live_after_date = int(time_to_live_after_date.total_seconds())
if time_to_live_after_date is None:
time_to_live_after_date = 0
if isinstance(ttl_offset, datetime.timedelta):
ttl_offset = int(ttl_offset.total_seconds())
if ttl_offset is None:
ttl_offset = 0
return _ObjectTTLCreate(
deleteOn=date_property,
postSearchFilter=post_search_filter,
defaultTtl=time_to_live_after_date,
deleteOn=property_name,
filterExpiredObjects=filter_expired_objects,
defaultTtl=ttl_offset,
)
Loading