[Feat] 기본 임베딩 모델 등록 및 조회 - #11
Conversation
📝 WalkthroughWalkthrough임베딩 모델의 생성 검증과 데이터베이스 제약, 활성 모델 조회 서비스 및 REST API가 추가되었습니다. 테스트 프로파일과 시드 데이터가 구성되었고, 위험한 Git push를 차단하는 Bash 훅과 프로젝트 작업 지침 문서가 추가되었습니다. Changes임베딩 모델 조회 API
개발 가이드와 명령 보호
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant EmbeddingModelController
participant EmbeddingModelQueryService
participant EmbeddingModelRepository
Client->>EmbeddingModelController: GET /api/embedding-models/active
EmbeddingModelController->>EmbeddingModelQueryService: getActiveModelResponse()
EmbeddingModelQueryService->>EmbeddingModelRepository: findAllByIsActiveTrueAndIsSearchableTrue()
EmbeddingModelRepository-->>EmbeddingModelQueryService: 활성·검색 가능 모델 목록
EmbeddingModelQueryService-->>EmbeddingModelController: EmbeddingModelResponse
EmbeddingModelController-->>Client: ApiResponse
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
AGENTS.md (1)
55-55: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value코드 블록 언어 명시
렌더링 품질 향상 및 정적 분석 도구의 경고 해결을 위해, 펜스 코드 블록에 적절한 언어(예:
text)를 명시하는 것이 좋습니다.🛠 제안하는 수정안
-``` +```text🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@AGENTS.md` at line 55, 문서의 언어 지정 없는 펜스 코드 블록을 찾아 내용에 맞는 언어 식별자를 추가하세요. 일반 텍스트 예시는 text를 사용하고, 기존 코드 블록 내용은 변경하지 마세요.Source: Linters/SAST tools
src/test/java/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryServiceTest.java (1)
58-61: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value메서드 참조를 사용하여 코드를 더 간결하게 작성하세요.
람다 표현식
() -> embeddingModelQueryService.getActiveModel()대신 메서드 참조를 사용하면 클린코드 관점에서 코드의 가독성을 높일 수 있습니다.
src/test/java/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryServiceTest.java#L58-L61:assertThatThrownBy(embeddingModelQueryService::getActiveModel)로 변경하세요.src/test/java/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryServiceTest.java#L71-L74: 동일하게assertThatThrownBy(embeddingModelQueryService::getActiveModel)로 변경하세요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryServiceTest.java` around lines 58 - 61, Replace the lambda passed to assertThatThrownBy with the embeddingModelQueryService::getActiveModel method reference in both affected sites: src/test/java/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryServiceTest.java lines 58-61 and 71-74. Preserve the existing exception type and errorCode assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.codex/hooks.json:
- Line 9: Update the hook command in the hooks configuration to remove the
hardcoded user-specific absolute path and invoke pre-bash.sh using a
project-root-relative path, preserving the existing hook script and bash
execution behavior.
In `@AGENTS.md`:
- Line 33: AGENTS.md의 상황별 룰 안내에서 경로 표기를 실제 구조인 .codex/hooks/로 통일하고, 문서 내 언어 미지정
코드 블록에는 bash 등 적절한 언어 식별자를 추가하세요.
In `@src/main/resources/db/migration/V27__add_embedding_model_constraints.sql`:
- Around line 2-3: Update the ck_embedding_models_dimension_positive CHECK
constraint definition to use the database’s NOT VALID option, deferring
validation and avoiding the initial full-table scan; leave constraint validation
to a separate future migration using VALIDATE CONSTRAINT.
- Around line 6-9: Update the uk_embedding_models_one_active_searchable index
creation to use PostgreSQL’s CONCURRENTLY option, and configure or split the
Flyway migration so this statement executes outside a transaction while
preserving the existing uniqueness and predicate.
---
Nitpick comments:
In `@AGENTS.md`:
- Line 55: 문서의 언어 지정 없는 펜스 코드 블록을 찾아 내용에 맞는 언어 식별자를 추가하세요. 일반 텍스트 예시는 text를
사용하고, 기존 코드 블록 내용은 변경하지 마세요.
In
`@src/test/java/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryServiceTest.java`:
- Around line 58-61: Replace the lambda passed to assertThatThrownBy with the
embeddingModelQueryService::getActiveModel method reference in both affected
sites:
src/test/java/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryServiceTest.java
lines 58-61 and 71-74. Preserve the existing exception type and errorCode
assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8ead191e-0d9e-4754-a98a-bbcb7270d443
📒 Files selected for processing (20)
.codex/hooks.json.codex/hooks/pre-bash.shAGENTS.mdsrc/main/java/com/opensource/docgrid/domain/embedding/controller/EmbeddingModelController.javasrc/main/java/com/opensource/docgrid/domain/embedding/converter/EmbeddingModelConverter.javasrc/main/java/com/opensource/docgrid/domain/embedding/dto/response/EmbeddingModelResponse.javasrc/main/java/com/opensource/docgrid/domain/embedding/entity/EmbeddingModel.javasrc/main/java/com/opensource/docgrid/domain/embedding/repository/EmbeddingModelRepository.javasrc/main/java/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryService.javasrc/main/java/com/opensource/docgrid/global/exception/ErrorCode.javasrc/main/resources/application-local.ymlsrc/main/resources/application-test.ymlsrc/main/resources/db/migration/V27__add_embedding_model_constraints.sqlsrc/main/resources/db/seed/R__seed_mock_embedding_model.sqlsrc/test/java/com/opensource/docgrid/DocgridApplicationTests.javasrc/test/java/com/opensource/docgrid/domain/embedding/controller/EmbeddingModelControllerTest.javasrc/test/java/com/opensource/docgrid/domain/embedding/entity/EmbeddingModelTest.javasrc/test/java/com/opensource/docgrid/domain/embedding/fixture/EmbeddingModelFixture.javasrc/test/java/com/opensource/docgrid/domain/embedding/repository/EmbeddingModelRepositoryTest.javasrc/test/java/com/opensource/docgrid/domain/embedding/service/query/EmbeddingModelQueryServiceTest.java
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": "bash '/Users/giminkim/IdeaProjects/backend/.codex/hooks/pre-bash.sh'" |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔴 Critical | ⚡ Quick win
절대 경로 사용 금지 및 상대 경로로 변경
환경에 종속적인 절대 경로가 하드코딩되어 있어, 다른 개발자의 로컬 환경이나 CI 파이프라인에서 훅이 정상적으로 실행되지 않고 실패합니다. 프로젝트 루트 기준의 상대 경로로 수정해야 합니다.
🛠 제안하는 수정안
- "command": "bash '/Users/giminkim/IdeaProjects/backend/.codex/hooks/pre-bash.sh'"
+ "command": "bash .codex/hooks/pre-bash.sh"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "command": "bash '/Users/giminkim/IdeaProjects/backend/.codex/hooks/pre-bash.sh'" | |
| "command": "bash .codex/hooks/pre-bash.sh" |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.codex/hooks.json at line 9, Update the hook command in the hooks
configuration to remove the hardcoded user-specific absolute path and invoke
pre-bash.sh using a project-root-relative path, preserving the existing hook
script and bash execution behavior.
| - 프로젝트 구조 → 이 파일 (AGENTS.md) | ||
| - 도메인 목록 → `src/main/java/com/opensource/docgrid/domain/` | ||
|
|
||
| ### 🟢 상황별 룰 (`.Codex/rules/`) — 자동 로드됨 |
There was a problem hiding this comment.
📐 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
경로 표기와 코드 블록 형식을 정리하세요
AGENTS.md:33의.Codex/rules/는 실제 경로인.codex/hooks/와 이름/대소문자가 다릅니다. 경로를 실제 구조에 맞게 통일해야 혼동을 줄일 수 있습니다.AGENTS.md:55의 코드 블록에는 언어 지정이 없어 lint 경고가 납니다.bash같은 식으로 붙여 주세요.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@AGENTS.md` at line 33, AGENTS.md의 상황별 룰 안내에서 경로 표기를 실제 구조인 .codex/hooks/로
통일하고, 문서 내 언어 미지정 코드 블록에는 bash 등 적절한 언어 식별자를 추가하세요.
| ADD CONSTRAINT ck_embedding_models_dimension_positive | ||
| CHECK (dimension > 0); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
운영 환경에서의 테이블 락(Lock) 방지를 위해 제약 조건 검증을 지연시키세요.
기본적으로 기존 테이블에 새로운 CHECK 제약 조건을 추가하면 전체 테이블 스캔이 발생하며 쓰기 작업이 차단됩니다. 테이블 락에 의한 성능 및 가용성 저하를 막기 위해 NOT VALID 옵션을 사용하여 제약 조건을 추가한 후, 향후 별도의 마이그레이션에서 VALIDATE CONSTRAINT를 수행하는 것을 권장합니다.
🛠 제안하는 수정안
ADD CONSTRAINT ck_embedding_models_dimension_positive
- CHECK (dimension > 0);
+ CHECK (dimension > 0) NOT VALID;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ADD CONSTRAINT ck_embedding_models_dimension_positive | |
| CHECK (dimension > 0); | |
| ADD CONSTRAINT ck_embedding_models_dimension_positive | |
| CHECK (dimension > 0) NOT VALID; |
🧰 Tools
🪛 Squawk (2.59.0)
[warning] 2-3: By default new constraints require a table scan and block writes to the table while that scan occurs. Use NOT VALID with a later VALIDATE CONSTRAINT call.
(constraint-missing-not-valid)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/resources/db/migration/V27__add_embedding_model_constraints.sql`
around lines 2 - 3, Update the ck_embedding_models_dimension_positive CHECK
constraint definition to use the database’s NOT VALID option, deferring
validation and avoiding the initial full-table scan; leave constraint validation
to a separate future migration using VALIDATE CONSTRAINT.
Source: Linters/SAST tools
| CREATE UNIQUE INDEX uk_embedding_models_one_active_searchable | ||
| ON embedding_models ((1)) | ||
| WHERE is_active = TRUE | ||
| AND is_searchable = TRUE; |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
운영 환경에서의 쓰기 작업 차단을 방지하기 위해 인덱스를 동시 생성(Concurrently)하세요.
일반적인 인덱스 생성은 완료될 때까지 테이블의 쓰기(Update/Insert/Delete) 작업을 차단합니다. 시스템 가용성을 유지하기 위해 CONCURRENTLY 키워드를 사용하는 것이 좋습니다.
단, PostgreSQL에서 CONCURRENTLY는 트랜잭션 블록 내에서 실행할 수 없으므로, Flyway 환경에서는 스크립트가 트랜잭션 외부에서 실행되도록 설정(예: Flyway 설정 조정 또는 마이그레이션 파일 분리)해야 할 수 있습니다.
🛠 제안하는 수정안
-CREATE UNIQUE INDEX uk_embedding_models_one_active_searchable
+CREATE UNIQUE INDEX CONCURRENTLY uk_embedding_models_one_active_searchable
ON embedding_models ((1))📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| CREATE UNIQUE INDEX uk_embedding_models_one_active_searchable | |
| ON embedding_models ((1)) | |
| WHERE is_active = TRUE | |
| AND is_searchable = TRUE; | |
| CREATE UNIQUE INDEX CONCURRENTLY uk_embedding_models_one_active_searchable | |
| ON embedding_models ((1)) | |
| WHERE is_active = TRUE | |
| AND is_searchable = TRUE; |
🧰 Tools
🪛 Squawk (2.59.0)
[warning] 6-9: During normal index creation, table updates are blocked, but reads are still allowed. Use concurrently to avoid blocking writes.
(require-concurrent-index-creation)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/resources/db/migration/V27__add_embedding_model_constraints.sql`
around lines 6 - 9, Update the uk_embedding_models_one_active_searchable index
creation to use PostgreSQL’s CONCURRENTLY option, and configure or split the
Flyway migration so this statement executes outside a transaction while
preserving the existing uniqueness and predicate.
Source: Linters/SAST tools
작업 내용
embedding_models의dimension > 0제약과 active+searchable 단일 모델 partial unique index를 추가했습니다.getActiveModel()과 외부 API용 DTO 조회를 분리했습니다.GET /api/embedding-models/active와 Swagger/OpenAPI 문서를 추가했습니다.ErrorCode및 HTTP 500 응답으로 처리했습니다.설계 배경
후속 문서 업로드 작업은 embedding job 생성 시점의 기본 모델 Entity를 조회해
embedding_model_id를 고정해야 합니다. Worker가 처리 중인 Job은 이후 기본 모델 설정 변경의 영향을 받지 않도록 내부 조회 메서드는 DTO가 아닌 Entity를 반환합니다.외부 API는 내부 설정인
configJson,vectorStorageStrategy, 활성 상태와 감사 필드를 노출하지 않고 공개 메타데이터 6개만 반환합니다.DB 및 Profile
CHECK, partial unique index,ON CONFLICT동작을 확인했습니다.db/seedFlyway location을 사용하며 prod에는 Mock Seed가 적용되지 않습니다.docgrid_test전용 스키마를 사용합니다.검증
./gradlew build/v3/api-docs에서 ApiResponse Wrapper, Enum, 두 HTTP 500 예시 확인Summary by CodeRabbit
새로운 기능
버그 수정 및 안정성
문서