Skip to content

Commit 4d166ad

Browse files
committed
if no docs for rag found switch to non-rag mode
1 parent 921bca4 commit 4d166ad

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def main():
188188
if not rag_path.is_dir():
189189
console.print(f"[bold red]Error: RAG path is not a directory: {args.rag_dir}[/]")
190190
sys.exit(1)
191-
191+
192192
try:
193193
index, store = build_or_load(
194194
rag_path,
@@ -198,6 +198,12 @@ def main():
198198
args.debug,
199199
args.embed_batch_size,
200200
)
201+
# If no documents found, switch to non-RAG mode
202+
if index is None:
203+
console.print(
204+
"[yellow]📄 Switching to non-RAG mode due to no documents found.[/]"
205+
)
206+
index, store = None, {}
201207
except RuntimeError as e:
202208
console.print(f"[bold red]Error: {e}[/]")
203209
sys.exit(1)

rag.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def build_or_load(
159159
rebuild: bool,
160160
debug: bool,
161161
batch_size: int = 32,
162-
) -> Tuple[Any, Dict[str, Any]]:
162+
) -> Tuple[Any | None, Dict[str, Any]]:
163163
"""Build or load FAISS index and document store"""
164164
# Save index files in the target directory
165165
db_path = root / "faiss_index.bin"
@@ -189,8 +189,8 @@ def build_or_load(
189189
docs = scan_docs(root)
190190

191191
if not docs:
192-
console.print("[bold red]💀 No documents found![/bold red]")
193-
raise RuntimeError("No documents found")
192+
console.print("[bold yellow]⚠️ No documents found in directory![/bold yellow]")
193+
return None, {}
194194

195195
chunks: List[str] = []
196196
meta: List[Dict[str, str]] = []

0 commit comments

Comments
 (0)