[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
@@ -2,89 +2,214 @@
id: wiki-2026-0508-recommendation-systems
title: Recommendation Systems
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [BIZ-REC-SYS-001]
aliases: [RecSys, Recommender Systems, Recommendation Engine]
duplicate_of: none
source_trust_level: A
confidence_score: 1.0
tags: [ai, machine-learning, recommendation-systems, Collaborative-Filtering, Matrix-Factorization, personalization, Deep-Learning]
confidence_score: 0.9
verification_status: applied
tags: [recsys, machine-learning, ranking, retrieval]
raw_sources: []
last_reinforced: 2026-04-26
last_reinforced: 2026-05-10
github_commit: pending
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
tech_stack:
language: unspecified
framework: unspecified
language: python
framework: pytorch
---
# Recommendation[[_system|system]]s (추천 시스템)
# Recommendation Systems
## 📌 한 줄 통찰 (The Karpathy Summary)
> "사용자의 과거와 타인의 선택 속에 숨겨진 '취향의 좌표'를 찾아내어, 사용자가 미처 인지하지 못한 잠재적 욕망을 선제적으로 제안하라" — 사용자의 이력과 선호도를 분석하여 개인에게 가장 적합한 아이템(콘텐츠, 상품 등)을 선별해주는 지능형 큐레이션 시스템.
## 한 줄
> **"매 user × item 의 relevance prediction at scale"**. 매 collaborative filtering (Netflix Prize 2009) → matrix factorization → deep two-tower / sequential / generative recsys. 2026 현재 매 industrial stack 의 multi-stage (retrieval → ranking → re-ranking), 매 LLM-augmented (semantic ID, generative recsys, LLM reranker).
## 📖 구조화된 지식 (Synthesized Content)
- **추출된 패턴:** "P[[Reference|Reference]] Matching and Latent Feature Discovery" — 사용자-아이템 간의 거대한 상호작용 행렬을 분해하여 숨겨진 특징(Latent Factors)을 찾아내거나(Matrix Factorization), 유사한 취향의 이웃을 찾아 그들의 선택을 추천하는 패턴.
- **주요 알고리즘:**
- **Collaborative Filtering:** "나와 비슷한 사람들은 이것도 샀다" (User-based, Item-based).
- **Content-based Filtering:** "내가 본 것과 비슷한 특성을 가진 아이템이다."
- **Hybrid Systems:** 두 방식의 장점을 결합하여 콜드 스타트(Cold Start) 문제 해결.
- **Deep Learning for Recs:** 복잡한 비정형 데이터와 문맥을 반영한 고도화된 추천.
- **의의:** 정보 과부하 환경에서 사용자의 탐색 비용을 획기적으로 낮추고, 플랫폼의 체류 시간과 매출을 극대화하는 비즈니스 지능의 정수.
## 매 핵심
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌:** 단순히 과거 이력만 반복 추천하여 사용자를 '필터 버블(Filter Bubble)'에 가두던 단계에서, 이제는 탐험(Exploration)과 활용(Exploitation)의 균형을 맞추어 사용자의 취향 외연을 확장하는 강화학습 기반 추천으로 진화 중.
- **정책 변화:** Antigravity 프로젝트는 위키 지식 탐색 시, 현재 읽고 있는 문서와 의미적으로 가장 가깝거나 보완적인 관계에 있는 '다음에 읽을만한 주제'를 추천하는 지능형 지식 내비게이션 기능을 제공함.
### 매 paradigms
- **Content-based**: item features × user profile (cold-start friendly).
- **Collaborative filtering (CF)**: user-item interactions only.
- **Memory-based**: user-user / item-item KNN.
- **Model-based**: matrix factorization (MF, ALS, SVD++).
- **Hybrid**: CF + content (LightFM, DCN).
- **Deep**:
- **Two-tower**: user-tower / item-tower → dot product (retrieval).
- **Sequential**: SASRec, BERT4Rec, GRU4Rec — 매 user history sequence modeling.
- **DIN/DIEN**: attention over user behaviors (Alibaba).
- **Graph**: PinSage, LightGCN.
- **Generative recsys (2024-2026)**: TIGER, semantic ID, LLM-as-recommender.
## 🔗 지식 연결 (Graph)
- [[Ranking-Algorithms|Ranking-Algorithms]], Matrix-Factorization-[[Opera|Opera]]tions, [[Reinforcement-Learning|Reinforcement-Learning]], Vector-Database-Foundations
- **Raw Source:** 10_Wiki/Topics/AI/Recommendation-Systems.md
### 매 pipeline (industrial)
1. **Candidate generation (retrieval)**: 100M items → 1000 (two-tower ANN, FAISS / ScaNN).
2. **Ranking**: 1000 → 100 (heavy DCN / DIN, full features).
3. **Re-ranking**: 100 → 10 (diversity, business rules, MMR, RL).
4. **Serving**: <100ms p99.
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
### 매 metrics
- **Offline**: Recall@K, NDCG@K, MAP, AUC, MRR.
- **Online (A/B)**: CTR, conversion, dwell time, session length, retention.
- **Diversity / fairness**: ILD (intra-list diversity), exposure parity.
**언제 이 지식을 쓰는가:**
- *(TODO)*
### 매 응용
1. E-commerce (Amazon, Coupang, Taobao).
2. Video / music (YouTube, TikTok, Spotify).
3. Social feed (Facebook, Twitter/X, LinkedIn).
4. News (Toutiao, Yahoo News).
5. Ads (Google Ads ranking).
**언제 쓰면 안 되는가:**
- *(TODO)*
## 💻 패턴
## 🧪 검증 상태 (Validation)
### Matrix factorization (implicit ALS)
```python
import implicit
from scipy.sparse import csr_matrix
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
# user-item interactions (rows=users, cols=items)
ui = csr_matrix(interactions) # 1.0 for click, weighted by dwell
## 🧬 중복 검사 (Duplicate Check)
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
## 🕓 변경 이력 (Changelog)
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
## 💻 코드 패턴 (Code Patterns)
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
```text
# TODO
model = implicit.als.AlternatingLeastSquares(
factors=128, regularization=0.01, iterations=20, use_gpu=True,
)
model.fit(ui)
recs = model.recommend(userid=42, user_items=ui[42], N=10)
```
## 🤔 의사결정 기준 (Decision Criteria)
### Two-tower retrieval (PyTorch)
```python
import torch
import torch.nn as nn
**선택 A를 써야 할 때:**
- *(TODO)*
class TwoTower(nn.Module):
def __init__(self, n_users, n_items, dim=128):
super().__init__()
self.u_emb = nn.Embedding(n_users, dim)
self.i_emb = nn.Embedding(n_items, dim)
self.u_mlp = nn.Sequential(nn.Linear(dim, dim), nn.ReLU(), nn.Linear(dim, dim))
self.i_mlp = nn.Sequential(nn.Linear(dim, dim), nn.ReLU(), nn.Linear(dim, dim))
**선택 B를 써야 할 때:**
- *(TODO)*
def user_repr(self, u): return nn.functional.normalize(self.u_mlp(self.u_emb(u)), dim=-1)
def item_repr(self, i): return nn.functional.normalize(self.i_mlp(self.i_emb(i)), dim=-1)
**기본값:**
> *(TODO)*
def forward(self, u, i_pos, i_negs):
u_v = self.user_repr(u).unsqueeze(1) # (B, 1, D)
pos = self.item_repr(i_pos).unsqueeze(1) # (B, 1, D)
negs = self.item_repr(i_negs) # (B, K, D)
logits = torch.cat([u_v @ pos.transpose(-1,-2), u_v @ negs.transpose(-1,-2)], dim=-1).squeeze(1)
labels = torch.zeros(u.size(0), dtype=torch.long, device=u.device)
return nn.functional.cross_entropy(logits / 0.07, labels) # in-batch + sampled negs
```
## ❌ 안티패턴 (Anti-Patterns)
### ANN retrieval with FAISS
```python
import faiss, numpy as np
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
item_vecs = model.item_repr(torch.arange(n_items)).detach().cpu().numpy()
index = faiss.IndexFlatIP(128) # inner product
index.add(item_vecs)
def retrieve(user_vec, k=1000):
D, I = index.search(user_vec[None, :], k)
return I[0]
```
### SASRec (sequential recsys)
```python
class SASRec(nn.Module):
def __init__(self, n_items, dim=64, max_len=200, n_heads=2, n_layers=2):
super().__init__()
self.item_emb = nn.Embedding(n_items + 1, dim, padding_idx=0)
self.pos_emb = nn.Embedding(max_len, dim)
layer = nn.TransformerEncoderLayer(dim, n_heads, batch_first=True, activation="gelu")
self.tr = nn.TransformerEncoder(layer, n_layers)
def forward(self, seq): # (B, L)
L = seq.size(1)
pos = torch.arange(L, device=seq.device).unsqueeze(0)
x = self.item_emb(seq) + self.pos_emb(pos)
mask = torch.triu(torch.ones(L, L), diagonal=1).bool().to(seq.device)
h = self.tr(x, mask=mask)
# next-item prediction
return h @ self.item_emb.weight.T # (B, L, V)
```
### DIN-style attention over user history
```python
class DINAttention(nn.Module):
def __init__(self, dim):
super().__init__()
self.mlp = nn.Sequential(nn.Linear(4*dim, dim), nn.ReLU(), nn.Linear(dim, 1))
def forward(self, target, history, mask):
# target (B, D), history (B, L, D), mask (B, L)
T = target.unsqueeze(1).expand_as(history)
feats = torch.cat([T, history, T - history, T * history], dim=-1)
attn = self.mlp(feats).squeeze(-1)
attn = attn.masked_fill(~mask, -1e9).softmax(-1)
return (attn.unsqueeze(-1) * history).sum(1)
```
### LLM reranker (2026)
```python
from anthropic import Anthropic
client = Anthropic()
def llm_rerank(user_history, candidates):
msg = client.messages.create(
model="claude-opus-4-7",
max_tokens=500,
messages=[{"role": "user", "content": f"""
User watched: {user_history}
Rerank these candidates by relevance, return top-10 IDs only as JSON array:
{candidates}
"""}],
)
return parse_json(msg.content[0].text)
```
### Implicit feedback BPR loss
```python
def bpr_loss(u, i_pos, i_neg, model):
s_pos = (model.u(u) * model.i(i_pos)).sum(-1)
s_neg = (model.u(u) * model.i(i_neg)).sum(-1)
return -torch.log(torch.sigmoid(s_pos - s_neg) + 1e-12).mean()
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Cold-start (new user / item) | content-based + popularity |
| Small data (<10k users) | item-item KNN |
| Mid (10k-1M) | ALS / LightFM |
| Large (>1M, sequence behavior) | two-tower retrieval + DIN/SASRec ranking |
| Strict latency budget | two-tower + ANN |
| Need explanation / control | LLM reranker on top-100 |
| Cross-domain (text + image) | multimodal embeddings (CLIP-style) |
**기본값**: 매 industrial 의 two-tower retrieval + DCN/DIN ranking + business-rule rerank, 매 ANN (FAISS / ScaNN), 매 implicit feedback + sampled softmax. 매 LLM-as-reranker 의 emerging 2026 pattern for top-K refinement.
## 🔗 Graph
- 부모: [[Machine-Learning]] · [[Information-Retrieval]]
- 변형: [[Collaborative-Filtering]] · [[Two-Tower-Models]] · [[Sequential-Recsys]]
- 응용: [[E-commerce]] · [[Content-Recommendation]] · [[Ad-Ranking]]
- Adjacent: [[Embeddings]] · [[ANN-Search]] · [[Ranking-Loss]] · [[FAISS]]
## 🤖 LLM 활용
**언제**: cold-start (zero-shot recommendation from item description), reranker on top-100, explanation generation, semantic ID encoding.
**언제 X**: full-funnel retrieval at scale (latency / cost prohibitive). 매 LLM 의 reranker only, 매 retrieval 의 ANN.
## ❌ 안티패턴
- **Random negative sampling only**: easy negatives, model 의 saturate — use hard negatives + in-batch negatives.
- **Train on biased logged data**: position bias / popularity bias not corrected → IPS / counterfactual.
- **Offline metric chasing**: NDCG up but online CTR flat — online A/B 의 truth.
- **Cold-start ignore**: pure CF 의 fail on new items — hybrid fallback.
- **No exploration**: greedy ranking → filter bubble. ε-greedy / Thompson / contextual bandit.
- **Single objective**: CTR-only optimization 의 clickbait. Multi-objective (dwell, retention).
## 🧪 검증 / 중복
- Verified (Koren 2009 Netflix Prize, He LightGCN 2020, Kang SASRec 2018, Zhou DIN 2018, Covington YouTube DNN 2016, Google TIGER 2024).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — full canonical recsys with two-tower/SASRec/DIN/LLM-reranker |