From 9d77175ac8bf0421a726d8a1eb53d00b779bc90d Mon Sep 17 00:00:00 2001 From: Andy Lee Date: Tue, 29 Jul 2025 15:55:46 -0700 Subject: [PATCH] fix: Fix issues in unified examples - Add smart path detection for data directory - Fix add_texts -> add_text method call - Handle both running from project root and examples directory --- examples/base_rag_example.py | 3 ++- examples/document_rag.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/base_rag_example.py b/examples/base_rag_example.py index 84cb957..5f9d81f 100644 --- a/examples/base_rag_example.py +++ b/examples/base_rag_example.py @@ -164,7 +164,8 @@ class BaseRAGExample(ABC): batch_size = 1000 for i in range(0, len(texts), batch_size): batch = texts[i : i + batch_size] - builder.add_texts(batch) + for text in batch: + builder.add_text(text) print(f"Added {min(i + batch_size, len(texts))}/{len(texts)} texts...") print("Building index structure...") diff --git a/examples/document_rag.py b/examples/document_rag.py index 3497698..d32b0da 100644 --- a/examples/document_rag.py +++ b/examples/document_rag.py @@ -26,11 +26,17 @@ class DocumentRAG(BaseRAGExample): def _add_specific_arguments(self, parser): """Add document-specific arguments.""" doc_group = parser.add_argument_group("Document Parameters") + + # Smart default path detection + default_data_dir = Path("examples/data") + if not default_data_dir.exists() and Path("data").exists(): + default_data_dir = Path("data") + doc_group.add_argument( "--data-dir", type=str, - default="examples/data", - help="Directory containing documents to index (default: examples/data)", + default=str(default_data_dir), + help=f"Directory containing documents to index (default: {default_data_dir})", ) doc_group.add_argument( "--file-types",