OpenAI 임베딩 + Qdrant 업서트 파이프라인 적용기 (Spring Boot, JDK 21)

송현진·2025년 9월 22일
0

프로젝트 회고

목록 보기
21/22
  • EmbeddingService로 OpenAI 임베딩 생성(캐시 + 429 재시도 + dummy 모드 지원)
  • ProductVectorService가 상품 텍스트를 벡터화 → Qdrant 컬렉션 보증 → 업서트
  • 저장 시점에 도메인 이벤트(ProductCreatedEvent) 발행 → (향후) 비동기 인덱싱으로 전환 예정
  • 차원/거리 지표 일관성, 예외/운영 지점까지 정리

배경

문자열 매칭만으로는 “무드등 vs 분위기 조명” 같은 의미적 유사를 잡기 어렵다. 추천 품질을 높이기 위해 임베딩 + 벡터 검색을 도입.
1차 목표는 간단하고 확실하게 E2E 파이프라인을 세우는 것: “상품 텍스트 → 임베딩 → Qdrant 업서트 → 검색 준비”.

목표

  1. 상품 단건 기준 임베딩 생성 → Qdrant 업서트 서비스화
  2. 컬렉션이 없으면 자동 생성(차원/거리 지표 일치)
  3. 운영성: 캐시로 중복 호출 방지, 429 재시도(지수 백오프), 더미 모드 제공
  4. 저장 로직과 느슨히 결합: 도메인 이벤트로 후속 작업 분리 기반 마련

구성도

sequenceDiagram
    participant API/Service
    participant Embedding as EmbeddingService
    participant Qdrant as QdrantClient
    participant Repo as CrawlingProductRepository

    API/Service->>Repo: findById(productId)
    Repo-->>API/Service: CrawlingProduct
    API/Service->>API/Service: buildEmbeddingText(product)
    API/Service->>Embedding: embed(text)
    Embedding-->>API/Service: List<Float> (dim=1536)
    API/Service->>Qdrant: ensureCollection(collection, dim, "Cosine")
    API/Service->>Qdrant: upsertPoint(collection, pointId, vector, payload)
    API/Service->>Repo: p.markEmbedding(pointId, model, true)
    API/Service-->>API/Service: log done

환경설정

Gradle

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-webflux" // (Qdrant REST 구현 시)
    implementation "org.springframework.boot:spring-boot-starter-validation"

    // OpenAI Java
    implementation 'com.openai:openai-java-spring-boot-starter:3.6.0'
}
profile
개발자가 되고 싶은 취준생

0개의 댓글