"이 정보는 어디서 나온 거야?"
LLM에게 질문했는데 그럴듯하지만 완전히 틀린 답변을 받아본 적 있으신가요?
이것이 바로 환각(Hallucination) 문제입니다.
"Where did this information come from?"
Have you ever asked an LLM a question and received a plausible but completely wrong answer?
This is the hallucination problem.
2025년, 이 문제를 해결하는 가장 효과적인 방법이 바로 RAG(Retrieval-Augmented Generation, 검색 증강 생성)입니다. RAG는 LLM이 답변하기 전에 관련 문서를 검색하여 참조하게 만들어, 정확하고 신뢰할 수 있는 응답을 생성합니다.
In 2025, the most effective solution to this problem is RAG (Retrieval-Augmented Generation). RAG makes LLMs search and reference relevant documents before answering, generating accurate and reliable responses.
RAG란 무엇인가? What is RAG?
RAG는 두 가지 핵심 기술을 결합합니다: 검색(Retrieval)과 생성(Generation). 사용자 질문이 들어오면, 먼저 관련 문서를 검색하고, 그 문서를 컨텍스트로 제공하여 LLM이 답변을 생성하게 합니다.
RAG combines two key technologies: Retrieval and Generation. When a user question comes in, it first retrieves relevant documents, then provides them as context for the LLM to generate an answer.
💡 RAG의 핵심 장점 💡 Key Benefits of RAG
- 환각 감소: 실제 문서 기반 답변으로 정확도 향상
- 최신 정보: LLM 학습 이후 데이터도 활용 가능
- 출처 추적: 답변의 근거 문서를 명시 가능
- 도메인 특화: 기업 내부 문서로 맞춤형 AI 구축
- 비용 효율: 파인튜닝 없이 지식 업데이트
- Reduced hallucination: Improved accuracy with document-based answers
- Up-to-date info: Can use data after LLM training cutoff
- Source tracking: Can cite reference documents
- Domain-specific: Build custom AI with internal docs
- Cost-effective: Update knowledge without fine-tuning
RAG 아키텍처 이해하기 Understanding RAG Architecture
RAG 시스템은 크게 두 단계로 나뉩니다: 인덱싱(준비)과 쿼리(실행).
RAG systems are divided into two main phases: Indexing (Preparation) and Query (Execution).
1단계: 인덱싱 (문서 준비) Phase 1: Indexing (Document Preparation)
문서 로드
Load Documents
PDF, 웹페이지, DB 등 다양한 소스에서 문서를 수집합니다.
Collect documents from various sources: PDF, web pages, databases, etc.
청킹 (Chunking)
Chunking
긴 문서를 검색에 적합한 작은 조각(chunk)으로 분할합니다.
Split long documents into smaller chunks suitable for retrieval.
임베딩 생성
Generate Embeddings
각 청크를 벡터(숫자 배열)로 변환합니다. 의미가 비슷한 텍스트는 비슷한 벡터가 됩니다.
Convert each chunk into a vector (array of numbers). Similar texts become similar vectors.
벡터 DB 저장
Store in Vector DB
임베딩을 벡터 데이터베이스에 저장하여 빠른 유사도 검색을 가능하게 합니다.
Store embeddings in a vector database for fast similarity search.
2단계: 쿼리 (실행) Phase 2: Query (Execution)
질문 임베딩
Embed Query
사용자 질문을 동일한 임베딩 모델로 벡터화합니다.
Convert user question to vector using the same embedding model.
유사 문서 검색
Retrieve Similar Documents
벡터 DB에서 질문과 가장 유사한 청크들을 검색합니다.
Search the vector DB for chunks most similar to the question.
프롬프트 구성
Construct Prompt
검색된 문서와 사용자 질문을 결합하여 LLM 프롬프트를 만듭니다.
Combine retrieved documents with user question to create LLM prompt.
LLM 응답 생성
Generate LLM Response
LLM이 컨텍스트를 참조하여 정확한 답변을 생성합니다.
LLM generates accurate answer by referencing the context.
주요 벡터 DB 비교 Vector Database Comparison
서버리스 옵션
Serverless option
로컬 개발에 최적
Best for local dev
GraphQL 지원
GraphQL support
| 기능 | Pinecone | Chroma | Weaviate |
|---|---|---|---|
| 호스팅 | 클라우드 전용 | 로컬/클라우드 | 로컬/클라우드 |
| 가격 | 유료 (무료 티어) | 무료 (오픈소스) | 무료 (오픈소스) |
| 설정 난이도 | 쉬움 | 매우 쉬움 | 보통 |
| 하이브리드 검색 | ✅ | ⚠️ 제한적 | ✅ |
| 프로덕션 추천 | ✅ 우수 | ⚠️ 소규모 | ✅ 우수 |
| Feature | Pinecone | Chroma | Weaviate |
|---|---|---|---|
| Hosting | Cloud only | Local/Cloud | Local/Cloud |
| Pricing | Paid (free tier) | Free (open source) | Free (open source) |
| Setup difficulty | Easy | Very easy | Moderate |
| Hybrid search | ✅ | ⚠️ Limited | ✅ |
| Production ready | ✅ Excellent | ⚠️ Small scale | ✅ Excellent |
LangChain으로 RAG 구현하기 Implementing RAG with LangChain
LangChain은 RAG 파이프라인을 쉽게 구축할 수 있는 인기 프레임워크입니다. 다음은 기본적인 RAG 시스템 구현 예제입니다.
LangChain is a popular framework for easily building RAG pipelines. Here's a basic RAG system implementation example.
from langchain_community.document_loaders import PyPDFLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from langchain_community.vectorstores import Chroma
from langchain.chains import RetrievalQA
# 1. 문서 로드
loader = PyPDFLoader("company_docs.pdf")
documents = loader.load()
# 2. 청킹
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=1000,
chunk_overlap=200
)
chunks = text_splitter.split_documents(documents)
# 3. 임베딩 및 벡터 DB 저장
embeddings = OpenAIEmbeddings()
vectorstore = Chroma.from_documents(chunks, embeddings)
# 4. RAG 체인 생성
llm = ChatOpenAI(model="gpt-4")
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
retriever=vectorstore.as_retriever()
)
# 5. 질문하기
result = qa_chain.invoke("회사의 휴가 정책은?")
print(result)
RAG 성능 최적화 전략 RAG Performance Optimization Strategies
🚀 청킹 최적화 🚀 Chunking Optimization
- 청크 크기: 너무 작으면 컨텍스트 손실, 너무 크면 노이즈 증가 (500-1500자 권장)
- 오버랩: 청크 간 10-20% 오버랩으로 문맥 연결 유지
- 시맨틱 청킹: 단순 길이 대신 의미 단위로 분할
- Chunk size: Too small loses context, too large adds noise (500-1500 chars recommended)
- Overlap: 10-20% overlap between chunks maintains context
- Semantic chunking: Split by meaning instead of length
🔍 검색 최적화 🔍 Retrieval Optimization
- 하이브리드 검색: 벡터 검색 + 키워드 검색 결합
- 리랭킹: 검색 결과를 재정렬하여 관련성 향상
- 메타데이터 필터: 날짜, 카테고리 등으로 검색 범위 제한
- Hybrid search: Combine vector + keyword search
- Reranking: Reorder results for better relevance
- Metadata filters: Limit search by date, category, etc.
RAG vs 파인튜닝: 언제 무엇을? RAG vs Fine-tuning: When to Use What?
📊 RAG를 선택해야 할 때 📊 When to Choose RAG
- 지식이 자주 업데이트되는 경우
- 출처 추적이 중요한 경우
- 비용과 시간이 제한된 경우
- 도메인 지식만 추가하면 되는 경우
- Knowledge updates frequently
- Source tracking is important
- Limited budget and time
- Just need to add domain knowledge
🎯 파인튜닝을 선택해야 할 때 🎯 When to Choose Fine-tuning
- 특정 작성 스타일/톤이 필요한 경우
- 모델의 행동 패턴을 바꿔야 하는 경우
- 응답 형식을 엄격히 통제해야 하는 경우
- 복잡한 도메인 추론이 필요한 경우
- Need specific writing style/tone
- Need to change model behavior patterns
- Strict response format control needed
- Complex domain reasoning required
실무 적용 사례 Real-World Use Cases
RAG는 다양한 산업에서 활용되고 있습니다.
RAG is being used across various industries.
- 고객 지원: 제품 매뉴얼 기반 자동 응답 시스템
- 법률: 판례와 법령 검색 및 분석
- 의료: 의학 문헌 기반 진단 보조
- 금융: 규정 준수 문서 검색 및 해석
- 개발: 내부 문서 기반 코드 생성 도우미
- Customer support: Auto-response based on product manuals
- Legal: Case law and regulation search & analysis
- Healthcare: Medical literature-based diagnosis assistance
- Finance: Compliance document search & interpretation
- Development: Code assistant based on internal docs
결론: RAG로 신뢰할 수 있는 AI 구축하기 Conclusion: Building Trustworthy AI with RAG
RAG는 LLM의 환각 문제를 해결하고, 신뢰할 수 있는 AI 시스템을 구축하는 핵심 기술입니다. 벡터 DB와 임베딩을 활용하여 기업 내부 지식을 AI에 연결하면, 정확하고 최신의 정보를 기반으로 답변하는 맞춤형 AI 어시스턴트를 만들 수 있습니다.
RAG is the key technology for solving LLM hallucination and building trustworthy AI systems. By connecting enterprise knowledge to AI using vector DBs and embeddings, you can create custom AI assistants that answer based on accurate, up-to-date information.
"RAG는 AI를 '아는 척하는' 시스템에서 '실제로 아는' 시스템으로 바꿔줍니다." "RAG transforms AI from 'pretending to know' to 'actually knowing'."
