C.W.K.
Stream
Lesson 04 of 10 · published

Reranking — top-K가 거짓말할 때

~16 min · context, reranking, rag

Level 0수련생
0 XP0/100 lessons0/14 achievements
0/120 XP to next level120 XP to go0% complete

vector similarity는 relevance가 아니야

Embedding 기반 retrieval은 cosine similarity로 rank하는데, relevance와 correlate되지만 같은 건 아니야. vector search의 top-K는 흔히 vibe로는 비슷한데 살짝 다른 질문에 답하는 chunk 포함. Reranker가 각 candidate를 더 비싼 모델로 실제 query랑 score해서 fix해.

2-stage 패턴

  1. Retrieve — 싸고 broad. vector + BM25 hybrid에서 top-50.
  2. Rerank — 비싸고 narrow. cross-encoder나 LLM으로 50개 각각 query에 score.
  3. Pack — top-N reranked chunk를 synthesis 모델에 feed.

reranking이 비용 값할 때

  • Recall이 precision보다 중요 (legal, medical, support — 답 set에 맞는 chunk 있어야).
  • Query가 짧고 모호 (single keyword, partial phrase).
  • Corpus에 near-duplicate 있음 (reranker가 disambiguate 도와).

skip하는 때

  • Latency budget 빡빡 (200ms 못 더해).
  • Retrieval이 이미 top-3에서 95% 정확.
  • Cost가 dominate, 정확도 acceptable.

Code

Cohere나 LLM judge로 reranking·python
import cohere

cohere_client = cohere.Client()
results = cohere_client.rerank(
    query=user_query,
    documents=top_50_chunks,  # from vector search
    model="rerank-english-v3.0",
    top_n=5,
)

final_chunks = [r.document for r in results.results]

# Or LLM-as-judge alternative:
# Send the 50 chunks to an LLM with a scoring prompt and pick top 5.

External links

Exercise

RAG pipeline에 reranking stage 추가. 라벨된 query set에서 reranking 전후 top-3 정확도 측정. recall gain이 latency 비용 값해?

Progress

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

댓글 0

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

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