feat(retrieval): 요청 카테고리 존중 + 카테고리 다양성 (#40)#59
Merged
Conversation
시연 중 '여드름 스킨/토너 추천'에 토너가 하나도 안 나오고 LLM이 '토너
카테고리가 없다'고 잘못 답하는 문제. 실제로는 토너 301개(여드름 성분 3개+
매칭 37개)가 있으나, 제품 쿼리가 relevance_score 정렬 후 LIMIT 5만 반환해
고가중 성분 많은 앰플/세럼이 상위를 독식 → 토너가 밀려남.
- _requested_categories(): 메시지에서 포맷 요청 추출('스킨'=토너, 단
스킨케어/스킨타입 등 합성어는 오탐 제외)
- _appropriate_categories(): 요청 카테고리 우선 존중(concern 적합과 교집합,
비면 요청 그대로)
- _diversify(): 요청 없을 때 후보 풀(limit=30)에서 카테고리당 상한을 둬
한 포맷 독식 방지, 부족하면 랭킹순 보충
- query_products_by_ingredients: limit 파라미터화(LIMIT $limit)
- config: product_result_limit=6
- 동기·스트리밍 중복 로직을 select_products()로 통합
- tests: 카테고리 감지 오탐/다양성/상한 12케이스
recommend_service.py가 import하는 이 파일이 워킹트리에만 있고 커밋된 적이 없어(a5d44b5에서 import만 머지됨) fresh checkout(CI) 시 ModuleNotFoundError로 recommend_service 전체 import가 실패. eval-gate '생성 eval' 스텝이 이 때문에 크래시. 참조하는 config 설정(product_image_*, aws_*)은 이미 커밋돼 있어 파일만 추가하면 복구됨.
품질 회귀 게이트✅ PASS — 품질 게이트 통과 추출 품질 (run_eval)
생성 품질 (LLM-judge)
검색 품질 (RAG precision)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
배경 (시연 중 발견)
LLM의 잘못된 보고였다. 실제로 그래프엔 토너 301개, 여드름 성분(상위10) 3개+ 매칭 토너만 37개 존재.
원인
query_products_by_ingredients가 전체를 relevance_score(성분 가중합)로 정렬 후 **LIMIT 5**만 반환.앰플/세럼이 고가중 성분(나이아신아마이드+레티놀 등)을 더 많이 담아 상위 5개를 독식 → 토너가 6등 밖으로 밀림 → LLM엔 앰플만 전달됨.
핵심 갭 2개:
해결 (둘 다)
_requested_categories()로 메시지에서 포맷 추출('스킨'=토너, 단스킨케어/스킨타입/스킨톤/스킨십합성어는 오탐 제외)._appropriate_categories(concerns, requested)가 요청을 우선 존중(concern 적합과 교집합, 비면 요청 그대로).limit=30)에서_diversify(per_category=2, total=6)로 한 포맷 상위 독식 방지, 부족하면 랭킹순 보충.select_products()로 통합.query_products_by_ingredients에limit파라미터화,config.product_result_limit=6.검증 (라이브 :8000)
오탐 단위 확인:
스킨타입·스킨케어→ 미감지 ✅,미백 세럼→ {세럼} ✅.유닛테스트 12 passed, 기존 테스트 회귀 없음. 정밀도(#56 목적필터)는 뒤에서 그대로 동작.
변경 파일
app/services/recommend_service.py—_requested_categories,_appropriate_categories(시그니처 확장),_diversify,select_productsapp/clients/neo4j_client.py—LIMIT $limitapp/core/config.py—product_result_limittests/test_product_selection.py— 신규 12케이스