C.W.K.
Stream
Lesson 03 of 05 · published

임베딩 기반 recall + 메모리 인덱싱

~22 min · memory, retrieval

Level 0Scout
0 XP0/41 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

메모리 store 에 뭘 임베딩해

모든 발화가 벡터 받을 자격 있는 거 아냐. 좋은 룰: 검색할 가치 있는 콘텐츠 + 필터할 가치 있는 메타데이터 가진 메모리 아이템 임베딩. 인사, 끄덕임, tool-output JSON 은 보통 noise.

유용한 메모리 아이템 모양 셋

  • Turn-level — 유저/어시스턴트 메시지당 청크 하나. 쉬움, 아이템 많음, retrieval 이 흩어진 느낌.
  • Episode-level — 일관된 episode (디버깅 세션, 기능 디자인 토론) 로 연속 turn 그룹. 더 좋은 retrieval relevance, 자동 청킹 더 어려움.
  • Distillation-level — 모델-쓴 episode 요약 ('30분 latency 벤치마크 후 유저가 IVFFlat 보다 HNSW 결정'). 가장 높은 신호-잡음, 주기적 distillation pass 필요.

Decay-aware retrieval

최근 메모리가 옛 거보다 tie 이김. Score = similarity * exp(-age_days / half_life). eval set 으로 half_life 튜닝; cwkPippa 가 일반 메모리에 ~30일 사용, 정체성-defining 순간엔 더 길게.

Code

Decay-aware reranking·python
import math
from datetime import datetime, timezone

def decay_rerank(candidates: list[dict], half_life_days: float = 30.0):
    now = datetime.now(timezone.utc)
    for c in candidates:
        ts = datetime.fromisoformat(c['metadata']['created_at'])
        age_days = (now - ts).total_seconds() / 86400
        decay = math.exp(-age_days / half_life_days)
        c['final_score'] = c['similarity'] * decay
    return sorted(candidates, key=lambda c: -c['final_score'])
Episode distillation pass (nightly)·python
DISTILL_PROMPT = '''Read the following turns and produce 1-3 standalone facts worth remembering long-term. Each fact should be self-contained — readable in 6 months without re-reading the conversation.

Turns:
{turns}

Output as JSON: [{{"fact": "...", "tags": ["..."]}}]
'''

def distill_episode(turns: list[dict]) -> list[dict]:
    text = '\n'.join(f"{t['role']}: {t['content']}" for t in turns)
    return json.loads(llm.complete(DISTILL_PROMPT.format(turns=text)))

External links

Exercise

저장한 대화 하나 골라 (또는 가짜 만들어). 구현: turn-level 임베딩, episode-level 임베딩, distillation 임베딩. 각 store 에 retrieval query 10개 실행. 어느 아이템 모양이 토큰당 가장 useful 한 context 반환하는지 노트.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.