Retrieval-Augmented Generation (RAG)란 무엇인가요?

Retrieval-Augmented Generation (RAG) is an AI architecture that combines a large language model with an external knowledge retrieval step, so the model can look up relevant documents before producing an answer. This grounding in retrieved, up-to-date sources helps reduce hallucinations and lets the system answer questions about information it was not explicitly trained on.

검색 증강 생성(Retrieval-Augmented Generation, RAG)은 AI 시스템을 구축하기 위한 기법으로, 언어 모델이 질문에 답하기 전에 외부 문서를 참조할 수 있게 해 줍니다. 학습 중에 배운 내용만 활용하는 대신, RAG 파이프라인은 먼저 사용자 질의와 관련된 구절을 지식 베이스에서 검색한 다음, 그 구절들을 컨텍스트로 모델에 전달합니다. 그 결과는 모델의 내부 가중치만이 아니라 특정하고 인용 가능한 소스에 근거한 생성된 응답입니다.

검색 증강 생성의 작동 원리

일반적인 RAG 시스템은 두 가지 주요 구성 요소, 즉 리트리버(retriever)와 제너레이터(generator)로 이루어져 있습니다. 리트리버는 보통 문서 코퍼스로부터 구축된 벡터 검색 인덱스입니다. 각 문서가 인덱스에 추가될 때 임베딩 모델이 그 청크들을 수치 벡터로 변환하고, 동일한 모델이 들어오는 사용자 질의를 임베딩하며, 유사도 검색(보통 코사인 또는 내적 거리를 사용하는 최근접 이웃 조회)이 쿼리와 벡터가 가장 가까운 청크들을 반환합니다. 그다음 상위 랭크의 청크들이 대형 언어 모델에 전송되는 프롬프트에 삽입되며, 종종 "제공된 컨텍스트만 사용하여 답하라"와 같은 지시와 함께 전달됩니다.

예를 들어, 사용자가 사내 회사 어시스턴트에게 "우리의 parental leave 정책은 무엇인가요?"라고 묻는다면, 리트리버는 직원 핸드북의 관련 섹션을 찾아내고, 언어 모델은 그 구절들을 활용해 해당 정책을 인용하는 정확한 답변을 작성합니다. Facebook AI Research의 Lewis 등이 2020년 논문에서 소개한 이 패턴은 지식(인덱스에 저장됨)과 추론(모델이 수행)을 분리하기 때문에, 소스 자료가 변경되더라도 이 접근 방식이 잘 확장됩니다.

이 기법이 중요한 이유

RAG는 단독 언어 모델에 존재하는 세 가지 지속적 문제를 해결합니다. 첫째, 모델이 즉흥적으로 답변하지 않고 검색된 텍스트에 고정되기 때문에 환각이 줄어듭니다. 둘째, 인덱스만 업데이트하면 되므로 모델의 학습 시점 이후에 존재하지 않았거나 변경된 정보를 시스템이 반영할 수 있습니다. 셋째, 모델의 답변을 더 검증 가능하게 만듭니다. 개발자와 사용자는 검색된 청크를 검사하고, 인용하며, 모든 주장을 소스 문서까지 추적할 수 있습니다.

이러한 특성 덕분에 RAG는 엔터프라이즈 질의응답, 고객 지원 코파일럿, 법률 및 컴플라이언스 검색, 그리고 기본 모델을 재학습시키지 않고 비공개 또는 독점 데이터를 대상으로 작동해야 하는 AI 어시스턴트의 기본 패턴이 되었습니다.

주요 유형과 패턴

  • Naive(또는 "검색 후 읽기") RAG: 단일 검색 단계가 상위 k개 청크를 제너레이터의 프롬프트에 직접 전달합니다.
  • Advanced RAG: 생성 전에 쿼리 재작성, 리랭킹, 청크 단위 필터링을 추가해 정확도를 높입니다.
  • Modular RAG: 웹 검색, SQL 조회, API 호출 등 교체 가능한 구성 요소로 파이프라인을 조립하며, 검색과 생성 사이를 반복할 수도 있습니다.
  • Graph RAG: 코퍼스로부터 지식 그래프를 구축하고 관련 엔터티의 서브그래프를 검색하여, 연결된 데이터에 대해 더 맥락적인 답변을 생성할 수 있습니다.
  • Agentic RAG: 언어 모델이 최종 답변을 생성하기 전에 언제, 무엇을 검색할지를 직접 결정하며, 종종 여러 도구에 걸쳐 이를 수행합니다.

지식의 저장과 추론 엔진을 분리함으로써, RAG는 정확하고, 최신이며, 감사 가능한 프로덕션 AI 애플리케이션을 위한 핵심 구성 요소로 자리 잡았습니다. 원래 연구는 Lewis 등, "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks" (2020)에 기술되어 있으며, 현재의 모범 사례는 LlamaIndexLangChain 같은 프레임워크에 문서화되어 있습니다.

Frequently Asked Questions

How is RAG different from fine-tuning a language model?
Fine-tuning bakes new knowledge and behavior into a model's weights by continuing training on example data, which is expensive and must be repeated whenever the source material changes. RAG leaves the model unchanged and instead supplies relevant documents at inference time, so knowledge can be updated by simply editing the search index. The two approaches are complementary and are often combined in production systems.
What is a vector database and why does RAG need one?
A vector database stores documents (or chunks of them) as numerical embeddings produced by an embedding model. RAG needs it because retrieving by meaning, rather than exact keywords, requires comparing the query's embedding to every candidate's embedding and returning the nearest matches. Specialized vector stores such as FAISS, Pinecone, Weaviate, and pgvector make this nearest-neighbor search fast at scale.
Does RAG eliminate hallucinations?
No system fully eliminates hallucinations, but RAG significantly reduces them by forcing the model to answer from supplied context. Errors can still occur if the retriever returns irrelevant or low-quality chunks, if the source documents themselves are wrong, or if the model misinterprets the retrieved text. Best-practice pipelines add re-ranking, citation checks, and guardrails to catch these cases.
What kind of data can a RAG system search over?
Almost any text-based corpus: PDFs, wikis, help-center articles, code repositories, product catalogs, legal contracts, internal chat logs, and web pages. After appropriate parsing and chunking, the content is embedded and indexed, and the same RAG pipeline can serve many domains. Multimodal RAG extensions can also retrieve images, tables, and audio.