Wolf-Chat-for-Lastwar/memory_backup.py
z060142 48c0c25a42 Extend ChromaDB memory system with scheduled tasks and Setup UI support
- Added new scripts to manage ChromaDB memory processing and periodic scheduling (e.g. compaction, deduplication, reindexing).
- Optimized chatbot memory usage by improving base memory retrieval logic and preload strategy.
- Updated Setup.py UI to include scheduling options for memory maintenance tasks.
- Ensures better long-term memory performance, avoids memory bloat, and enables proactive management of large-scale memory datasets.
2025-05-08 03:08:51 +08:00

43 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Wolf Chat 記憶備份工具
用於手動執行記憶備份或啟動定時調度器
"""
import sys
import argparse
import datetime
from memory_manager import run_memory_backup_manual, MemoryScheduler # Updated import
import config # Import config to access default schedule times
def main():
parser = argparse.ArgumentParser(description='Wolf Chat 記憶備份工具')
parser.add_argument('--backup', action='store_true', help='執行一次性備份 (預設為昨天,除非指定 --date)')
parser.add_argument('--date', type=str, help='處理指定日期的日誌 (YYYY-MM-DD格式) for --backup')
parser.add_argument('--schedule', action='store_true', help='啟動定時調度器')
parser.add_argument('--hour', type=int, help='備份時間小時0-23for --schedule')
parser.add_argument('--minute', type=int, help='備份時間分鐘0-59for --schedule')
args = parser.parse_args()
if args.backup:
# The date logic is now handled inside run_memory_backup_manual
run_memory_backup_manual(args.date)
elif args.schedule:
scheduler = MemoryScheduler()
# Use provided hour/minute or fallback to config defaults
backup_hour = args.hour if args.hour is not None else getattr(config, 'MEMORY_BACKUP_HOUR', 0)
backup_minute = args.minute if args.minute is not None else getattr(config, 'MEMORY_BACKUP_MINUTE', 0)
scheduler.schedule_daily_backup(backup_hour, backup_minute)
scheduler.start()
else:
print("請指定操作: --backup 或 --schedule")
parser.print_help()
sys.exit(1)
if __name__ == "__main__":
main()