diff --git a/300_architecture/database/tables.md b/300_architecture/database/tables.md index bd22ab8..ccde12e 100644 --- a/300_architecture/database/tables.md +++ b/300_architecture/database/tables.md @@ -304,15 +304,74 @@ --- +--- + +## 7. 감정 분석 테이블 (robeing_metrics DB) + +### emotion_readings +- **용도**: 사용자 및 로빙 감정 분석 시계열 데이터 +- **데이터베이스**: robeing_metrics (TimescaleDB) +- **특징**: 시계열 하이퍼테이블, Top-p 기반 복합 감정 저장 + +| 컬럼명 | 타입 | NULL | 기본값 | 설명 | +|--------|------|------|--------|------| +| created_at | TIMESTAMPTZ | NO | | 분석 시각 (파티션 키) | +| user_id | UUID | YES | | 사용자 ID (user 테이블 참조) | +| company_id | UUID | YES | | 회사 ID | +| robeing_id | VARCHAR(50) | YES | | 로빙 ID | +| emotion_type | VARCHAR(20) | YES | | 'user' 또는 'robeing' | +| probs | JSONB | NO | | 7개 감정 확률 분포 | +| entropy | DOUBLE PRECISION | YES | | 감정 엔트로피 값 | +| model_version | VARCHAR(50) | YES | | 모델 버전 (예: onnx-7emotions-v1) | +| meta | JSONB | YES | | 메타데이터 (source, message_length 등) | +| text_hash | VARCHAR(64) | YES | | 텍스트 SHA256 해시 | +| top_emotions | JSONB | YES | | Top-p 복합 감정 배열 [{"label", "probability"}] | +| cumulative_p | DOUBLE PRECISION | YES | | 누적 확률 (Top-p 70%) | + +**인덱스**: +- `emotion_readings_created_at_idx`: btree (created_at DESC) +- `idx_emotion_user_time`: btree (user_id, created_at DESC) +- `idx_emotion_company_time`: btree (company_id, created_at DESC) +- `idx_emotion_robeing_time`: btree (robeing_id, created_at DESC) +- `idx_emotion_type`: btree (emotion_type, created_at DESC) + +**제약 조건**: +- `emotion_readings_emotion_type_check`: emotion_type IN ('user', 'robeing') + +**트리거**: +- `ts_insert_blocker`: TimescaleDB 하이퍼테이블 삽입 제어 + +**예시 데이터**: +```json +{ + "top_emotions": [ + {"label": "fear", "probability": 0.499}, + {"label": "neutral", "probability": 0.335} + ], + "cumulative_p": 0.833, + "probs": { + "fear": 0.499, "neutral": 0.335, "anger": 0.056, + "sadness": 0.048, "disgust": 0.032, "surprise": 0.018, "happiness": 0.012 + }, + "entropy": 1.234 +} +``` + +--- + ## 주의사항 ### 데이터베이스 정보 -- **소유자**: 모든 테이블 robeings 소유 +- **main_db**: 주요 서비스 데이터 (PostgreSQL) + - 소유자: robeings + - 테이블: user, team, robeing, conversation_log 등 +- **robeing_metrics**: 시계열 메트릭 데이터 (TimescaleDB) + - 테이블: emotion_readings + - 특징: 시간 기반 파티셔닝, 자동 압축, retention 정책 - **타임스탬프**: TIMESTAMPTZ 사용 (WITH TIME ZONE) - **자동 갱신**: update_column_updated_at 트리거로 updated_at 자동 관리 - **UUID 기반**: 주요 테이블 모두 UUID 사용 - --- **문서 끝** \ No newline at end of file