From 1ee73a89020346fdec3300b783f51035a3a1f462 Mon Sep 17 00:00:00 2001 From: balabanovan530 <175+balabanovan530@noreply.localhost> Date: Thu, 28 May 2026 12:29:24 +0000 Subject: [PATCH] Add init_loader.py --- init_loader.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 init_loader.py diff --git a/init_loader.py b/init_loader.py new file mode 100644 index 0000000..39f79be --- /dev/null +++ b/init_loader.py @@ -0,0 +1,32 @@ +"""Script to load documents from a directory into the vector store.""" + +import os +from pathlib import Path + +from .vector_store import VectorStore +from .splitter import chunk_text + + +def load_documents(directory: str, store: VectorStore | None = None) -> int: + """Load all text files from *directory* into the vector store. + + Returns the number of documents added. + """ + if store is None: + store = VectorStore() + count = 0 + for path in Path(directory).rglob("*.txt"): + content = path.read_text(encoding="utf-8") + chunks = chunk_text(content) + store.add_documents(chunks) + count += 1 + return count + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser(description="Load documents into the RAG vector store.") + parser.add_argument("directory", help="Path to directory containing .txt files") + args = parser.parse_args() + added = load_documents(args.directory) + print(f"Loaded {added} documents into the vector store.") \ No newline at end of file