Files

21 lines
784 B
Python

import sys
from pathlib import Path
from rag_agent import add_to_knowledge_base
def load_docs_from_dir(directory: str):
for file_path in Path(directory).rglob("*"):
if file_path.is_file() and file_path.suffix.lower() in {".txt", ".md", ".pdf"}:
try:
content = file_path.read_text(encoding="utf-8", errors="ignore")
except Exception as e:
print(f"Failed to read {file_path}: {e}")
continue
title = file_path.stem
result = add_to_knowledge_base(content, title)
print(f"Loaded {file_path}: {result}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python load_docs.py <directory>")
sys.exit(1)
load_docs_from_dir(sys.argv[1])