@@ -202,6 +202,8 @@ class MemoryManager:
202202 # --- 기억 조회 관련 감정 영향도 ---
203203 RETRIEVAL_FETCH_MULTIPLIER = 4 # 유사도 후보를 조금 넓게 뽑은 뒤 감정 점수로 재정렬
204204 RETRIEVAL_SURPRISE_TRAUMA_WEIGHT = 0.2
205+ RETRIEVAL_MOOD_RESONANCE_WEIGHT = 0.08 # 현재 기분과 같은 방향의 정서 기억은 더 쉽게 떠오름 (기분 좋을땐 좋은 생각)
206+ RETRIEVAL_AROUSAL_RESONANCE_WEIGHT = 0.04 # 현재 각성도와 비슷한 강도의 기억은 약하게 공명
205207 # 아래 상수 합은 1로 맞추는 것을 권장 (KIND_RETRIEVAL_BONUS와 적정 스케일로 맞출 것)
206208 RETRIEVAL_SIMILARITY_WEIGHT = 0.62 # 의미적 관련성은 항상 1순위로 유지 (이성 판단)
207209 RETRIEVAL_AROUSAL_WEIGHT = 0.18 # 각성도가 높은 기억은 현재 판단에 더 잘 끼어듦
@@ -266,18 +268,37 @@ def store_memory(
266268 )
267269 )
268270
269- def retrieve_memory (self , query : str ) -> list [str ]:
271+ def retrieve_memory (
272+ self ,
273+ query : str ,
274+ current_arousal : float = 0.0 ,
275+ current_mood : float = 0.0 ,
276+ ) -> list [str ]:
270277 clean_query = query .strip ()
271278 if not clean_query :
272279 return []
273280
274281 query_embedding = self ._embed_text (clean_query )
275282 retrieved_candidates : list [tuple [float , str ]] = []
276283 retrieved_candidates .extend (
277- self ._query_collection (self .hot_storage , query_embedding , self .HOT_RESULTS_PER_QUERY , "VIVID" )
284+ self ._query_collection (
285+ self .hot_storage ,
286+ query_embedding ,
287+ self .HOT_RESULTS_PER_QUERY ,
288+ "VIVID" ,
289+ current_arousal ,
290+ current_mood ,
291+ )
278292 )
279293 retrieved_candidates .extend (
280- self ._query_collection (self .cold_storage , query_embedding , self .COLD_RESULTS_PER_QUERY , "DISTANT" )
294+ self ._query_collection (
295+ self .cold_storage ,
296+ query_embedding ,
297+ self .COLD_RESULTS_PER_QUERY ,
298+ "DISTANT" ,
299+ current_arousal ,
300+ current_mood ,
301+ )
281302 )
282303
283304 retrieved_candidates .sort (key = lambda item : item [0 ], reverse = True )
@@ -543,6 +564,8 @@ def _query_collection(
543564 query_embedding : list [float ],
544565 result_count : int ,
545566 label : str ,
567+ current_arousal : float = 0.0 ,
568+ current_mood : float = 0.0 ,
546569 ) -> list [tuple [float , str ]]:
547570 collection_count = self ._chroma_call (collection .count , fallback = 0 )
548571 if collection_count == 0 :
@@ -582,11 +605,15 @@ def _query_collection(
582605 # 그런데 계속 관련 없는 기억이 답변을 오염함 → 나쁨. retrieval 스케일 조정 필요 (지나친 딴소리)
583606 # 혹은, 특정 threat/reward가 거의 항상 튀어나옴 → kind/arousal 가중치 과함 (지나친 과민 반응)
584607 similarity_score = 1.0 / (1.0 + max (0.0 , float (distance )))
608+ mood_resonance = max (0.0 , current_mood * valence )
609+ arousal_resonance = 1.0 - min (1.0 , abs (current_arousal - arousal ))
585610 affective_score = (
586611 self .RETRIEVAL_SIMILARITY_WEIGHT * similarity_score
587612 + self .RETRIEVAL_AROUSAL_WEIGHT * arousal
588613 + self .RETRIEVAL_SURPRISE_WEIGHT * surprise
589614 + self .RETRIEVAL_VALENCE_WEIGHT * abs (valence )
615+ + self .RETRIEVAL_MOOD_RESONANCE_WEIGHT * mood_resonance
616+ + self .RETRIEVAL_AROUSAL_RESONANCE_WEIGHT * arousal_resonance
590617 + self .KIND_RETRIEVAL_BONUS .get (kind , 0.0 )
591618 )
592619
0 commit comments