Skip to content

Commit f2950f8

Browse files
committed
latest
1 parent dae6c1e commit f2950f8

File tree

5 files changed

+77
-49
lines changed

5 files changed

+77
-49
lines changed

back/src/main/java/com/back/global/ai/bootstrap/SeedOrchestrator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.concurrent.atomic.AtomicLong;
2121

2222
@Component
23-
@Profile("prod")
23+
@Profile({"test","prod"})
2424
@RequiredArgsConstructor
2525
public class SeedOrchestrator {
2626

back/src/main/resources/db/migration/V8__add_seed_theme.sql

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* 이 파일은 pgvector 기반 실서비스용 스키마를 생성한다.
3+
* 흐름: 확장 활성화 → age_theme(제약/인덱스) → vocab_term(제약/인덱스) → ANALYZE
4+
*/
5+
6+
-- 확장 활성화
7+
CREATE EXTENSION IF NOT EXISTS vector;
8+
9+
-- age_theme 테이블 생성
10+
CREATE TABLE IF NOT EXISTS age_theme (
11+
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
12+
min_age INT NOT NULL,
13+
max_age INT NOT NULL,
14+
category VARCHAR(32) NOT NULL
15+
CHECK (category IN ('EDUCATION','CAREER','RELATIONSHIP','FINANCE','HEALTH','LOCATION','ETC')),
16+
theme TEXT NOT NULL,
17+
embedding VECTOR(768) NOT NULL,
18+
-- 무결성 검증
19+
CHECK (min_age >= 0 AND max_age >= min_age)
20+
);
21+
22+
-- 범주/연령대 필터 인덱스
23+
CREATE INDEX IF NOT EXISTS idx_age_theme_cat_age
24+
ON age_theme(category, min_age, max_age);
25+
26+
-- 코사인 KNN 인덱스(운영 저사양 고려 ivfflat 사용)
27+
CREATE INDEX IF NOT EXISTS idx_age_theme_embedding_ivfflat
28+
ON age_theme USING ivfflat (embedding vector_cosine_ops)
29+
WITH (lists = 50);
30+
31+
-- vocab_term 테이블 생성(용어 유니크)
32+
CREATE TABLE IF NOT EXISTS vocab_term (
33+
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
34+
term VARCHAR(128) NOT NULL UNIQUE,
35+
embedding VECTOR(768) NOT NULL
36+
);
37+
38+
-- 코사인 KNN 인덱스
39+
CREATE INDEX IF NOT EXISTS idx_vocab_term_embedding_ivfflat
40+
ON vocab_term USING ivfflat (embedding vector_cosine_ops)
41+
WITH (lists = 50);
42+
43+
-- 통계 수집(IVFFLAT 생성 후 권장)
44+
ANALYZE age_theme;
45+
ANALYZE vocab_term;
46+
47+
/*
48+
-- 무결성 검증
49+
-- HNSW를 쓰고 싶다면 아래로 교체(메모리 여유 필요, PG ≥ 16 권장)
50+
-- CREATE INDEX IF NOT EXISTS idx_age_theme_embedding_hnsw
51+
-- ON age_theme USING hnsw (embedding vector_cosine_ops);
52+
-- CREATE INDEX IF NOT EXISTS idx_vocab_term_embedding_hnsw
53+
-- ON vocab_term USING hnsw (embedding vector_cosine_ops);
54+
*/

back/src/test/java/com/back/domain/node/controller/DecisionFlowControllerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ void success_createNextDecision() throws Exception {
266266
.content(nextReq))
267267
.andExpect(status().isCreated())
268268
.andExpect(jsonPath("$.parentId").value(parentId))
269-
.andExpect(jsonPath("$.aiNextSituation").value("테스트-상황(한 문장)"))
270-
.andExpect(jsonPath("$.aiNextRecommendedOption").value("테스트-추천"))
269+
.andExpect(jsonPath("$.aiNextSituation").value("테스트-상황이다."))
270+
.andExpect(jsonPath("$.aiNextRecommendedOption").value("테스트-추천한다"))
271271
.andReturn();
272272

273273
JsonNode body = om.readTree(res.getResponse().getContentAsString());
@@ -732,8 +732,8 @@ void success_aiHints_persisted_and_mapped_on_line_detail() throws Exception {
732732
assertThat(childNode2.path("aiNextRecommendedOption").asText()).isNotBlank();
733733

734734
// (테스트 더미 AI 고정값을 사용하는 환경이면 아래 주석 해제해서 정확 값까지 검증 가능)
735-
assertThat(childNode2.path("aiNextSituation").asText()).isEqualTo("테스트-상황(한 문장)");
736-
assertThat(childNode2.path("aiNextRecommendedOption").asText()).isEqualTo("테스트-추천");
735+
assertThat(childNode2.path("aiNextSituation").asText()).isEqualTo("테스트-상황이다.");
736+
assertThat(childNode2.path("aiNextRecommendedOption").asText()).isEqualTo("테스트-추천한다");
737737
}
738738

739739
@Nested

back/src/test/resources/sql/init_vector.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,21 @@
22
-- 1) pgvector 확장을 설치한다.
33
-- 2) Hibernate가 이후에 vector(768) 컬럼을 포함한 테이블을 생성할 수 있게 준비한다.
44
CREATE EXTENSION IF NOT EXISTS vector;
5+
6+
-- age_theme 테이블
7+
CREATE TABLE IF NOT EXISTS age_theme (
8+
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
9+
min_age INT NOT NULL,
10+
max_age INT NOT NULL,
11+
category VARCHAR(32) NOT NULL,
12+
theme TEXT NOT NULL,
13+
embedding BYTEA NULL,
14+
CHECK (min_age >= 0 AND max_age >= min_age)
15+
);
16+
17+
-- vocab_term 테이블
18+
CREATE TABLE IF NOT EXISTS vocab_term (
19+
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
20+
term VARCHAR(128) NOT NULL UNIQUE,
21+
embedding BYTEA NULL
22+
);

0 commit comments

Comments
 (0)