feat(regulatory): 增加本地法规RAG索引检索

This commit is contained in:
2026-06-07 00:30:53 +08:00
parent 2a4dd6cfab
commit 26490f7c46
7 changed files with 411 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
from __future__ import annotations
from pathlib import Path
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from review_agent.regulatory_review.services.rag_embedding import get_embedding_provider
from review_agent.regulatory_review.services.rag_index import build_chroma_index
from review_agent.regulatory_review.services.rule_loader import load_rule_file
class Command(BaseCommand):
help = "构建 NMPA 法规材料本地 ChromaDB RAG 索引。"
def add_arguments(self, parser):
parser.add_argument("--provider", default=None, help="覆盖 REGULATORY_RAG_PROVIDER。")
def handle(self, *args, **options):
rule_set = load_rule_file()
source_dir = Path(settings.BASE_DIR) / rule_set["source_material_dir"]
if not source_dir.exists():
raise CommandError(f"法规材料目录不存在:{source_dir}")
try:
provider = get_embedding_provider(options["provider"])
count = build_chroma_index(source_dir=source_dir, embedding_provider=provider)
except Exception as exc:
raise CommandError(str(exc)) from exc
self.stdout.write(
self.style.SUCCESS(
f"已构建法规 RAG 索引collection={settings.REGULATORY_RAG_COLLECTION}, chunks={count}"
)
)