[HSC-398] v1.1.0#60
Conversation
[HCR-369] 데이터 타입별 검색
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 PR은 애플리케이션의 유연성과 추천 시스템의 견고성을 향상시키는 데 중점을 둡니다. 특정 외부 라이브러리( Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
이번 PR에서는 pgvector와 aiokafka를 선택적 의존성으로 변경하여 유연성을 높이고, 추천 로직에서 상품 다양성을 확보하기 위한 타입별 후보 검색을 추가하셨네요. 특히 폴백 추천 로직에도 동일한 다양성 확보 로직을 적용하여 일관성을 유지한 점이 좋습니다. 다만, 이 과정에서 _run_recommendation_with_context와 _run_fallback_recommendation 함수에 중복되는 코드가 발생했습니다. 코드 유지보수성을 높이기 위해 이 중복 코드를 별도 함수로 추출하는 것을 제안합니다. 자세한 내용은 개별 코멘트를 참고해주세요.
| # 2-1) 타입별 검색으로 후보 풀 분산(최소 1개/타입 유도) | ||
| seen: set[int] = set() | ||
| product_ids: list[int] = [] | ||
| for ptype in MAIN_PRODUCT_TYPES: | ||
| r = await session.execute( | ||
| SEARCH_SIMILAR_BY_TYPE_SQL, | ||
| { | ||
| "query_vec": query_vec, | ||
| "exclude_ids": exclude_ids, | ||
| "k": RETRIEVAL_CANDIDATES_K, | ||
| "ptype": ptype, | ||
| "k": RETRIEVAL_PER_TYPE_K, | ||
| }, | ||
| ) | ||
| rows = result.fetchall() | ||
| product_ids = [r[0] for r in rows] | ||
| for row in r.fetchall(): | ||
| pid = row[0] | ||
| if pid in seen: | ||
| continue | ||
| product_ids.append(pid) | ||
| seen.add(pid) | ||
|
|
||
| # 2-2) 부족분은 기존 전체 검색(가중치 boost 포함 가능)으로 보충 | ||
| if len(product_ids) < RETRIEVAL_CANDIDATES_K: | ||
| if use_type_boost: | ||
| result = await session.execute( | ||
| SEARCH_SIMILAR_WITH_TYPE_BOOST_SQL, | ||
| { | ||
| "query_vec": query_vec, | ||
| "exclude_ids": exclude_ids, | ||
| "k": RETRIEVAL_CANDIDATES_K, | ||
| "boost_type1": boost_type1, | ||
| "boost1": boost1, | ||
| "boost_type2": boost_type2, | ||
| "boost2": boost2, | ||
| }, | ||
| ) | ||
| else: | ||
| result = await session.execute( | ||
| SEARCH_SIMILAR_SQL, | ||
| { | ||
| "query_vec": query_vec, | ||
| "exclude_ids": exclude_ids, | ||
| "k": RETRIEVAL_CANDIDATES_K, | ||
| }, | ||
| ) | ||
| for row in result.fetchall(): | ||
| pid = row[0] | ||
| if pid in seen: | ||
| continue | ||
| product_ids.append(pid) | ||
| seen.add(pid) | ||
| if len(product_ids) >= RETRIEVAL_CANDIDATES_K: | ||
| break |
There was a problem hiding this comment.
이 후보 상품 ID를 가져오는 로직은 _run_fallback_recommendation 함수 내의 1078-1114행에 있는 로직과 매우 유사합니다. 코드 중복은 향후 버그 발생 가능성을 높이고 유지보수를 어렵게 만듭니다.
이 중복된 로직을 별도의 헬퍼 함수로 추출하여 두 곳에서 모두 재사용하는 것을 고려해 보세요. 예를 들어, 다음과 같은 헬퍼 함수를 만들 수 있습니다.
async def _retrieve_candidate_products(
session: AsyncSession,
query_vec: list[float],
exclude_ids: list[int],
use_type_boost: bool = False,
boost_type1: str = "",
boost1: float = 0.0,
boost_type2: str = "",
boost2: float = 0.0,
) -> list[int]:
# ... 중복 로직 구현 ...
return product_ids이렇게 하면 _run_recommendation_with_context와 _run_fallback_recommendation 함수가 더 간결해지고, 추천 후보를 가져오는 로직을 한 곳에서 관리할 수 있게 됩니다.
📝작업 내용
👀변경 사항
🎫 Jira Ticket
#️⃣관련 이슈