From 76ed2786f3f12ce912291d79bbe27e998ea94232 Mon Sep 17 00:00:00 2001 From: Claude-51124 Date: Tue, 27 Jan 2026 10:44:34 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20=EA=B3=84=ED=9A=8D=20=EB=AC=B8=EC=84=9C?= =?UTF-8?q?=20=EC=9B=90=EC=B9=99=20=EC=A4=80=EC=88=98=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 251017: 완료 섹션 간소화, 상세 내용 제거, 남은 작업만 기록 - 251023: 상세 구현 내용 제거, Phase별 필요 작업만 기록 - 251225: DB 스키마 상세 SQL 제거, 테이블 구조만 요약, Phase별 필요 작업만 기록 - 원칙 준수: 구현 완료 섹션 삭제, troubleshooting 링크만, 아키텍처/Phase/필요작업만 --- ...251017_intent_analysis_improvement_plan.md | 34 ++------ ...드_임베딩_베이지안_동적학습.md | 34 ++------ ...251225_프롬프트_동적관리_계획.md | 83 +++++++------------ 3 files changed, 46 insertions(+), 105 deletions(-) diff --git a/journey/plans/251017_intent_analysis_improvement_plan.md b/journey/plans/251017_intent_analysis_improvement_plan.md index 4800996..3c8fcf6 100644 --- a/journey/plans/251017_intent_analysis_improvement_plan.md +++ b/journey/plans/251017_intent_analysis_improvement_plan.md @@ -1,30 +1,19 @@ # 로빙 의도 파악 개선 플랜 **날짜**: 2025-10-17 -**현재**: 정규식 패턴 매칭만 사용 +**상태**: 부분 완료 (3단계 아키텍처 완료, 하이브리드 시스템 미구현) --- -## 현재 문제 - -### 처리 불가 사례 -| 질문 | 현재 처리 | 문제 | -|------|----------|------| -| "오늘 몇일이야?" | UNKNOWN | 시간 질문 패턴 없음 | -| "리버스마운틴 유사 기업 가치평가해줘" | UNKNOWN | 복잡한 멀티스텝 질문 | -| "아까 말한 그 기업 투자 단계는?" | UNKNOWN | 맥락 참조 불가 | - -**결론**: 단순 명령만 처리 가능, 복합 질문 처리 불가 - ---- - -## 구현 완료 (3단계 구조) +## Phase 1: 3단계 아키텍처 (✅ 완료) → 상세: `troubleshooting/251126_happybell80_rb8001_의도_3단계_아키텍처_도입_및_배포.md` --- -## ⏳ 미구현: 하이브리드 시스템 +## 남은 작업 + +### 하이브리드 시스템 구현 **구조**: 1. 정규식 FastPath (명확한 패턴) → conf ≥ 0.9 즉시 결정 @@ -32,15 +21,8 @@ 3. LLM 제로샷 분류 → conf < 0.5 시 CLARIFY **필요 작업**: - -**1. SemanticIntentClassifier 구현** -- 파일: `app/services/brain/semantic_classifier.py` -- intent_prototypes 테이블 활용 -- 임베딩 유사도로 Top-3 후보 선택 - -**2. LLM 폴백** -- Top-3 후보를 LLM에 전달 -- 확신도 < 0.5 시 CLARIFY +- SemanticIntentClassifier 구현: `app/services/brain/semantic_classifier.py`, intent_prototypes 테이블 활용, 임베딩 유사도로 Top-3 후보 선택 +- LLM 폴백: Top-3 후보를 LLM에 전달, 확신도 < 0.5 시 CLARIFY --- @@ -48,4 +30,4 @@ - `troubleshooting/251126_happybell80_rb8001_의도_3단계_아키텍처_도입_및_배포.md` - `troubleshooting/251126_intent_3step_db_bayesian_integration.md` -- `311_FastAPI_구조_원칙.md` +- `book/300_architecture/311_백엔드_구조_원칙.md` diff --git a/journey/plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md b/journey/plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md index 623878d..18c3797 100644 --- a/journey/plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md +++ b/journey/plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md @@ -2,6 +2,7 @@ **날짜**: 2025-10-23 **목표**: 임베딩 + 베이지안 + 동적학습 통합 의도 파악 시스템 +**상태**: 미구현 --- @@ -13,39 +14,20 @@ FastPath + 임베딩 Top-K + LLM 재분석 + Beta(α,β) 동적 임계치 하이 ## Phase 1: 하이브리드 파이프라인 -**파일**: `rb8001/app/services/brain/intent_graph.py` (신규) -- FastPath: 정규식 + Naive Bayes, conf ≥ 0.9 즉시 결정 -- SemanticIntentClassifier: intent 설명/예시 벡터와 코사인 유사도, Top-K 후보 선택 -- LLM 재분석: Top-K만 JSON 스키마로 결정, conf < τ는 clarify +**필요 작업**: +- `rb8001/app/services/brain/intent_graph.py` (신규): FastPath + SemanticIntentClassifier + LLM 재분석 파이프라인 +- `rb8001/app/services/brain/semantic_classifier.py` (신규): intent_prototypes 테이블 활용, 임베딩 유사도로 Top-K 후보 선택 +- `rb8001/app/services/llm/intent_parser.py` (신규): LLM JSON 파서 -**파일**: `rb8001/app/services/brain/semantic_classifier.py` (신규) -- intent_prototypes 테이블 활용 -- 임베딩 유사도로 Top-3 후보 선택 - -**파일**: `rb8001/app/services/llm/intent_parser.py` (신규) -- LLM JSON 파서 +--- ## Phase 2: 베이지안 동적 학습 -**파일**: `rb8001/app/state/repositories/intent_decision_repository.py` (신규) -- `intent_decision_log` 테이블 생성 +**필요 작업**: +- `rb8001/app/state/repositories/intent_decision_repository.py` (신규): intent_decision_log 테이블 생성 - 의도/경로별 성공률 추적 (Beta(α,β)) - Thompson Sampling으로 임계치 τ 동적 최적화 -**DB 스키마**: -```sql -CREATE TABLE intent_decision_log ( - user_id UUID, - message TEXT, - candidates JSONB, - chosen TEXT, - path TEXT, - success BOOLEAN, - latency_ms INT, - timestamp TIMESTAMPTZ -); -``` - --- ## 참고 diff --git a/journey/plans/251225_프롬프트_동적관리_계획.md b/journey/plans/251225_프롬프트_동적관리_계획.md index 8920925..d60d1ae 100644 --- a/journey/plans/251225_프롬프트_동적관리_계획.md +++ b/journey/plans/251225_프롬프트_동적관리_계획.md @@ -2,8 +2,7 @@ **날짜**: 2025-12-25 **작성자**: happybell80 -**관련 파일**: `rb8001/app/services/llm/gemini_handler.py`, `rb8001/app/services/llm/llm_service.py` -**상태**: 📋 계획 단계 +**상태**: 미구현 --- @@ -11,77 +10,55 @@ 프롬프트 DB화를 통한 동적 변경 및 개인화 구현 +--- + ## DB 스키마 설계 -```sql -CREATE TABLE prompt_templates ( - id UUID PRIMARY KEY, - scope_level VARCHAR(20) NOT NULL, -- 'global', 'robeing', 'user', 'task' - scope_id VARCHAR(255), -- robeing_id, user_id, task_type 등 - prompt_type VARCHAR(50) NOT NULL, -- 'system', 'chat', 'extract', 'calendar_confirm', 'ir_analysis' 등 - version VARCHAR(20) DEFAULT '1.0', - content JSONB NOT NULL, -- 템플릿 내용 + 변수 정의 (XML 구조 유지) - is_active BOOLEAN DEFAULT true, - created_at TIMESTAMPTZ DEFAULT now(), - updated_at TIMESTAMPTZ DEFAULT now(), - - UNIQUE(scope_level, scope_id, prompt_type, version) -); -``` +**테이블**: `prompt_templates` +- scope_level: 'global', 'robeing', 'user', 'task' +- scope_id: robeing_id, user_id, task_type 등 +- prompt_type: 'system', 'chat', 'extract', 'calendar_confirm', 'ir_analysis' 등 +- content: JSONB (템플릿 내용 + 변수 정의) +- version, is_active, created_at, updated_at +--- ## 프롬프트 분류 기준 -### 1. 변경 빈도별 -- **거의 안 바뀜**: Global/system_basic (기본 정체성) -- **자주 변경**: User/preferred_name (사용자 피드백 반영) +### 계층적 범위(Scope) +- Global: 모든 사용자 공통 기본 프롬프트 +- Robeing: 특정 로빙 공통 +- User: 사용자별 개인화 +- Task: 작업 타입별 -### 2. 계층적 범위(Scope) -- **Global**: 모든 사용자 공통 기본 프롬프트 -- **Robeing**: 특정 로빙 공통 -- **User**: 사용자별 개인화 -- **Task**: 작업 타입별 (chat, extract, calendar_confirm 등) - -### 3. 병합 로직 +### 병합 로직 - Global → Robeing → User 순서로 조회 - 각 레벨별 개별 쿼리 후 애플리케이션에서 병합 -- Global scope는 scope_id=NULL로 조회 +--- ## 구현 Phase -## Phase 1: DB 스키마 및 기본 인프라 - -**파일**: `rb8001/app/state/repositories/prompt_repository.py` (신규) -- `prompt_templates` 테이블 생성 -- PromptService 클래스 (조회, 병합, 캐싱) +### Phase 1: DB 스키마 및 기본 인프라 +- `rb8001/app/state/repositories/prompt_repository.py` (신규): prompt_templates 테이블 생성, PromptService 클래스 (조회, 병합, 캐싱) - 기본 프롬프트 마이그레이션 (하드코딩 → DB) -## Phase 2: 핵심 프롬프트 DB화 - -**파일**: `rb8001/app/services/llm/gemini_handler.py`, `rb8001/app/services/llm/llm_service.py` -- 시스템 프롬프트 DB 조회로 변경 +### Phase 2: 핵심 프롬프트 DB화 +- `rb8001/app/services/llm/gemini_handler.py`, `rb8001/app/services/llm/llm_service.py`: 시스템 프롬프트 DB 조회로 변경 - 작업 타입별 프롬프트 (chat, extract, calendar_confirm) DB화 - 폴백 로직: DB 조회 실패 시 기존 `_get_system_prompt()` 메서드 사용 -## Phase 3: 개인화 및 동적 프롬프트 +### Phase 3: 개인화 및 동적 프롬프트 +- `rb8001/app/services/llm/prompt_service.py` (신규): 사용자별 프롬프트 오버라이드, 감정 기반 동적 프롬프트 조합, 변수 치환 시스템 -**파일**: `rb8001/app/services/llm/prompt_service.py` (신규) -- 사용자별 프롬프트 오버라이드 -- 감정 기반 동적 프롬프트 조합 -- 변수 치환 시스템 ({current_time}, {emotion_labels}) +### Phase 4: A/B 테스트 및 모니터링 +- 프롬프트 버전 관리, A/B 테스트 지원, 롤백 기능 -## Phase 4: A/B 테스트 및 모니터링 - -**파일**: `rb8001/app/services/llm/prompt_service.py` -- 프롬프트 버전 관리 -- A/B 테스트 지원 -- 롤백 기능 +--- ## 참고 문서 -- **[[book/300_architecture/313_Gemini_프롬프트_설계_원칙]]** - Gemini 프롬프트 설계 원칙 (XML 구조화, 퓨샷 예시, 구조화 등) - **필수 참고** -- [[ideas/250828_dynamic_system_prompt_memory]] - 동적 시스템 프롬프트 메모리 시스템 -- [[troubleshooting/250806_happybell80_동적프롬프트구현]] - 동적 프롬프트 구현 기록 -- [[book/300_architecture/311_FastAPI_구조_원칙]] - 계층 분리 원칙 - +- `book/300_architecture/313_Gemini_프롬프트_설계_원칙.md` - Gemini 프롬프트 설계 원칙 (필수 참고) +- `ideas/250828_dynamic_system_prompt_memory.md` - 동적 시스템 프롬프트 메모리 시스템 +- `troubleshooting/250806_happybell80_동적프롬프트구현.md` - 동적 프롬프트 구현 기록 +- `book/300_architecture/311_백엔드_구조_원칙.md` - 계층 분리 원칙