Skip to content

[HCR-235] 추천 api + 상품 임베딩 #20

Merged
tkv00 merged 5 commits into
devfrom
feat/HSC-235
Mar 9, 2026
Merged

[HCR-235] 추천 api + 상품 임베딩 #20
tkv00 merged 5 commits into
devfrom
feat/HSC-235

Conversation

@rettooo

@rettooo rettooo commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

📝작업 내용

  • 회원 프로필 기반(초기) 상품 추천 api 추가
  • pgvector 유사도 검색 + openai로 추천 이유 생성 (AsyncOpenAI)

👀변경 사항

api: POST /api/v1/recommendations (member_id, profile_text)

서비스: 프로필 임베딩 -> product 벡터 유사도 top k -> llm 추천 이유 생성

설정

Docker


🎫 Jira Ticket

  • Jira Ticket: HCR-235

#️⃣관련 이슈

@github-actions github-actions Bot added Customer Team ✨ feat 새로운 기능 추가, 기존 기능을 요구 사항에 맞추어 수정 🔥 priority: P0 즉시 처리 필요(서비스/데모 블로커) 🗂️ area: BE 백엔드 영역 labels Mar 9, 2026
@github-actions github-actions Bot changed the title Feat/hsc 235 [HCR-235] Feat/hsc 235 Mar 9, 2026
@rettooo rettooo changed the title [HCR-235] Feat/hsc 235 추천 api + 상품 임베딩 Mar 9, 2026
@rettooo rettooo requested review from YeongHyeonHeo and tkv00 March 9, 2026 04:09
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, 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은 사용자 프로필을 기반으로 상품을 추천하는 새로운 기능을 도입합니다. 이는 pgvector를 사용하여 상품 벡터 유사도를 검색하고, OpenAI의 대규모 언어 모델을 활용하여 각 추천 상품에 대한 설명을 생성함으로써 이루어집니다. 이로써 개인화된 상품 추천 경험을 제공하고, 추천 시스템의 확장성을 확보합니다.

Highlights

  • 회원 프로필 기반 상품 추천 API 추가: 사용자 프로필 텍스트를 기반으로 상품을 추천하는 새로운 API 엔드포인트가 구현되었습니다.
  • PGVector 및 OpenAI 통합: PGVector를 활용한 상품 벡터 유사도 검색과 AsyncOpenAI를 이용한 추천 이유 생성이 핵심 로직에 통합되었습니다.
  • 환경 설정 및 데이터베이스 연결 개선: OpenAI API 키, 모델, 데이터베이스 URL 등 추천 시스템 관련 환경 변수가 추가되었고, PGVector를 지원하는 비동기 데이터베이스 연결 설정이 도입되었습니다.
  • 상품 임베딩 파이프라인 스크립트 추가: 상품 데이터를 정규화하고 임베딩 텍스트를 생성하며, 이를 OpenAI API로 벡터화하여 데이터베이스에 저장하는 스크립트가 추가되었습니다.
Changelog
  • .env.example
    • OpenAI API 키, 모델, 데이터베이스 URL 등 추천 시스템 관련 환경 변수가 추가되었습니다.
  • .gitignore
    • Python 관련 빌드 파일, 환경 파일, 로그 파일 등 무시할 파일 목록이 확장되었습니다.
  • .husky/pre-commit
    • pnpm test를 실행하는 pre-commit 훅이 추가되었습니다.
  • Dockerfile
    • build-essential 및 python3-dev와 같은 C 확장 빌드에 필요한 패키지를 설치하고 정리하는 로직이 추가되어 pip install 과정이 개선되었습니다.
  • README.md
    • 파일 상단에 '하이'라는 텍스트가 추가되었습니다.
  • app/api/router.py
    • 새로운 추천 API 라우터(app.api.v1.recommendation)가 메인 API 라우터에 포함되었습니다.
  • app/api/v1/recommendation.py
    • 회원 ID와 프로필 텍스트를 받아 상품 추천을 반환하는 POST /recommendations 엔드포인트가 추가되었습니다.
  • app/core/config.py
    • 데이터베이스, OpenAI, 추천 관련 설정(예: database_url, openai_api_key, recommend_top_k)이 Settings 클래스에 추가되었고, 환경 파일 로딩 로직이 개선되었습니다.
  • app/core/database.py
    • 비동기 PostgreSQL 연결을 위한 AsyncEngine, AsyncSession 설정 및 pgvector 확장을 등록하는 로직이 추가되었습니다.
  • app/main.py
    • 루트 엔드포인트(GET /)가 앱 이름, 문서 경로, 헬스 체크 경로를 반환하도록 수정되었습니다.
  • app/schemas/recommendation.py
    • 추천 요청(RecommendationRequest) 및 응답(RecommendationResponse), 추천 상품 항목(RecommendedProductItem)에 대한 Pydantic 스키마가 정의되었습니다.
  • app/services/recommendation_service.py
    • OpenAI 임베딩을 사용하여 프로필 텍스트의 벡터를 생성하고, pgvector를 통해 유사한 상품을 검색하며, OpenAI Chat 모델로 추천 이유를 생성하는 핵심 추천 로직이 구현되었습니다.
  • docker-compose.local.yaml
    • 로컬 개발 환경에서 앱을 실행하기 위한 Docker Compose 설정 파일이 추가되었습니다.
  • package.json
    • test 스크립트가 'No tests'를 출력하도록 변경되었고, husky 개발 의존성이 추가되었습니다.
  • pnpm-lock.yaml
    • husky 패키지에 대한 pnpm 잠금 파일이 추가되었습니다.
  • requirements.txt
    • langchain, openai, sqlalchemy[asyncio], pgvector 등 새로운 Python 라이브러리 의존성이 추가되었습니다.
  • scripts/embed_products.py
    • Postgres에서 상품 데이터를 정규화하고, tag_strategy.csv를 기반으로 태그 컨텍스트를 주입하며, 임베딩 텍스트를 생성하여 DB에 업데이트하는 스크립트가 추가되었습니다.
  • scripts/embed_vectors.py
    • embedding_text를 사용하여 OpenAI 임베딩 API를 호출하고, 반환된 벡터를 product.embedding_vector 필드에 업데이트하는 스크립트가 추가되었습니다.
  • scripts/tag_strategy.csv
    • 상품 태그에 대한 전략(대상 고객, 마케팅 메시지, 업셀 포인트 등)을 정의하는 CSV 파일이 추가되었습니다.
Activity
  • 이 풀 리퀘스트에는 아직 활동이 없습니다.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@rettooo rettooo changed the title 추천 api + 상품 임베딩 [HCR-235] 추천 api + 상품 임베딩 Mar 9, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR introduces a profile-based product recommendation API and a product embedding pipeline, utilizing OpenAI and pgvector for the new recommendation service. A critical prompt injection vulnerability was identified in the recommendation reason generation logic, where user-provided profile text is directly concatenated into the LLM prompt without sufficient sanitization or structural isolation. This must be addressed to ensure the reliability and safety of the LLM-generated content. Furthermore, the database update logic in the embedding script needs performance improvement, and dependency management should be made more stable. Please refer to specific file comments for detailed feedback.

Comment thread requirements.txt Outdated
Comment thread scripts/embed_products.py Outdated
Comment thread scripts/embed_vectors.py Outdated
Comment thread app/services/recommendation_service.py
Comment thread README.md
Comment thread app/core/config.py Outdated
Comment thread app/core/config.py
Comment thread app/services/recommendation_service.py Outdated
Comment thread app/services/recommendation_service.py Outdated
Comment thread scripts/embed_vectors.py Outdated

@tkv00 tkv00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다~

@tkv00 tkv00 merged commit eddb690 into dev Mar 9, 2026
1 check passed
@tkv00 tkv00 deleted the feat/HSC-235 branch March 20, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🗂️ area: BE 백엔드 영역 Customer Team ✨ feat 새로운 기능 추가, 기존 기능을 요구 사항에 맞추어 수정 🔥 priority: P0 즉시 처리 필요(서비스/데모 블로커)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HSC-235] recommendation server 합치기

2 participants