fix(insta-lab): ranked가 judge에 보낼 후보를 상위 30개로 cap

미사용 키워드 대량 누적 시 judge 프롬프트/응답이 토큰 한도를 넘어 파싱 실패→claude 신호 전부 null로 degrade되던 문제(프로덕션 확인됨) 해결. base score 상위 JUDGE_CANDIDATE_CAP(30)개만 judge·선별에 적용해 claude 신호 일관 보장.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-11 03:07:29 +09:00
parent e1b1944f43
commit c62e3e70b9
2 changed files with 34 additions and 0 deletions

View File

@@ -153,6 +153,11 @@ def list_keywords(
return {"items": db.list_trending_keywords(category=category, used=used)}
# judge(Claude)에 보낼 최대 후보 수 — 미사용 키워드 대량 누적 시 응답 truncation으로
# claude 점수가 전부 null로 degrade되는 것을 방지 (base score 상위 N개만 평가).
JUDGE_CANDIDATE_CAP = 30
@app.get("/api/insta/keywords/ranked")
def ranked_keywords(
limit: int = Query(20, ge=1, le=100),
@@ -162,6 +167,10 @@ def ranked_keywords(
candidates = db.list_trending_keywords(used=False)
if not candidates:
return {"items": []}
# base score 상위 JUDGE_CANDIDATE_CAP개로 제한 → judge·선별 동일 집합에 적용(claude 신호 일관)
candidates = sorted(
candidates, key=lambda c: float(c.get("score", 0.0)), reverse=True
)[:JUDGE_CANDIDATE_CAP]
issued = db.list_recent_issued_topics(window_days=dedup_window_days)
prefs = {p["category"]: p["weight"] for p in db.get_preferences()}
claude_scores = selection_judge.judge_candidates(candidates)