|
| 1 | +import datetime |
1 | 2 | from dataclasses import dataclass |
2 | 3 | from typing import ( |
3 | 4 | Any, |
|
31 | 32 | _NamedVectors, |
32 | 33 | _NamedVectorsUpdate, |
33 | 34 | ) |
| 35 | +from weaviate.collections.classes.config_object_ttl import _ObjectTTL, _ObjectTTLCreate |
34 | 36 | from weaviate.collections.classes.config_vector_index import ( |
35 | 37 | PQEncoderDistribution, |
36 | 38 | PQEncoderType, |
@@ -1136,64 +1138,6 @@ def contextualai( |
1136 | 1138 | return _RerankerContextualAIConfig(model=model, instruction=instruction, topN=top_n) |
1137 | 1139 |
|
1138 | 1140 |
|
1139 | | -class _CollectionConfigCreateBase(_ConfigCreateModel): |
1140 | | - description: Optional[str] = Field(default=None) |
1141 | | - invertedIndexConfig: Optional[_InvertedIndexConfigCreate] = Field( |
1142 | | - default=None, alias="inverted_index_config" |
1143 | | - ) |
1144 | | - multiTenancyConfig: Optional[_MultiTenancyConfigCreate] = Field( |
1145 | | - default=None, alias="multi_tenancy_config" |
1146 | | - ) |
1147 | | - replicationConfig: Optional[_ReplicationConfigCreate] = Field( |
1148 | | - default=None, alias="replication_config" |
1149 | | - ) |
1150 | | - shardingConfig: Optional[_ShardingConfigCreate] = Field(default=None, alias="sharding_config") |
1151 | | - vectorIndexConfig: Optional[_VectorIndexConfigCreate] = Field( |
1152 | | - default=None, alias="vector_index_config" |
1153 | | - ) |
1154 | | - moduleConfig: _VectorizerConfigCreate = Field( |
1155 | | - default=_Vectorizer.none(), alias="vectorizer_config" |
1156 | | - ) |
1157 | | - generativeSearch: Optional[_GenerativeProvider] = Field(default=None, alias="generative_config") |
1158 | | - rerankerConfig: Optional[_RerankerProvider] = Field(default=None, alias="reranker_config") |
1159 | | - |
1160 | | - def _to_dict(self) -> Dict[str, Any]: |
1161 | | - ret_dict: Dict[str, Any] = {} |
1162 | | - |
1163 | | - for cls_field in type(self).model_fields: |
1164 | | - val = getattr(self, cls_field) |
1165 | | - if cls_field in ["name", "model", "properties", "references"] or val is None: |
1166 | | - continue |
1167 | | - elif isinstance(val, (bool, float, str, int)): |
1168 | | - ret_dict[cls_field] = str(val) |
1169 | | - elif isinstance(val, _GenerativeProvider): |
1170 | | - self.__add_to_module_config(ret_dict, val.generative.value, val._to_dict()) |
1171 | | - elif isinstance(val, _RerankerProvider): |
1172 | | - self.__add_to_module_config(ret_dict, val.reranker.value, val._to_dict()) |
1173 | | - elif isinstance(val, _VectorizerConfigCreate): |
1174 | | - ret_dict["vectorizer"] = val.vectorizer.value |
1175 | | - if val.vectorizer != Vectorizers.NONE: |
1176 | | - self.__add_to_module_config(ret_dict, val.vectorizer.value, val._to_dict()) |
1177 | | - elif isinstance(val, _VectorIndexConfigCreate): |
1178 | | - ret_dict["vectorIndexType"] = val.vector_index_type() |
1179 | | - ret_dict[cls_field] = val._to_dict() |
1180 | | - else: |
1181 | | - assert isinstance(val, _ConfigCreateModel) |
1182 | | - ret_dict[cls_field] = val._to_dict() |
1183 | | - if self.vectorIndexConfig is None: |
1184 | | - ret_dict["vectorIndexType"] = VectorIndexType.HNSW.value |
1185 | | - return ret_dict |
1186 | | - |
1187 | | - @staticmethod |
1188 | | - def __add_to_module_config( |
1189 | | - return_dict: Dict[str, Any], addition_key: str, addition_val: Dict[str, Any] |
1190 | | - ) -> None: |
1191 | | - if "moduleConfig" not in return_dict: |
1192 | | - return_dict["moduleConfig"] = {addition_key: addition_val} |
1193 | | - else: |
1194 | | - return_dict["moduleConfig"][addition_key] = addition_val |
1195 | | - |
1196 | | - |
1197 | 1141 | class _CollectionConfigUpdate(_ConfigUpdateModel): |
1198 | 1142 | description: Optional[str] = Field(default=None) |
1199 | 1143 | property_descriptions: Optional[Dict[str, str]] = Field(default=None) |
@@ -1764,13 +1708,25 @@ def to_dict(self) -> Dict: |
1764 | 1708 | NamedVectorConfig = _NamedVectorConfig |
1765 | 1709 |
|
1766 | 1710 |
|
| 1711 | +@dataclass |
| 1712 | +class _ObjectTTLConfig(_ConfigBase): |
| 1713 | + enabled: bool |
| 1714 | + time_to_live: Optional[datetime.timedelta] |
| 1715 | + post_search_filter: bool |
| 1716 | + delete_on: Union[str, Literal["updateTime"], Literal["creationTime"]] |
| 1717 | + |
| 1718 | + |
| 1719 | +ObjectTTLConfig = _ObjectTTLConfig |
| 1720 | + |
| 1721 | + |
1767 | 1722 | @dataclass |
1768 | 1723 | class _CollectionConfig(_ConfigBase): |
1769 | 1724 | name: str |
1770 | 1725 | description: Optional[str] |
1771 | 1726 | generative_config: Optional[GenerativeConfig] |
1772 | 1727 | inverted_index_config: InvertedIndexConfig |
1773 | 1728 | multi_tenancy_config: MultiTenancyConfig |
| 1729 | + object_ttl_config: Optional[ObjectTTLConfig] |
1774 | 1730 | properties: List[PropertyConfig] |
1775 | 1731 | references: List[ReferencePropertyConfig] |
1776 | 1732 | replication_config: ReplicationConfig |
@@ -1841,6 +1797,7 @@ class _CollectionConfigSimple(_ConfigBase): |
1841 | 1797 | vectorizer_config: Optional[VectorizerConfig] |
1842 | 1798 | vectorizer: Optional[Union[Vectorizers, str]] |
1843 | 1799 | vector_config: Optional[Dict[str, _NamedVectorConfig]] |
| 1800 | + object_ttl_config: Optional[ObjectTTLConfig] |
1844 | 1801 |
|
1845 | 1802 |
|
1846 | 1803 | CollectionConfigSimple = _CollectionConfigSimple |
@@ -1992,6 +1949,7 @@ class _CollectionConfigCreate(_ConfigCreateModel): |
1992 | 1949 | multiTenancyConfig: Optional[_MultiTenancyConfigCreate] = Field( |
1993 | 1950 | default=None, alias="multi_tenancy_config" |
1994 | 1951 | ) |
| 1952 | + objectTtlConfig: Optional[_ObjectTTLCreate] = Field(default=None, alias="object_ttl_config") |
1995 | 1953 | replicationConfig: Optional[_ReplicationConfigCreate] = Field( |
1996 | 1954 | default=None, alias="replication_config" |
1997 | 1955 | ) |
@@ -2155,6 +2113,7 @@ class Configure: |
2155 | 2113 | NamedVectors = _NamedVectors |
2156 | 2114 | Vectors = _Vectors |
2157 | 2115 | MultiVectors = _MultiVectors |
| 2116 | + ObjectTTL = _ObjectTTL |
2158 | 2117 |
|
2159 | 2118 | @staticmethod |
2160 | 2119 | def inverted_index( |
|
0 commit comments