""" دستور CLI برای ساخت index پایگاه دانش. """ from pathlib import Path from django.core.management.base import BaseCommand from knowledge_base.rag_settings import RAGConfig from knowledge_base.indexer import build_index class Command(BaseCommand): help = "ساخت/بازسازی پایگاه دانش RAG از sensor_data، soil_data و فایل لحن" def add_arguments(self, parser): parser.add_argument( "--config", type=str, default="config/rag_config.yaml", help="مسیر فایل config یامل (پیش‌فرض: config/rag_config.yaml)", ) def handle(self, *args, **options): config_path = options["config"] path = Path(config_path) if not path.is_absolute(): path = Path.cwd() / config_path if not path.exists(): self.stderr.write( self.style.ERROR(f"فایل config یافت نشد: {path}") ) self.stderr.write( "یک فایل config از روی config/rag_config.yaml بسازید یا از config/rag_config.example.yaml کپی کنید." ) return self.stdout.write("در حال بارگذاری config...") config = RAGConfig.load(path) self.stdout.write("در حال تولید chunks از soil_data و sensor_data...") count = build_index(config) self.stdout.write( self.style.SUCCESS(f"پایگاه دانش با {count} سند ساخته شد.") )