From 1b444ace2086c34dbf3207dcd1002f522ee58669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Thu, 4 Jun 2026 20:02:38 +0000 Subject: [PATCH] Add init_loader.py --- init_loader.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 init_loader.py 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