diff --git a/journey/plans/251017_intent_analysis_improvement_plan.md b/journey/plans/251017_intent_analysis_improvement_plan.md deleted file mode 100644 index 3c8fcf6..0000000 --- a/journey/plans/251017_intent_analysis_improvement_plan.md +++ /dev/null @@ -1,33 +0,0 @@ -# 로빙 의도 파악 개선 플랜 - -**날짜**: 2025-10-17 -**상태**: 부분 완료 (3단계 아키텍처 완료, 하이브리드 시스템 미구현) - ---- - -## Phase 1: 3단계 아키텍처 (✅ 완료) - -→ 상세: `troubleshooting/251126_happybell80_rb8001_의도_3단계_아키텍처_도입_및_배포.md` - ---- - -## 남은 작업 - -### 하이브리드 시스템 구현 - -**구조**: -1. 정규식 FastPath (명확한 패턴) → conf ≥ 0.9 즉시 결정 -2. 임베딩 후보 축소 (Top-3) → 확신도 < 0.7 시 -3. LLM 제로샷 분류 → conf < 0.5 시 CLARIFY - -**필요 작업**: -- SemanticIntentClassifier 구현: `app/services/brain/semantic_classifier.py`, intent_prototypes 테이블 활용, 임베딩 유사도로 Top-3 후보 선택 -- LLM 폴백: Top-3 후보를 LLM에 전달, 확신도 < 0.5 시 CLARIFY - ---- - -## 참고 - -- `troubleshooting/251126_happybell80_rb8001_의도_3단계_아키텍처_도입_및_배포.md` -- `troubleshooting/251126_intent_3step_db_bayesian_integration.md` -- `book/300_architecture/311_백엔드_구조_원칙.md` diff --git a/journey/plans/README.md b/journey/plans/README.md index 76743c7..10c3c3b 100644 --- a/journey/plans/README.md +++ b/journey/plans/README.md @@ -12,6 +12,7 @@ 3. **main_db3_migration_plan (250911)** - 완료 → archive 이동 4. **뉴스 시스템 (250906)** - 완료 → archive 이동 (E2E 테스트 완료) 5. **동남아 스타트업 뉴스 아침브리핑 (260129)** - 완료 → `plans/archive/260129_동남아_스타트업_뉴스_아침브리핑.md` +6. **의도 런타임 하이브리드 (251023)** - 전체 완료 (260203) → `plans/archive/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md` --- @@ -39,16 +40,7 @@ - Phase 4: A/B 테스트 및 모니터링 **참고**: `plans/251225_프롬프트_동적관리_계획.md` -### 4. 의도 런타임 하이브리드 (251023) -**상태**: 부분 완료 (3단계 아키텍처 완료) -**목표**: FastPath + 임베딩 + LLM 하이브리드 시스템 -**필요 작업**: -- SemanticIntentClassifier 구현 (임베딩 후보 축소) -- LLM 폴백 (Top-K 후보 재분석) -- 베이지안 동적 학습 (Beta(α,β) 추적, Thompson Sampling) -**참고**: `plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md` - -### 5. 감정 기록 및 패턴 분석 시스템 (250808 Phase 3) +### 4. 감정 기록 및 패턴 분석 시스템 (250808 Phase 3) **상태**: 부분 완료 (Phase 1 완료, Phase 2/3 미구현) **목표**: 감정 패턴 분석 시스템 구축 및 리서치 기반 감정 시스템 확장 **필요 작업**: @@ -80,11 +72,6 @@ - **남은 작업**: Phase 1.5 (베이지안 학습), Phase 2-3 (Neo4j 기억 시스템, 감정-기억-윤리) - **참고**: `plans/251016_ontology_coldmail_implementation.md` -### 4. 의도 런타임 하이브리드 (251023) -- **완료**: Phase 1·2, Phase 3 DB 접근(311)·Thompson τ·Thompson pytest -- **남은 작업**: Phase 3 LLM 호출 문서화, 의도 프롬프트(313), LangGraph 검토 -- **참고**: `plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md` - --- ## 참고 문서 diff --git a/journey/plans/archive/251017_intent_analysis_improvement_plan.md b/journey/plans/archive/251017_intent_analysis_improvement_plan.md index e4048d6..7bd83f5 100644 --- a/journey/plans/archive/251017_intent_analysis_improvement_plan.md +++ b/journey/plans/archive/251017_intent_analysis_improvement_plan.md @@ -1,93 +1,25 @@ # 로빙 의도 파악 개선 플랜 **날짜**: 2025-10-17 -**현재**: 정규식 패턴 매칭만 사용 +**아카이브**: 251023으로 통합됨. 남은 작업은 `plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md` 참조 --- -## 현재 문제 +## Phase 1: 3단계 아키텍처 (✅ 완료) -### 처리 불가 사례 -| 질문 | 현재 처리 | 문제 | -|------|----------|------| -| "오늘 몇일이야?" | UNKNOWN | 시간 질문 패턴 없음 | -| "리버스마운틴 유사 기업 가치평가해줘" | UNKNOWN | 복잡한 멀티스텝 질문 | -| "아까 말한 그 기업 투자 단계는?" | UNKNOWN | 맥락 참조 불가 | - -**결론**: 단순 명령만 처리 가능, 복합 질문 처리 불가 +→ 상세: `troubleshooting/251126_happybell80_rb8001_의도_3단계_아키텍처_도입_및_배포.md` --- -## 개선 방향 (3단계 구조) +## Phase 1.5: 하이브리드 파이프라인 (✅ 완료) -**구현 완료**: `troubleshooting/251126_happybell80_rb8001_의도_3단계_아키텍처_도입_및_배포.md` - -**완료일**: 2025-11-26 -**커밋**: `a4738b9` (rb8001) - -### 완료 사항 -- ✅ 3단계 스키마 정의: `intent/schemas.py` (IntentCategory, IntentGoal, ActionPlan, SkillSequence) -- ✅ IntentAnalyzer 구현: LLM 기반 제로샷 의도 분석 -- ✅ ActionPlanner 구현: IntentGoal → ActionPlan 변환 -- ✅ SkillSelector 구현: ActionPlan → SkillSequence 변환 -- ✅ DecisionEngine 통합: `_build_intent_pipeline()` 메서드 추가, execution_plan에 intent_pipeline 메타데이터 포함 -- ✅ TDD 테스트: `tests/test_intent_3step_architecture.py` 통과 - -``` -1. 의도 파악 → 추상적 목표 (일정 관리, 정보 검색 등) -2. 행동 계획 → 구체적 행동 (등록, 조회, 삭제 등) -3. 스킬 선택 → 적절한 도구 (calendar_skill 등) -``` +→ 상세: `troubleshooting/251126_intent_3step_db_bayesian_integration.md` --- -## 하이브리드 시스템 +## 남은 작업 -**초기 테스트 결과 (2026-01-03)**: `troubleshooting/260103_하이브리드_의도_분류_성능_비교_테스트.md` -- FastPath: 49.6% (72ms) -- 제로샷 임베딩: 23.4% (80ms) - 개선 필요 -- 병행 비교: 49.6% (154ms) - 의미 없음 - -**Multi-centroid 적용 완료 (2026-01-03)**: `troubleshooting/260103_하이브리드_의도_분류_성능_비교_테스트.md` -- **커밋**: `247496a` (rb8001) -- FastPath: 72.3% (64ms) - +22.7%p -- 제로샷 임베딩: 70.2% (82ms) - +46.8%p ✅ -- 병행 비교: 70.9% (148ms) - +21.3%p - -### 개선된 구조 -``` -사용자 메시지 - ↓ -1단계: 정규식 FastPath (명확한 패턴) - ↓ 실패 또는 확신도 < 0.9 -2단계: Multi-centroid 임베딩 (Top-3 후보 생성) - ↓ 확신도 < 0.7 -3단계: Few-shot LLM 분류 (Top-3 후보 + 예시) -``` - -### 완료 작업 - -**1. Multi-centroid 방식 도입** ✅ -- 파일: `scripts/seed_multi_centroid_prototypes.py` 생성 -- 각 intent별 3개 K-means centroid 생성 (123개 샘플 사용) -- intent_prototypes 테이블 version=3으로 저장 -- `intent_store.py`: `load_multi_prototypes_db()` 추가 -- `semantic_classifier.py`: multi-centroid 최대 유사도 계산 적용 - -**2. Intent Prototypes DB 초기화** ✅ -- 768d Ko-SRoBERTa 기준으로 재임베딩 완료 -- intent_prototypes 테이블 version=3으로 저장 -- dimension mismatch 해결 (768d 일관성 유지) - -**3. Few-shot LLM 프롬프트 개선** 🔄 진행 중 -- 파일: `app/services/llm/intent_parser.py` -- Top-3 후보를 활용한 Few-shot 예시 추가 필요 -- Gemini 프롬프트 설계 원칙(`313_Gemini_프롬프트_설계_원칙.md`) 적용 필요 - -**4. 성능 목표** -- FastPath: 72.3% 정확도 (64ms) ✅ -- Multi-centroid embedding: 70.2% 정확도 (82ms) - 75%+ 목표 미달, 개선 필요 -- Few-shot LLM: 미구현 - 75%+ 달성을 위해 필요 +→ `plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md` Phase 3 참조 --- @@ -95,4 +27,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/archive/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md similarity index 51% rename from journey/plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md rename to journey/plans/archive/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md index c6040f7..e9c6286 100644 --- a/journey/plans/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md +++ b/journey/plans/archive/251023_happybell80_의도_런타임_하이브리드_임베딩_베이지안_동적학습.md @@ -2,7 +2,7 @@ **날짜**: 2025-10-23 (251017 통합) **목표**: FastPath + 임베딩 Top-K + LLM 재분석 + Beta(α,β) 동적 임계치 하이브리드 -**상태**: Phase 1·2 완료, Phase 3 부분 완료 +**상태**: 전체 완료 (260203 archive 이동) --- @@ -18,14 +18,16 @@ --- -## Phase 3: 베이지안 동적 학습 (부분 완료) +## Phase 3: 베이지안 동적 학습 (✅ 완료) → 완료: `intent_path_stats`, `decision_logs`, ActionPlanner 경로별 성공률 조회 → 2번 DB 접근·1번 Thompson·4번 Thompson 테스트: `troubleshooting/260203_intent_phase3_db_thompson_tests.md` -### 작업 순서 (권장) +### 완료 (260203) -- **3번(LLM 문서화)·5번(프롬프트)·6번(LangGraph)** 서로 독립, 병렬 진행 가능. +- **3번 LLM 호출 최적화**: `troubleshooting/260203_intent_llm_call_optimization.md` (경로별 호출 수·할당량 참고) +- **5번 의도 분류 프롬프트 313**: `troubleshooting/260203_intent_prompt_313_alignment.md` (형식·퓨샷·구조화) +- **6번 LangGraph 검토**: 의도 분류는 이미 LangGraph 워크플로우(`intent_langgraph_workflow`)로 전환됨. `INTENT_USE_LANGGRAPH=true` 시 사용, `_detect_traditional`은 폴백. ### 관련 코드 위치 (rb8001) @@ -36,34 +38,6 @@ | ActionPlanner | `app/services/brain/intent/action_planner.py` (intent_store만 사용, psycopg2 없음) | | Beta 갱신·decision 로깅 | `app/state/intent_runtime_repository.py` | -### 남은 작업 - -#### 3. LLM 호출 최적화 (311 섹션 14) - -| 항목 | 내용 | -|------|------| -| **필수** | FastPath→Semantic→LLM 경로별 호출 횟수 계산 및 DOCS에 문서화 | -| **확인** | API 할당량(RPM/RPD) 대비 호출량 검토 | -| **완료 조건** | 경로별 호출 수·할당량 대비 비율이 troubleshooting 또는 plans 하위 문서에 기록됨 | - -#### 5. 의도 분류 프롬프트 (313) - -| 항목 | 내용 | -|------|------| -| **대상** | 의도 분류 LLM 호출 (intent_analyzer 또는 intent_parser 쪽 프롬프트) | -| **필수** | 출력 형식, 퓨샷 예시, 구조화 검증을 313 원칙에 맞게 정리 | -| **참조** | `book/300_architecture/313_Gemini_프롬프트_설계_원칙.md` | -| **완료 조건** | 프롬프트가 313 체크리스트(형식·예시·검증)를 충족하고 문서에 반영됨 | - -#### 6. LangGraph 검토 (311 섹션 5) - -| 항목 | 내용 | -|------|------| -| **311 원칙** | 의도 분류 등 다단계 워크플로우는 LangGraph 활용 권장 | -| **현재** | `intent_graph.py` 일반 함수 파이프라인 | -| **선택** | 체크포인트·재개·분기 복잡도 증가 시 LangGraph 전환 여부를 311에 맞게 결정하고 계획에 기록 | -| **완료 조건** | 전환 시도 시 troubleshooting에 결정 근거·변경 범위 기록; 미전환 시 이유를 본 계획 또는 ideas에 한 줄 기록 | - --- ## 참고 diff --git a/journey/troubleshooting/260203_intent_llm_call_optimization.md b/journey/troubleshooting/260203_intent_llm_call_optimization.md new file mode 100644 index 0000000..262ae20 --- /dev/null +++ b/journey/troubleshooting/260203_intent_llm_call_optimization.md @@ -0,0 +1,30 @@ +# 의도 분류 경로별 LLM 호출 최적화 (311 섹션 14) + +**날짜**: 2026-02-03 +**작성자**: happybell80 +**관련 파일**: `rb8001/app/services/brain/intent_graph.py`, `intent_langgraph_workflow.py`, `app/services/llm/intent_parser.py` + +--- + +## 경로별 LLM 호출 수 (메시지 1건당) + +| 경로 | 조건 | LLM 호출 수 | 비고 | +|------|------|-------------|------| +| **fastpath** | DecisionEngine 규칙/패턴 매칭, conf ≥ τ | **0** | LLM 미호출 | +| **semantic** | 임베딩 Top-K + 신뢰도 ≥ accept | **0** | 임베딩 API만, LLM 미호출 | +| **llm** | fastpath/semantic 미충족 시 | **1** | IntentParserLLM.parse 1회 | +| **LangGraph** | INTENT_USE_LANGGRAPH=true 시 | **0~2** | 짧은 메시지: expand_question 1회 + classify(내부 fastpath/semantic/llm) 0~1 + extract_entities 시 parser.parse 1회 | + +- **traditional** (_detect_traditional): 메시지당 **0 또는 1** LLM 호출. +- **LangGraph**: 메시지당 **0** (fastpath/semantic으로 종료) 또는 **1** (expand만) 또는 **2** (expand + parse). + +## API 할당량 검토 + +- Gemini API: RPM(분당 요청), RPD(일당 요청), TPM(분당 토큰) 제한. 초과 시 429. +- 의도 분류는 메시지당 최대 2회 LLM 호출이므로, 동시 사용자 증가 시 RPM/RPD 모니터링 권장. +- 할당량: [Google AI Rate limits](https://ai.google.dev/gemini-api/docs/rate-limits) 참고. 프로젝트별 한도 확인 필수. + +## 교훈 + +- FastPath·Semantic으로 대부분 메시지에서 LLM 호출 0회로 비용 절감. LLM 호출은 불확실한 케이스에만 발생. +- 경로별 호출 수를 문서화해 할당량 계획 및 311 체크리스트 충족. diff --git a/journey/troubleshooting/260203_intent_prompt_313_alignment.md b/journey/troubleshooting/260203_intent_prompt_313_alignment.md new file mode 100644 index 0000000..80182b2 --- /dev/null +++ b/journey/troubleshooting/260203_intent_prompt_313_alignment.md @@ -0,0 +1,22 @@ +# 의도 분류 프롬프트 313 정리 (251023 계획 5번) + +**날짜**: 2026-02-03 +**작성자**: happybell80 +**관련 파일**: `rb8001/app/services/llm/intent_parser.py`, `rb8001/app/services/brain/intent/intent_analyzer.py` + +--- + +## 313 체크리스트 반영 + +| 항목 | intent_parser | intent_analyzer | +|------|---------------|-----------------| +| **출력 형식 명시** | `` 스키마 JSON 한 줄 | `` JSON only | +| **퓨샷 예시** | `` 2건 (일정 등록, 취소) | `` 2건 (등록, "그래" 승인) | +| **구조화** | XML role/output_format/examples/constraints | XML role/categories/output_format/examples | + +- 의도 분류 LLM 호출 두 곳(IntentParserLLM, IntentAnalyzer) 모두 313 원칙에 맞게 출력 형식·긍정 퓨샷·XML 구조 적용. +- 검증: 응답에서 JSON 추출 및 필드 검증은 기존 `extract_json_from_text`·IntentGoal 파싱 유지. + +## 교훈 + +- 313: 명확한 출력 형식과 긍정적 퓨샷이 분류 품질에 유리. XML 태그로 구역 분리 시 파싱·유지보수 용이.