diff --git a/init_loader.py b/init_loader.py new file mode 100644 index 0000000..b637d8a --- /dev/null +++ b/init_loader.py @@ -0,0 +1,37 @@ +""" +Load documents from a directory into the Qdrant knowledge base. +""" + +import argparse +from pathlib import Path + +from vector_store import add_document + +def load_documents_from_dir(directory: str, title_prefix: str = "") -> None: + """Recursively load all text files from *directory* and add them to the store. + + Parameters + ---------- + directory: str + Path to the directory containing documents. + title_prefix: str, optional + Prefix to add to each document title (useful when loading many files). + """ + dir_path = Path(directory) + if not dir_path.is_dir(): + raise ValueError(f"{directory} is not a valid directory") + + for file_path in dir_path.rglob("*.txt"): + with file_path.open("r", encoding="utf-8") as f: + content = f.read() + title = f"{title_prefix}{file_path.stem}" + add_document(content, title) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Load documents into the knowledge base") + parser.add_argument("directory", help="Directory with .txt files") + parser.add_argument("--prefix", default="", help="Optional title prefix") + args = parser.parse_args() + + load_documents_from_dir(args.directory, args.prefix) + print("Loading completed.") \ No newline at end of file