-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathingest_rag_data.py
More file actions
40 lines (31 loc) · 1.2 KB
/
Copy pathingest_rag_data.py
File metadata and controls
40 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import argparse
import json
import logging
from pathlib import Path
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Ingest medical documents into the configured RAG backend."
)
source = parser.add_mutually_exclusive_group(required=True)
source.add_argument("--file", type=Path, help="Path to one document to ingest")
source.add_argument("--dir", type=Path, help="Directory of documents to ingest")
return parser
def run_ingestion(args: argparse.Namespace) -> dict:
# Keep optional RAG dependencies out of the CLI help path.
from agents.rag_agent import MedicalRAG
from config import Config
rag = MedicalRAG(Config())
if args.file is not None:
return rag.ingest_file(str(args.file))
return rag.ingest_directory(str(args.dir))
def main() -> int:
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
args = build_parser().parse_args()
result = run_ingestion(args)
print("Ingestion result:", json.dumps(result, indent=2))
return 0 if result.get("success") else 1
if __name__ == "__main__":
raise SystemExit(main())