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

Retrieval Contract

~20 min · rag, design

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

retrieval 이 generator 한테 빚지는 것

RAG 는 retrieval 이 generator 와 명확한 contract 유지할 때 작동: 여기 청크들, 여기 각각의 source, 여기 confidence 신호. 셋 중 하나라도 빠지면 LLM 이 hallucinate 하거나 인용 거부.

모든 retrieval 결과가 가져야 할 세 신호

  1. Text — 임베딩한 그대로의 청크 콘텐츠.
  2. Source — 파일 경로, URL, 문서 id, 청크 index. generator (그리고 유저) 가 traceback 가능하게 하는 모든 거.
  3. Score — similarity 또는 rerank score 로 prompt 도달 전 low-confidence hit drop.

최소 viable RAG 루프

question -> embed -> retrieve top-k -> filter by score -> stuff into prompt -> generate -> render with citations

나머지 (query rewriting, multi-query, reranking, summarization) 는 다 optimization. 먼저 루프 돌게 하기; eval set 이 깨졌다고 말하는 거 optimize.

Code

30줄 MVP RAG 루프·python
def rag(question: str, k: int = 5, min_score: float = 0.3) -> dict:
    candidates = retrieve(question, k=k * 4)
    candidates = [c for c in candidates if c['score'] >= min_score]
    candidates = candidates[:k]

    if not candidates:
        return {'answer': "I don't have enough information to answer that.",
                'citations': []}

    context = '\n\n'.join(
        f'[{i+1}] (source: {c["source"]})\n{c["text"]}'
        for i, c in enumerate(candidates)
    )
    system = (
        'Answer using ONLY the provided context. Cite sources as [1], [2], etc. '
        'If the context is insufficient, say so explicitly.'
    )
    prompt = f'Context:\n{context}\n\nQuestion: {question}'
    answer = llm.complete(prompt, system=system)
    return {'answer': answer, 'citations': candidates}

External links

Exercise

본인 코퍼스에 위 MVP RAG 루프 구현. 질문 10개 실행. 측정: 답이 진짜 source 인용한 횟수, 답이 hallucinate 한 횟수, 'I don't know' 정확히 말한 횟수. 가장 아픈 failure mode 골라 다음에 고쳐.

Progress

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

댓글 0

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

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