"""카테고리 소프트 부스트 가중치 그리드 — 엔진 1회 로드, 여러 weight 측정.""" import sys, os, json from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent)) sys.stdout.reconfigure(encoding="utf-8") os.environ.setdefault("LLM_BACKEND", "openai") import warnings; warnings.filterwarnings("ignore") import logging; logging.disable(logging.CRITICAL) import core.search_engine as se from core.agent import run_agent BIX = Path(__file__).parent.parent.parent / "BIX_메뉴검색_20260624" / "BIX_회귀_통합.json" cases = json.loads(BIX.read_text(encoding="utf-8"))["confirmed_failures"] # 시장 케이스(해외 명시) vs 의도 케이스 분류 (라벨용) MARKET = {"REG-002","REG-003","REG-004","REG-017","REG-018","REG-019","REG-020"} INTENT = {"REG-007","REG-008","REG-009","REG-010","REG-011","REG-012"} def run_once(use_hyde): passed, market_ok, intent_ok, fails = 0, 0, 0, [] for c in cases: r = run_agent(query=c["query"], top_n=3, use_hyde=use_hyde, use_reranker=False) hits = r.get("search_results", []) top1 = hits[0]["menu_id"] if hits else "" ok = top1 in set(c.get("expected_menu_ids", [])) cid = c["regression_case_id"] if ok: passed += 1 if cid in MARKET: market_ok += 1 if cid in INTENT: intent_ok += 1 else: fails.append(cid) return passed, market_ok, intent_ok, fails configs = [ ("하드필터(기준)", False, None), ("소프트 w=0.02", True, 0.02), ("소프트 w=0.01", True, 0.01), ("소프트 w=0.005", True, 0.005), ("소프트 w=0.0", True, 0.0), ] print(f"{'설정':16} | 통과 | 시장{len(MARKET)} | 의도{len(INTENT)} | 실패목록") print("-"*80) for label, soft, w in configs: se.CATEGORY_SOFT_FILTER = soft if w is not None: se.CATEGORY_SOFT_BOOST_WEIGHT = w p, m, i, fails = run_once(use_hyde=False) print(f"{label:16} | {p:2}/29 | {m:2}/{len(MARKET)} | {i:2}/{len(INTENT)} | {','.join(fails)}")