Spaces:
Sleeping
Sleeping
Download scripts/bootstrap.py from QDB95/qdb-knowledge-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/QDB95/qdb-knowledge-bot/resolve/main/scripts/bootstrap.py
- Command line
-
hf download hf://spaces/QDB95/qdb-knowledge-bot/scripts/bootstrap.py
-
curl -L -o bootstrap.py https://huggingface.co/spaces/QDB95/qdb-knowledge-bot/resolve/main/scripts/bootstrap.py
1.19 kB
| """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() | |