|
| 1 | +import datetime |
1 | 2 | from typing import Generator, List, Optional, Union |
2 | 3 |
|
3 | 4 | import pytest as pytest |
@@ -1833,3 +1834,119 @@ def test_uncompressed_quantitizer(collection_factory: CollectionFactory) -> None |
1833 | 1834 | assert config.vector_index_config is not None |
1834 | 1835 | assert isinstance(config.vector_index_config, _VectorIndexConfigHNSW) |
1835 | 1836 | assert config.vector_index_config.quantizer is None |
| 1837 | + |
| 1838 | + |
| 1839 | +def test_object_ttl_creation(collection_factory: CollectionFactory) -> None: |
| 1840 | + dummy = collection_factory("dummy") |
| 1841 | + if dummy._connection._weaviate_version.is_lower_than(1, 35, 0): |
| 1842 | + pytest.skip("object ttl is not supported in Weaviate versions lower than 1.35.0") |
| 1843 | + |
| 1844 | + collection = collection_factory( |
| 1845 | + object_ttl=Configure.ObjectTTL.delete_by_creation_time( |
| 1846 | + time_to_live=datetime.timedelta(days=30), |
| 1847 | + filter_expired_objects=True, |
| 1848 | + ), |
| 1849 | + inverted_index_config=Configure.inverted_index(index_timestamps=True), |
| 1850 | + ) |
| 1851 | + |
| 1852 | + config = collection.config.get() |
| 1853 | + assert config.object_ttl_config is not None |
| 1854 | + assert config.object_ttl_config.delete_on == "creationTime" |
| 1855 | + assert config.object_ttl_config.time_to_live == datetime.timedelta(days=30) |
| 1856 | + |
| 1857 | + |
| 1858 | +def test_object_ttl_update_time(collection_factory: CollectionFactory) -> None: |
| 1859 | + dummy = collection_factory("dummy") |
| 1860 | + if dummy._connection._weaviate_version.is_lower_than(1, 35, 0): |
| 1861 | + pytest.skip("object ttl is not supported in Weaviate versions lower than 1.35.0") |
| 1862 | + |
| 1863 | + collection = collection_factory( |
| 1864 | + object_ttl=Configure.ObjectTTL.delete_by_update_time( |
| 1865 | + time_to_live=datetime.timedelta(days=30), |
| 1866 | + filter_expired_objects=True, |
| 1867 | + ), |
| 1868 | + inverted_index_config=Configure.inverted_index(index_timestamps=True), |
| 1869 | + ) |
| 1870 | + |
| 1871 | + config = collection.config.get() |
| 1872 | + assert config.object_ttl_config is not None |
| 1873 | + assert config.object_ttl_config.delete_on == "updateTime" |
| 1874 | + assert config.object_ttl_config.filter_expired_objects |
| 1875 | + assert config.object_ttl_config.time_to_live == datetime.timedelta(days=30) |
| 1876 | + |
| 1877 | + |
| 1878 | +def test_object_ttl_custom(collection_factory: CollectionFactory) -> None: |
| 1879 | + dummy = collection_factory("dummy") |
| 1880 | + if dummy._connection._weaviate_version.is_lower_than(1, 35, 0): |
| 1881 | + pytest.skip("object ttl is not supported in Weaviate versions lower than 1.35.0") |
| 1882 | + |
| 1883 | + collection = collection_factory( |
| 1884 | + properties=[wvc.config.Property(name="customDate", data_type=DataType.DATE)], |
| 1885 | + object_ttl=Configure.ObjectTTL.delete_by_date_property( |
| 1886 | + property_name="customDate", filter_expired_objects=False, ttl_offset=-1 |
| 1887 | + ), |
| 1888 | + inverted_index_config=Configure.inverted_index(index_timestamps=True), |
| 1889 | + ) |
| 1890 | + |
| 1891 | + config = collection.config.get() |
| 1892 | + assert config.object_ttl_config is not None |
| 1893 | + assert config.object_ttl_config.delete_on == "customDate" |
| 1894 | + assert config.object_ttl_config.time_to_live == datetime.timedelta(seconds=-1) |
| 1895 | + assert not config.object_ttl_config.filter_expired_objects |
| 1896 | + |
| 1897 | + |
| 1898 | +def test_object_ttl_update(collection_factory: CollectionFactory) -> None: |
| 1899 | + dummy = collection_factory("dummy") |
| 1900 | + if dummy._connection._weaviate_version.is_lower_than(1, 35, 0): |
| 1901 | + pytest.skip("object ttl is not supported in Weaviate versions lower than 1.35.0") |
| 1902 | + |
| 1903 | + collection = collection_factory( |
| 1904 | + properties=[ |
| 1905 | + wvc.config.Property(name="customDate", data_type=DataType.DATE), |
| 1906 | + wvc.config.Property(name="customDate2", data_type=DataType.DATE), |
| 1907 | + ], |
| 1908 | + inverted_index_config=Configure.inverted_index(index_timestamps=True), |
| 1909 | + ) |
| 1910 | + |
| 1911 | + conf = collection.config.get() |
| 1912 | + assert conf.object_ttl_config is None |
| 1913 | + |
| 1914 | + collection.config.update( |
| 1915 | + object_ttl_config=Reconfigure.ObjectTTL.delete_by_date_property( |
| 1916 | + property_name="customDate", filter_expired_objects=True, ttl_offset=3600 |
| 1917 | + ), |
| 1918 | + ) |
| 1919 | + |
| 1920 | + conf = collection.config.get() |
| 1921 | + assert conf.object_ttl_config is not None |
| 1922 | + assert conf.object_ttl_config.delete_on == "customDate" |
| 1923 | + assert conf.object_ttl_config.time_to_live == datetime.timedelta(seconds=3600) |
| 1924 | + assert conf.object_ttl_config.filter_expired_objects |
| 1925 | + |
| 1926 | + collection.config.update( |
| 1927 | + object_ttl_config=Reconfigure.ObjectTTL.delete_by_update_time(filter_expired_objects=False), |
| 1928 | + ) |
| 1929 | + |
| 1930 | + conf = collection.config.get() |
| 1931 | + assert conf.object_ttl_config is not None |
| 1932 | + assert conf.object_ttl_config.delete_on == "updateTime" |
| 1933 | + assert conf.object_ttl_config.time_to_live == datetime.timedelta(seconds=3600) |
| 1934 | + assert not conf.object_ttl_config.filter_expired_objects |
| 1935 | + |
| 1936 | + collection.config.update( |
| 1937 | + object_ttl_config=Reconfigure.ObjectTTL.delete_by_creation_time( |
| 1938 | + time_to_live=datetime.timedelta(seconds=600), |
| 1939 | + ), |
| 1940 | + ) |
| 1941 | + |
| 1942 | + conf = collection.config.get() |
| 1943 | + assert conf.object_ttl_config is not None |
| 1944 | + assert conf.object_ttl_config.delete_on == "creationTime" |
| 1945 | + assert conf.object_ttl_config.time_to_live == datetime.timedelta(seconds=600) |
| 1946 | + assert not conf.object_ttl_config.filter_expired_objects |
| 1947 | + |
| 1948 | + collection.config.update( |
| 1949 | + object_ttl_config=Reconfigure.ObjectTTL.disable(), |
| 1950 | + ) |
| 1951 | + conf = collection.config.get() |
| 1952 | + assert conf.object_ttl_config is None |
0 commit comments