File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
back/src/main/resources/db/migration Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ -- ==============================================
2+ -- pgvector 기반 node_snippet 테이블 생성
3+ -- ==============================================
4+
5+ -- 1. pgvector extension 활성화
6+ -- 이미 활성화 되어 있을 수 있으므로 IF NOT EXISTS 사용
7+ CREATE EXTENSION IF NOT EXISTS vector;
8+
9+ -- 2. node_snippet 테이블 생성
10+ CREATE TABLE IF NOT EXISTS node_snippet (
11+ id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY ,
12+ line_id BIGINT NOT NULL ,
13+ age_year INT NOT NULL ,
14+ category VARCHAR (50 ),
15+ text TEXT NOT NULL ,
16+ embedding VECTOR(768 ) NOT NULL
17+ );
18+
19+ -- 3. 검색 성능을 위한 인덱스 생성
20+ CREATE INDEX IF NOT EXISTS idx_node_snippet_line_age
21+ ON node_snippet(line_id, age_year);
22+
23+ -- 코사인 거리 기반 KNN 인덱스 생성
24+ -- hnsw 인덱스 성능이 좋지만 db.t3.micro 상 메모리 문제로 인해 ivfflat 사용
25+ CREATE INDEX IF NOT EXISTS idx_node_snippet_embedding_ivfflat
26+ ON node_snippet USING ivfflat (embedding vector_cosine_ops)
27+ WITH (lists = 50 )
You can’t perform that action at this time.
0 commit comments