import time import os from app.core.index import faiss_index from app.core.config import settings def watch_and_reload(interval=600): print("[HOT-RELOAD] Watching index file for updates...") last_mtime = None while True: try: mtime = os.path.getmtime(settings.INDEX_FILE) if last_mtime is None: last_mtime = mtime elif mtime != last_mtime: print("[HOT-RELOAD] Detected new index file. Reloading...") faiss_index.update_index(settings.INDEX_FILE) last_mtime = mtime except Exception as e: print(f"[HOT-RELOAD] Error: {e}") time.sleep(interval) if __name__ == "__main__": watch_and_reload()