트러블슈팅 추가: 이름 영속화 ChromaDB identity 컬렉션 구현
This commit is contained in:
parent
9d70b7e49b
commit
a45642368b
@ -148,8 +148,107 @@ f"안녕하세요{greeting_name}! 오늘은 어떤 도움이 필요하신가요?
|
||||
- 과도한 패턴 매칭이 캐시 시스템 무력화
|
||||
- 적절한 균형 필요
|
||||
|
||||
## 오후 4시 00분
|
||||
|
||||
### 이름 영속화 문제 발견
|
||||
|
||||
**서버팀 보고**:
|
||||
- 코드는 정상 작동 (에러 없음)
|
||||
- "내 이름은 김종태야" → "김종태님, 반갑습니다!" (인식 성공)
|
||||
- 하지만 다음 대화에서 까먹음 (영속화 실패)
|
||||
|
||||
**원인 분석**:
|
||||
1. 매 요청마다 새로운 Brain 인스턴스 생성
|
||||
2. 딕셔너리만 사용 → 인스턴스 소멸 시 이름 정보도 소실
|
||||
3. 컨테이너 재시작 시 모든 정보 리셋
|
||||
|
||||
### ChromaDB Identity 컬렉션 솔루션
|
||||
|
||||
**서버팀 제안**:
|
||||
- 이미 사용 중인 ChromaDB에 identity 컬렉션 추가
|
||||
- 벡터 검색 불필요한 단순 key-value 저장
|
||||
- 파일이나 Redis 추가 불필요
|
||||
|
||||
**구현 내역**:
|
||||
|
||||
1. **memory.py에 identity 컬렉션 추가**:
|
||||
```python
|
||||
self.identity_collection = self.client.get_or_create_collection(
|
||||
name=f"{settings.ROBING_ID}_identity",
|
||||
metadata={"type": "identity", "description": "User and robing names"}
|
||||
)
|
||||
```
|
||||
|
||||
2. **store_identity() 메서드**:
|
||||
```python
|
||||
async def store_identity(self, user_id: str, user_name: str = None, robing_name: str = None):
|
||||
doc_id = f"identity:{user_id}"
|
||||
self.identity_collection.upsert(
|
||||
ids=[doc_id],
|
||||
documents=[f"user:{user_name},robing:{robing_name}"],
|
||||
metadatas=[{"user_name": user_name, "robing_name": robing_name}]
|
||||
)
|
||||
```
|
||||
|
||||
3. **get_identity() 메서드**:
|
||||
```python
|
||||
async def get_identity(self, user_id: str) -> Dict:
|
||||
result = self.identity_collection.get(ids=[f"identity:{user_id}"])
|
||||
if result['metadatas']:
|
||||
return result['metadatas'][0]
|
||||
return {}
|
||||
```
|
||||
|
||||
4. **think() 시작 시 identity 로드**:
|
||||
```python
|
||||
# Identity 로드 (영속 저장된 이름 정보)
|
||||
identity = await self.memory.get_identity(user_id)
|
||||
|
||||
if identity.get('user_name'):
|
||||
self.current_user_name = identity['user_name']
|
||||
else:
|
||||
self.current_user_name = '사용자'
|
||||
```
|
||||
|
||||
5. **Structured Output에서 즉시 저장**:
|
||||
```python
|
||||
if data.get('user_name') and data['user_name'] != "null":
|
||||
await self.memory.store_identity(
|
||||
user_id=self.current_user_id,
|
||||
user_name=data['user_name']
|
||||
)
|
||||
logger.info(f"[IDENTITY] 사용자 이름 저장: {data['user_name']}")
|
||||
```
|
||||
|
||||
### 해결된 문제
|
||||
|
||||
1. **영속성 보장**:
|
||||
- 컨테이너 재시작 후에도 이름 유지
|
||||
- Brain 인스턴스 재생성과 무관
|
||||
- ChromaDB 백업과 함께 관리
|
||||
|
||||
2. **운영 단순화**:
|
||||
- 추가 인프라 불필요
|
||||
- 하나의 DB로 통합 관리
|
||||
- 모니터링 포인트 감소
|
||||
|
||||
## 교훈
|
||||
|
||||
1. **기존 인프라 활용**:
|
||||
- 새로운 솔루션 도입보다 기존 시스템 활용이 효율적
|
||||
- ChromaDB는 벡터 DB지만 key-value 저장도 가능
|
||||
|
||||
2. **영속성의 중요성**:
|
||||
- 메모리 기반 저장은 항상 휘발성 고려
|
||||
- 중요 정보는 반드시 영속 저장소에
|
||||
|
||||
3. **간단한 해결책 우선**:
|
||||
- 파일 저장 → 권한, 백업 문제
|
||||
- Redis → 새 의존성, 복잡도 증가
|
||||
- ChromaDB identity → 이미 있는 것 활용
|
||||
|
||||
---
|
||||
|
||||
작성자: happybell80 & Claude
|
||||
프로젝트: rb10508_micro
|
||||
주제: 동적 프롬프트 구현으로 의도 파악 개선
|
||||
주제: 동적 프롬프트 구현 및 이름 영속화
|
||||
Loading…
x
Reference in New Issue
Block a user