"""Bootstrap ingestion: index any documents found on disk that aren't already in ChromaDB. Runs at container startup. Safe to run repeatedly — `ingest_file` upserts by chunk hash. """ from __future__ import annotations from loguru import logger from app.core.config import settings from app.ingestion.pipeline import SUPPORTED_EXTS, ingest_file from app.rag.retriever import list_sources def main() -> None: docs_dir = settings.documents_dir docs_dir.mkdir(parents=True, exist_ok=True) files = sorted([p for p in docs_dir.iterdir() if p.suffix.lower() in SUPPORTED_EXTS]) if not files: logger.info("[bootstrap] no documents in {}, skipping", docs_dir) return indexed = {s["source_file"] for s in list_sources()} todo = [p for p in files if p.name not in indexed] if not todo: logger.info("[bootstrap] all {} files already indexed", len(files)) return logger.info("[bootstrap] indexing {} new files", len(todo)) for path in todo: try: ingest_file(path) except Exception as e: logger.error("[bootstrap] failed on {}: {}", path.name, e) if __name__ == "__main__": main()