From 1793249fa56d56b7915008847294a1701c486108 Mon Sep 17 00:00:00 2001 From: happybell80 Date: Mon, 18 Aug 2025 13:45:46 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20=EB=8C=80=ED=99=94=20=ED=9E=88=EC=8A=A4?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20=EA=B5=AC=ED=98=84=20=ED=8A=B8=EB=9F=AC?= =?UTF-8?q?=EB=B8=94=EC=8A=88=ED=8C=85=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 사용자 매핑 문제 해결 과정 추가 - UUID vs username 불일치 문제 및 해결책 기록 - 반복되는 User ID 체계 문제 교훈 추가 --- ...18_happybell80_대화히스토리구현.md | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/troubleshooting/250818_happybell80_대화히스토리구현.md b/troubleshooting/250818_happybell80_대화히스토리구현.md index e9eed92..691bfd9 100644 --- a/troubleshooting/250818_happybell80_대화히스토리구현.md +++ b/troubleshooting/250818_happybell80_대화히스토리구현.md @@ -107,4 +107,67 @@ app.include_router(api_router, prefix="/api") # 라우터 프리픽스 ### API 엔드포인트 - GET `/rb10508/api/config` - 설정 조회 -- GET `/rb10508/api/messages?before={timestamp}&limit={number}` - 메시지 조회 \ No newline at end of file +- GET `/rb10508/api/messages?before={timestamp}&limit={number}` - 메시지 조회 + +## 오후 1시 30분 - 사용자 매핑 문제 발견 + +### 문제 1: Username 변환 누락 +- API가 `user_id="default_user"`로 검색 +- 실제 데이터는 `rb10508_test_happybell80_episodic` 컬렉션에 저장 +- `search_memories`가 username 파라미터를 받지 못함 + +### 해결 +```python +# app/config.py에 매핑 테이블 추가 +USER_MAPPING: dict = { + "default_user": "happybell80", + "U0925SXQFDK": "happybell80", # Slack ID + "goeun2dc@gmail.com": "happybell80", # Email +} + +# app/api/endpoints.py에 헬퍼 함수 추가 +def resolve_username(user_id: str) -> str: + """user_id를 실제 username으로 변환""" + if user_id in settings.USER_MAPPING: + return settings.USER_MAPPING[user_id] + if "_user" in user_id: + return user_id.replace("_user", "") + return user_id +``` + +## 오후 1시 45분 - UUID vs Username 문제 + +### 문제 2: ChromaDB where 조건 불일치 +- Slack 저장 시: `user_id = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"` (UUID) +- 프론트 검색 시: `user_id = "happybell80"` (username) +- where 조건 `{"user_id": user_id}` 일치하지 않음 + +### 원인 +- 250809, 250812에도 같은 문제 발생 +- User ID 체계 3가지 혼재 (UUID, username, email) +- 각 시스템이 다른 ID 사용 + +### 해결 +```python +# app/core/memory/storage.py 수정 +# username으로 검색하도록 where 조건 변경 +where_clause = {"username": username} if username else {"user_id": user_id} + +results = collection.query( + query_texts=[query], + n_results=n_results, + where=where_clause +) +``` + +## 교훈 (추가) + +### 5. **User ID 체계 통일 필수** +- UUID, username, email 3가지 혼재 문제 +- 각 시스템이 다른 ID 사용하여 반복적 오류 +- 트러블슈팅 문서 확인 습관 필요 + +### 6. **ChromaDB 메타데이터 일관성** +- 저장 시와 검색 시 키 일치 확인 +- username vs user_id 명확히 구분 +- where 조건 디버깅 로그 추가 권장 \ No newline at end of file