feat(lps): AI 유사도 판정 — '같은 상품' 매칭으로 액세서리 오염 해결
파이프라인의 비워둔 슬롯(이상치 뒤·top-N 앞)에 OpenAI 유사도 판정을 결합. "스탠리 텀블러" 검색 시 빨대마개·커버 등 호환 액세서리가 최저가로 올라오던 문제를 해결한다(기계적 최저가 → 같은 상품 최저가). - ai/similarity: SimilarityJudge(OpenAI structured output). 액세서리/부품/다른규격 불일치 판별 - pipeline/core: apply_filters + rank_result 로 분리(AI 를 그 사이에 끼움), run_price_pipeline 동작 불변 - handler: judge 주입 시 ai_match STAGE 추가(필터 후 후보만 판정 → 토큰 절약), 미주입 시 생략 - worker_main: OPENAI_API_KEY 있으면 판정 ON - requirements: openai / tests: fake judge 필터링 검증 → 전체 32/32 - 라이브: '스탠리 퀜처 887ml' → ai_match(60→15) → 실제 텀블러 top-6(액세서리 제거) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9557c1b1af
commit
b0a86b9720
6 files changed
+175
-47
No files matched your search
@@ -56,3 +56,24 @@ async def test_all_sources_fail_raises():
|
||||
}
|
||||
with pytest.raises(RuntimeError):
|
||||
await build_search_handler(adapters)(_job())
|
||||
|
||||
|
||||
class FakeJudge:
|
||||
"""가격 조건으로 매칭을 흉내내는 판정기(실제 OpenAI 호출 없음)."""
|
||||
|
||||
def __init__(self, predicate):
|
||||
self._pred = predicate
|
||||
|
||||
async def judge(self, target, candidates):
|
||||
from services.ai.similarity import Judgment
|
||||
return [Judgment(index=i + 1, is_match=self._pred(c), score=100 if self._pred(c) else 0)
|
||||
for i, c in enumerate(candidates)]
|
||||
|
||||
|
||||
async def test_ai_judge_filters_non_matches():
|
||||
adapters = {"naver": FakeAdapter("naver", [_np("naver", 1000), _np("naver", 2000), _np("naver", 3000)])}
|
||||
judge = FakeJudge(lambda c: c.price == 2000) # 2000 만 '같은 상품'
|
||||
r = await build_search_handler(adapters, judge=judge)(_job())
|
||||
assert [p["price"] for p in r["top"]] == [2000] # 비매칭 제거됨
|
||||
ai_stage = next(s for s in r["stages"] if s["stage"] == "ai_match")
|
||||
assert ai_stage["in"] == 3 and ai_stage["out"] == 1
|
||||
Reference in new issue
Block a user