-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] 기본 임베딩 모델 등록 및 조회 #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "hooks": { | ||
| "PreToolUse": [ | ||
| { | ||
| "matcher": "Bash", | ||
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": "bash '/Users/giminkim/IdeaProjects/backend/.codex/hooks/pre-bash.sh'" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
| INPUT=$(cat) | ||
| COMMAND=$(echo "$INPUT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('command',''))" 2>/dev/null || echo "") | ||
|
|
||
| # git push --force 차단 | ||
| if echo "$COMMAND" | grep -qE "git push.*(--force|-f\b)"; then | ||
| echo "🚫 git push --force 는 금지되어 있습니다." >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| # main 브랜치 직접 push 차단 | ||
| if echo "$COMMAND" | grep -qE "git push (origin )?main"; then | ||
| echo "🚫 main 브랜치 직접 push 는 금지되어 있습니다. PR을 통해 merge하세요." >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| exit 0 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # AGENTS.md — DocGrid | ||
|
|
||
| ## Engineering Guidelines | ||
|
|
||
| Don't assume. Don't hide confusion. Surface tradeoffs. | ||
|
|
||
| **Think Before Coding** | ||
| - State assumptions explicitly. If uncertain, ask. | ||
| - If multiple interpretations exist, present them — don't pick silently. | ||
| - For non-trivial tasks, start in Plan Mode and don't implement until approved. | ||
|
|
||
| **Simplicity First** | ||
| - Minimum code that solves the problem. Nothing speculative. | ||
| - No features beyond what was asked. No abstractions for single-use code. | ||
|
|
||
| **Surgical Changes** | ||
| - Touch only what you must. Don't "improve" adjacent code or formatting. | ||
| - Match existing style, even if you'd do it differently. | ||
| - Every changed line should trace directly to the user's request. | ||
|
|
||
| **Goal-Driven Execution** | ||
| - Define success criteria before starting. | ||
| - For multi-step tasks, state a brief plan and verify each step. | ||
|
|
||
| --- | ||
|
|
||
| ## 어디서 무엇을 읽을지 | ||
|
|
||
| ### 🔵 작업 직전 항상 | ||
| - 프로젝트 구조 → 이 파일 (AGENTS.md) | ||
| - 도메인 목록 → `src/main/java/com/opensource/docgrid/domain/` | ||
|
|
||
| ### 🟢 상황별 룰 (`.Codex/rules/`) — 자동 로드됨 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check the actual casing of the codex directory in the root.
ls -ld .[cC]odex 2>/dev/nullRepository: DocGrid/backend Length of output: 209 🏁 Script executed: sed -n '1,120p' AGENTS.md | cat -nRepository: DocGrid/backend Length of output: 3196 🏁 Script executed: find .codex -maxdepth 3 -type d -o -type f | sortRepository: DocGrid/backend Length of output: 216 경로 표기와 코드 블록 형식을 정리하세요
🤖 Prompt for AI Agents |
||
| - Java 코드 작성 시 → `code_style.md` | ||
| - 테스트 작성/수정 시 → `testing_guide.md` | ||
| - Security/Config 만질 때 → `security.md` | ||
| - 배포/Docker/GitHub Actions 관련 → `deploy.md` | ||
|
|
||
| ### 🟣 AI 작업 흔적 (`.dev/`) | ||
| - 새로 알게 된 패턴·주의점·오류 기록 → `learnings/` | ||
| - 작업 중 임시 메모 (작업 종료 후 삭제 — 비어있는 게 정상) → `scratchpad/` | ||
|
|
||
| --- | ||
|
|
||
| ## 프로젝트 개요 | ||
|
|
||
| - **Framework**: Spring Boot 3.5.16 | ||
| - **Language**: Java 17 | ||
| - **Build**: Gradle | ||
| - **DB**: PostgreSQL + Flyway | ||
| - **Package**: `com.opensource.docgrid` | ||
|
|
||
| ## 프로젝트 구조 | ||
|
|
||
| ``` | ||
| src/main/java/com/opensource/docgrid/ | ||
| ├── global/ | ||
| │ ├── common/ # 공통 응답 (ApiResponse, ErrorResponse, BaseEntity) | ||
| │ ├── config/ # 설정 (SecurityConfig, CorsConfig, SwaggerConfig) | ||
| │ └── exception/ # 전역 예외 (DocGridException, ErrorCode, GlobalExceptionHandler) | ||
| └── domain/ | ||
| └── {도메인}/ | ||
| ├── entity/ | ||
| ├── repository/ | ||
| ├── service/ | ||
| │ ├── command/ # 상태 변경 | ||
| │ └── query/ # 조회 전용 | ||
| ├── controller/ | ||
| ├── dto/ | ||
| │ ├── request/ | ||
| │ └── response/ | ||
| ├── converter/ # Entity ↔ DTO 변환 | ||
| └── enums/ | ||
| ``` | ||
|
|
||
| ## 주요 명령어 | ||
|
|
||
| ```bash | ||
| ./gradlew build | ||
| ./gradlew clean build | ||
| ./gradlew build -x test | ||
| ./gradlew test | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 영구 금지 | ||
|
|
||
| - `git add -A` / `git add .` (민감 파일 우회 위험) | ||
| - `git push --force` / `--no-verify` / `--amend` (안전장치 우회) | ||
| - `main` 브랜치 직접 push — PR + 리뷰 후 merge만 허용 | ||
| - 시크릿을 `application.yml`에 하드코딩 | ||
| - Entity를 Controller 계층에 직접 노출 | ||
74 changes: 74 additions & 0 deletions
74
...ain/java/com/opensource/docgrid/domain/embedding/controller/EmbeddingModelController.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package com.opensource.docgrid.domain.embedding.controller; | ||
|
|
||
| import org.springframework.http.MediaType; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.opensource.docgrid.domain.embedding.dto.response.EmbeddingModelResponse; | ||
| import com.opensource.docgrid.domain.embedding.service.query.EmbeddingModelQueryService; | ||
| import com.opensource.docgrid.global.common.response.ApiResponse; | ||
| import com.opensource.docgrid.global.common.response.ErrorResponse; | ||
| import com.opensource.docgrid.global.common.response.ResponseUtils; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Tag( | ||
| name = "Embedding Model", | ||
| description = "문서 인덱싱과 검색에서 사용할 임베딩 모델 설정 조회 API" | ||
| ) | ||
| @RestController | ||
| @RequestMapping("/api/embedding-models") | ||
| @RequiredArgsConstructor | ||
| public class EmbeddingModelController { | ||
|
|
||
| private final EmbeddingModelQueryService embeddingModelQueryService; | ||
|
|
||
| @Operation( | ||
| summary = "기본 임베딩 모델 조회", | ||
| description = """ | ||
| is_active=true, is_searchable=true인 기본 임베딩 모델을 조회합니다. | ||
| 신규 embedding_job 생성 시 사용할 모델 설정이며, 정상적으로 하나만 존재해야 합니다. | ||
| 모델이 없거나 여러 개 존재하면 서버 설정 오류가 발생합니다. | ||
| 실제 Vector를 생성하거나 임베딩 모델을 실행하지 않습니다. | ||
| """ | ||
| ) | ||
| @ApiResponses({ | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "200", | ||
| description = "기본 임베딩 모델 조회 성공" | ||
| ), | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse( | ||
| responseCode = "500", | ||
| description = "기본 임베딩 모델 설정 오류", | ||
| content = @Content( | ||
| schema = @Schema(implementation = ErrorResponse.class), | ||
| examples = { | ||
| @ExampleObject( | ||
| name = "모델 미설정", | ||
| value = """ | ||
| {"success":false,"status":500,"code":"EMBEDDING-MODEL-001","message":"사용 가능한 임베딩 모델이 설정되지 않았습니다.","method":"GET","path":"/api/embedding-models/active","timestamp":"2026-07-14 12:00:00"} | ||
| """ | ||
| ), | ||
| @ExampleObject( | ||
| name = "모델 중복 설정", | ||
| value = """ | ||
| {"success":false,"status":500,"code":"EMBEDDING-MODEL-002","message":"사용 가능한 임베딩 모델이 여러 개 설정되어 있습니다.","method":"GET","path":"/api/embedding-models/active","timestamp":"2026-07-14 12:00:00"} | ||
| """ | ||
| ) | ||
| } | ||
| ) | ||
| ) | ||
| }) | ||
| @GetMapping(value = "/active", produces = MediaType.APPLICATION_JSON_VALUE) | ||
| public ResponseEntity<ApiResponse<EmbeddingModelResponse>> getActiveModel() { | ||
| return ResponseUtils.ok(embeddingModelQueryService.getActiveModelResponse()); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/opensource/docgrid/domain/embedding/converter/EmbeddingModelConverter.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.opensource.docgrid.domain.embedding.converter; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.opensource.docgrid.domain.embedding.dto.response.EmbeddingModelResponse; | ||
| import com.opensource.docgrid.domain.embedding.entity.EmbeddingModel; | ||
|
|
||
| @Component | ||
| public class EmbeddingModelConverter { | ||
|
|
||
| public EmbeddingModelResponse toResponse(EmbeddingModel embeddingModel) { | ||
| return new EmbeddingModelResponse( | ||
| embeddingModel.getId(), | ||
| embeddingModel.getProvider(), | ||
| embeddingModel.getModelName(), | ||
| embeddingModel.getModelVersion(), | ||
| embeddingModel.getDimension(), | ||
| embeddingModel.getDistanceMetric() | ||
| ); | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
...ain/java/com/opensource/docgrid/domain/embedding/dto/response/EmbeddingModelResponse.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.opensource.docgrid.domain.embedding.dto.response; | ||
|
|
||
| import com.opensource.docgrid.domain.embedding.enums.DistanceMetric; | ||
| import com.opensource.docgrid.domain.embedding.enums.EmbeddingProvider; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record EmbeddingModelResponse( | ||
| @Schema(description = "임베딩 모델 식별자", example = "1") | ||
| Long id, | ||
|
|
||
| @Schema(description = "모델 제공 또는 실행 방식", example = "MOCK") | ||
| EmbeddingProvider provider, | ||
|
|
||
| @Schema(description = "모델 이름", example = "mock-bge-m3") | ||
| String modelName, | ||
|
|
||
| @Schema(description = "모델 버전 또는 Revision", example = "v1") | ||
| String modelVersion, | ||
|
|
||
| @Schema(description = "모델이 생성하는 Vector 차원", example = "1024") | ||
| int dimension, | ||
|
|
||
| @Schema(description = "Vector 유사도 계산 방식", example = "COSINE") | ||
| DistanceMetric distanceMetric | ||
| ) { | ||
| } |
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
20 changes: 20 additions & 0 deletions
20
...ain/java/com/opensource/docgrid/domain/embedding/repository/EmbeddingModelRepository.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.opensource.docgrid.domain.embedding.repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import com.opensource.docgrid.domain.embedding.entity.EmbeddingModel; | ||
| import com.opensource.docgrid.domain.embedding.enums.EmbeddingProvider; | ||
|
|
||
| public interface EmbeddingModelRepository extends JpaRepository<EmbeddingModel, Long> { | ||
|
|
||
| // 다중 기본 모델 설정을 숨기지 않고 서비스에서 개수를 검증할 수 있도록 List로 반환한다. | ||
| List<EmbeddingModel> findAllByIsActiveTrueAndIsSearchableTrue(); | ||
|
|
||
| boolean existsByProviderAndModelNameAndModelVersion( | ||
| EmbeddingProvider provider, | ||
| String modelName, | ||
| String modelVersion | ||
| ); | ||
| } |
48 changes: 48 additions & 0 deletions
48
...ava/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryService.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.opensource.docgrid.domain.embedding.service.query; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.opensource.docgrid.domain.embedding.converter.EmbeddingModelConverter; | ||
| import com.opensource.docgrid.domain.embedding.dto.response.EmbeddingModelResponse; | ||
| import com.opensource.docgrid.domain.embedding.entity.EmbeddingModel; | ||
| import com.opensource.docgrid.domain.embedding.repository.EmbeddingModelRepository; | ||
| import com.opensource.docgrid.global.exception.DocGridException; | ||
| import com.opensource.docgrid.global.exception.ErrorCode; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class EmbeddingModelQueryService { | ||
|
|
||
| private final EmbeddingModelRepository embeddingModelRepository; | ||
| private final EmbeddingModelConverter embeddingModelConverter; | ||
|
|
||
| // 후속 embedding_jobs 생성 시 모델 Entity를 연관관계에 고정하기 위한 내부 조회 메서드다. | ||
| public EmbeddingModel getActiveModel() { | ||
| List<EmbeddingModel> activeModels = | ||
| embeddingModelRepository.findAllByIsActiveTrueAndIsSearchableTrue(); | ||
|
|
||
| if (activeModels.isEmpty()) { | ||
| log.error("사용 가능한 임베딩 모델이 설정되지 않았습니다."); | ||
| throw new DocGridException(ErrorCode.EMBEDDING_MODEL_NOT_CONFIGURED); | ||
| } | ||
|
|
||
| if (activeModels.size() > 1) { | ||
| log.error("사용 가능한 임베딩 모델이 여러 개 설정되어 있습니다. count={}", activeModels.size()); | ||
| throw new DocGridException(ErrorCode.MULTIPLE_ACTIVE_EMBEDDING_MODELS); | ||
| } | ||
|
|
||
| return activeModels.get(0); | ||
| } | ||
|
|
||
| public EmbeddingModelResponse getActiveModelResponse() { | ||
| return embeddingModelConverter.toResponse(getActiveModel()); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔴 Critical | ⚡ Quick win
절대 경로 사용 금지 및 상대 경로로 변경
환경에 종속적인 절대 경로가 하드코딩되어 있어, 다른 개발자의 로컬 환경이나 CI 파이프라인에서 훅이 정상적으로 실행되지 않고 실패합니다. 프로젝트 루트 기준의 상대 경로로 수정해야 합니다.
🛠 제안하는 수정안
📝 Committable suggestion
🤖 Prompt for AI Agents