Docent-AI-ChatBot / ingest_all.py
Abdullah0327's picture
Initial clean LFS commit
35fbb15
Raw History Blame Contribute Delete
1.36 kB
"""
Bulk pre-ingestion script.
Usage:
1. Copy all your PDF files into the documents/ folder.
2. Run from the project root:
python ingest_all.py
The script embeds every PDF and saves the FAISS index to vector_db/.
You only need to run this once (or whenever you add a new batch of PDFs).
The server loads the saved index automatically on startup.
"""
import sys
from pathlib import Path
# Allow importing from backend/
sys.path.insert(0, str(Path(__file__).parent / "backend"))
from ingest import ingest_pdf, DOCUMENTS_PATH, VECTOR_DB_PATH
def main():
pdfs = sorted(DOCUMENTS_PATH.glob("*.pdf"))
if not pdfs:
print(f"No PDF files found in {DOCUMENTS_PATH} ")
print("Copy your PDFs there and run this script again.")
return
print(f"Found {len(pdfs)} PDF(s) to ingest.\n")
total_chunks = 0
for i, pdf in enumerate(pdfs, 1):
print(f"[{i}/{len(pdfs)}] Ingesting: {pdf.name} ...", end=" ", flush=True)
try:
chunks = ingest_pdf(str(pdf))
total_chunks += chunks
print(f"{chunks} chunks")
except Exception as e:
print(f"ERROR — {e}")
print(f"\nDone. {total_chunks} total chunks saved to {VECTOR_DB_PATH} ")
print("Start the server and the index will be loaded automatically.")
if __name__ == "__main__":
main()