Skip to Content
RAG with Python 쿡북 (Korean Edition)
book

RAG with Python 쿡북 (Korean Edition)

by Dominik Polzer
May 2026
Intermediate
378 pages
5h 49m
Korean
O'Reilly Media, Inc.
Content preview from RAG with Python 쿡북 (Korean Edition)

제4장. 데이터 전처리

이 작품은 AI를 사용하여 번역되었습니다. 여러분의 피드백과 의견을 환영합니다: translation-feedback@oreilly.com

RAG 시스템에 긴 텍스트를 입력할 때, 전처리 과정은 문서를 더 작은 단위로 분할합니다. 각 단위는 그 의미적 내용을 포착하는 임베딩 벡터로 변환됩니다. 검색 과정에서 시스템은 관련 텍스트를 찾기 위해 이러한 벡터 간의 거리를 계산하여 유사성을 측정합니다.

이 방식은 각 청크가 정확히 하나의 정보를 포함하고 독립적으로 이해될 수 있을 때 가장 효과적입니다. 핵심 과제는 주변 문맥에 의존하지 않고도 독립적으로 성립하는 청크를 준비하는 것입니다. 견고한 처리 파이프라인은 원본 텍스트를 정리하고 적절한 지점에서 분할하여 의미 있는 청크를 생성합니다.

그림 4-1은 일반적인 자연어 처리( ) 전처리 기법을 보여줍니다:

텍스트 준비

약어를 대체하고 텍스트를 정리합니다.

메타데이터 수집

페이지 번호, 출처 및 저자를 저장합니다.

텍스트 분할

문자, 재귀, 의미론적 또는 에이전트 기반 청킹을 적용합니다.

목표는 주변 문맥에 의존하지 않는 명확하고 모호함이 없는 청크를 생성하는 것입니다.

Diagram illustrating the simplified RAG indexing pipeline, showing stages of processing, chunking, and embedding model.
그림 4-1. 잠재적인 데이터 처리기법을 포함한 단순화된 RAG 색인 생성파이프라인

검색 시 필터링이 가능하도록 각 청크에 유용한 메타데이터를 저장하면 프로세스의 속도와 정확도를 모두 높일 수 있습니다.

이 장의 모든 코드 예제는 책의 GitHub 저장소에서 확인할 수 있습니다.

4.1 메타데이터 필터링을 가능하게 하는 메타데이터 추가

문제

벡터 저장소에 텍스트 청크와 함께 메타데이터를 저장하여, 검색 시 메타데이터 필터링을 적용할 수 있도록 하고자 합니다.

해결 방안

문서에서 기존 메타데이터를 추출하고 추가 필드를 계산합니다. 특수한 사용 사례의 경우, 문서 콘텐츠에서 파생된 LLM 생성 메타데이터를 선택적으로 사용하여 문서와 함께 저장된 메타데이터를 보강할 수 있습니다. 다음 단계를 따르십시오:

  1. 문서에 이미 저장된 메타데이터(저자, 제목, 작성 날짜)를 추출합니다.

  2. 계산된 메타데이터 필드(파일 위치, 크기, 페이지 수, 텍스트 길이)를 추가합니다.

  3. (선택 사항) LLM을 사용하여 문서 텍스트를 분석함으로써 콘텐츠 기반 메타데이터를 생성합니다.

  4. 메타데이터를 텍스트 청크와 함께 저장합니다.

그림 4-2는 이 워크플로를 보여줍니다.

Diagram illustrating a four-step metadata extraction workflow involving text analysis, cloud processing, language model application, and metadata generation with examples of extracted metadata fields.
그림 4-2. 메타데이터 필드추출 및 생성

실습을 진행하려면 필요한 라이브러리를 설치하십시오:

pip install PyPDF2 openai pydantic

다음으로 PDF를 가져와 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Tips for Designing Effective Presentation Slide Decks

Tips for Designing Effective Presentation Slide Decks

Curtis Newbold
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
Three Essentials for Agentic AI Security

Three Essentials for Agentic AI Security

Paolo Dal Cin, Daniel Kendzior, Yusof Seedat, Renato Marinho
How to Overcome a Power Deficit

How to Overcome a Power Deficit

Cyril Bouquet, Jean-Louis Barsoux

Publisher Resources

ISBN: 0642572383596