[Week3] 스타듀밸리 위키 도메인 RAG 시스템 구현#18
Open
Parkhaeil wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
스타듀밸리 한국어 위키를 데이터 소스로 하는 도메인 특화 RAG 시스템을 구현했습니다. 위키 크롤링 → 청킹 전략 비교 실험 → LangGraph 기반 2-step RAG 그래프까지 전 과정을 포함합니다.
구현 요약
파일 구조
주요 설계
WikiRetrievalChain에splitter_type='recursive' | 'markdown_header'파라미터를 두어 전략 전환 가능.cache/faiss_index/stardew_wiki_{splitter_type}/)하여 비교 실험 시 재색인 없이 전환question/context/answer/source_docs/messages5개 필드, MemorySaver 체크포인터category + 파일명형식 출처 자동 부착청킹 전략 비교 결과 및 선택 이유
비교 대상:
RecursiveCharacterTextSplittervsMarkdownHeaderTextSplitter청크 통계
쿼리별 비교
farming_keg.md728자 청크 — 기본 정보 포함farming_keg.md전체 섹션 1,645자 — 재료·산출물 대응표 온전히 보존## 봄 작물), 5자(### 봄) 등 헤더만 잘린 무의미 청크farming_crops_spring.md봄 시즌 전체 컨텍스트 정상 검색farming_keg.md등 관련 없는 문서에서 "미끼" 언급 부분 상위 노출fishing_tackle.md§ 미끼 아이템 2,099자 효과 상세표 온전히 검색채택: MarkdownHeaderTextSplitter
Q2에서 Recursive가 7자·5자짜리 헤더만 남은 빈 청크를 상위로 올린 것이 결정적이었습니다.
chunk_size=800으로 자를 때 헤더 바로 뒤 내용이 다음 청크로 넘어가면서 헤더만 남은 조각이 생성된 것으로, 검색 결과로 활용 불가능한 수준이었습니다.반면 MarkdownHeaderTextSplitter는 위키 문서의 섹션 구조를 그대로 보존합니다. Q1의 재료-산출물 대응표(1,645자)와 Q3의 미끼 효과 상세표(2,099자)가 각각 단일 청크로 검색되어 LLM이 완전한 정보를 받을 수 있었습니다.
단점으로 평균 청크 크기가 2,303자로 커서 LLM 입력 토큰이 늘고, 최대 3,641자짜리 청크도 존재합니다. 그러나 스타듀밸리 위키처럼 헤더 단위로 정보가 명확히 구분된 문서에서는 구조 보존의 이점이 토큰 비용을 상쇄한다고 판단했습니다.
실행 결과
데이터 수집
crawl_wiki.py로ko.stardewvalleywiki.com에서 24개 마크다운 수집인덱싱
Group A 테스트 (6개 최종 질문, 모두 verified)
테스트 대상 질문:
farming_keg.mdfarming_ancient_seed.mdfarming_greenhouse.mdfishing_tackle.mdlivestock_mayonnaise.mdvillagers_marriage.md모든 질문이 예상 문서에서 검색되어 답변에 문서 출처가 정상 출력되었습니다.
Group B 테스트 (RAG 실패 케이스 관찰)
PGVector
psycopg2미설치로 인한 에러 발생. FAISS 캐시 기반 베이스라인으로 대체.run.ipynb셀 9에 테이블로 문서화.다음 주 연결 포인트
Group B 질문들(멀티홉, 문서 부재)이 다음 주 Agentic RAG — groundedness check, query rewrite, web search fallback — 의 직접적인 입력 소재가 됩니다.