Spaces:
Sleeping
Sleeping
| """ | |
| Convenience script to ingest all sample documents in data/samples/. | |
| Usage: | |
| python scripts/ingest_samples.py | |
| """ | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).parents[1])) | |
| from app.pipeline.rag_pipeline import build_pipeline | |
| def main(): | |
| samples_dir = Path(__file__).parents[1] / "data" / "samples" | |
| if not samples_dir.exists(): | |
| print(f"Samples directory not found: {samples_dir}") | |
| sys.exit(1) | |
| files = list(samples_dir.glob("*")) | |
| if not files: | |
| print("No files found in data/samples/") | |
| sys.exit(1) | |
| print(f"Found {len(files)} sample file(s):") | |
| for f in files: | |
| print(f" - {f.name}") | |
| print("\nBuilding pipeline…") | |
| pipeline = build_pipeline() | |
| def progress(label, cur, total): | |
| pct = int(cur / max(total, 1) * 100) | |
| print(f"\r [{pct:3d}%] {label:<50}", end="", flush=True) | |
| stored = pipeline.ingest(files, progress_callback=progress) | |
| print(f"\n\nDone! Stored {stored} chunks.") | |
| print(f"Total in DB: {pipeline.document_count}") | |
| if __name__ == "__main__": | |
| main() | |