import os from pymilvus import connections from pymilvus import Collection from datetime import date def get_min_age_to_delete(): BASE_DATE = date(2024, 1, 1) today = date.today() timedelta = today - BASE_DATE return timedelta.days - 30 # 30 days means deleting articles older than a month def get_secrets(): uri = os.environ.get("URI") token = os.environ.get("TOKEN") collection_name = os.environ.get("COLLECTION_NAME") return uri, token, collection_name def get_collection(uri: str, token: str, collection_name: str): connections.connect("default", uri=uri, token=token) collection = Collection(name=collection_name) print("Loaded existing collection") return collection def delete_from_db(): uri, token, collection_name = get_secrets() collection = get_collection(uri, token, collection_name) min_age_to_delete = get_min_age_to_delete() expr = f"article_age <= {min_age_to_delete}" collection.delete(expr) print('Successfully deleted older articles')