c24165b8bc
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게 [공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류. 문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인). - Topic_Programming → Domain_Programming (내부 구조 보존) - Topic_Graphic → Domain_Design - Topic_Business → Domain_Product - Topic_General → Domain_General - _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning), Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing) - 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서) - 빈 폴더 정리 (memory/procedures) - 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
4.7 KiB
4.7 KiB
id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
| id | title | category | status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | verification_status | tags | raw_sources | last_reinforced | github_commit | tech_stack | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wiki-2026-0508-term-frequency-inverse-document- | Term Frequency-Inverse Document Frequency | 10_Wiki/Topics | verified | self |
|
none | A | 0.95 | applied |
|
2026-05-10 | pending |
|
Term Frequency-Inverse Document Frequency
매 한 줄
"매 term frequency × inverse document frequency — 매 word's importance 의 corpus context 매 weight". Karen Spärck Jones (1972) 의 IDF formalization. 2026 매 dense retrieval (BGE, E5) 매 default 매도 매 baseline + hybrid (BM25 + dense) 의 second stage 매 still ubiquitous.
매 핵심
매 Formula
- TF: term의 doc 매 count (raw / log-normalized / frequency).
- IDF:
log(N / df_t)— 매 N corpus size, df_t = doc 매 t의 contains 의 count. - TF-IDF: TF(t,d) × IDF(t).
- L2 norm: 매 cosine 의 prepare.
매 Variants
- Raw TF / log(1+TF) / sublinear.
- IDF smoothing:
log((1+N)/(1+df)) + 1. - BM25: 매 TF saturation + length normalization 의 add.
매 응용
- Search baseline (sklearn + scikit-learn).
- Hybrid retrieval — 매 BM25 + dense embedding의 reciprocal-rank fuse.
- Feature extraction 매 classical ML (logistic regression, SVM).
- Keyword extraction (top-k tfidf).
💻 패턴
sklearn TF-IDF
from sklearn.feature_extraction.text import TfidfVectorizer
corpus = [
"the cat sat on the mat",
"the dog ate the bone",
"cats and dogs are pets",
]
vec = TfidfVectorizer(stop_words="english", sublinear_tf=True, ngram_range=(1, 2))
X = vec.fit_transform(corpus) # sparse (n_docs, n_features)
print(vec.get_feature_names_out())
Cosine search
from sklearn.metrics.pairwise import cosine_similarity
q = vec.transform(["pet animals"])
sims = cosine_similarity(q, X).flatten()
ranking = sims.argsort()[::-1]
Manual IDF (educational)
import math
from collections import Counter
def compute_idf(corpus_tokens):
N = len(corpus_tokens)
df = Counter()
for tokens in corpus_tokens:
for t in set(tokens):
df[t] += 1
return {t: math.log((N + 1) / (df_t + 1)) + 1 for t, df_t in df.items()}
BM25 (preferred over plain TF-IDF for IR)
from rank_bm25 import BM25Okapi
tokenized = [doc.lower().split() for doc in corpus]
bm25 = BM25Okapi(tokenized, k1=1.5, b=0.75)
scores = bm25.get_scores("pet animals".split())
Hybrid search (2026 standard)
import numpy as np
def rrf(rankings, k=60):
scores = {}
for ranking in rankings:
for rank, doc_id in enumerate(ranking):
scores[doc_id] = scores.get(doc_id, 0) + 1 / (k + rank)
return sorted(scores, key=scores.get, reverse=True)
bm25_top = bm25.get_top_n("query".split(), corpus, n=100)
dense_top = dense_index.search("query", k=100)
final = rrf([bm25_top, dense_top])[:10]
Top keyword extraction
def top_keywords(doc_idx, vec, X, k=10):
row = X[doc_idx].toarray().flatten()
feats = vec.get_feature_names_out()
top = np.argsort(-row)[:k]
return [(feats[i], row[i]) for i in top]
Persistence
import joblib
joblib.dump((vec, X), "tfidf_index.joblib")
vec, X = joblib.load("tfidf_index.joblib")
매 결정 기준
| 상황 | Approach |
|---|---|
| 매 small corpus + interpretability | TF-IDF (sklearn) |
| 매 medium corpus + better recall | BM25 |
| 매 semantic / paraphrase | Dense (BGE-M3, E5) |
| 매 production search | Hybrid (BM25 + dense + RRF) |
| 매 keyword extraction / explanation | Plain TF-IDF top-k |
기본값: 매 BM25 baseline → 매 hybrid + reranker (cross-encoder) for 2026 production.
🔗 Graph
- 부모: Information Retrieval
- 변형: BM25
- 응용: Search Engine · RAG
- Adjacent: Dense Retrieval
🤖 LLM 활용
언제: 매 small corpus 매 lookup, 매 RAG 의 sparse channel, 매 explainability ("matched on 'mat', 'cat'"). 언제 X: 매 paraphrase / multilingual 매 weak — 매 dense 의 prefer.
❌ 안티패턴
- TF-IDF 만으로 production search: 매 paraphrase miss.
- No stopword / lowercasing: 매 noisy features.
- Same vectorizer not pickled: 매 train/serve mismatch.
- No length normalization: 매 long docs 의 unfair advantage (use BM25 또는 normalize).
🧪 검증 / 중복
- Verified (Spärck Jones 1972; Manning IR Book Ch.6; sklearn TfidfVectorizer 2026).
- 신뢰도 A.
🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — TF-IDF formula + sklearn + BM25 + hybrid RRF |