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)

제5장. 임베딩

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

임베딩 모델은 텍스트, 이미지 및 기타 콘텐츠를 의미적 의미를 포착하는 벡터로 변환합니다. RAG 시스템에서 이러한 벡터를 통해 리트리버는 방대한 비정형 컬렉션에서 사용자의 질문과 관련된 콘텐츠를 검색할 수 있습니다. 리트리버는 쿼리를 임베딩하고, 이를 벡터 데이터베이스에 저장된 벡터와 비교한 후, 거리 값에 따라 후보를 순위를 매깁니다. 거리 값이 작을수록 의미적 유사성이 높음을 나타내며, 이는 LLM의 제한된 컨텍스트 윈도우에 어떤 내용이 포함될지를 결정합니다.

일반적인 임베딩 기반 검색 흐름은 다음과 같습니다:

  1. 벡터 데이터베이스를 구축할 때 문서를 청크로 분할하여 임베딩합니다.

  2. 들어오는 각 사용자 쿼리를 동일한 모델로 임베딩합니다.

  3. 쿼리 벡터와 저장된 벡터 간의 거리를 계산합니다.

  4. 가장 가까운 청크를 검색하여 컨텍스트로 LLM에 전달합니다.

이 장에서는 OpenAI, Google 및 오픈 소스 프로젝트와 같은 제공업체의 임베딩 모델을 활용하는 방법을 다룹니다. 임베딩을 생성하고, 의미적 관계를 시각화하며, 벡터 간 거리를 측정하고, 이를 실제 RAG 파이프라인에 적용하는 방법을 배웁니다. 또한 모델 선택, 다중 모달 임베딩, 벡터와 키워드 또는 메타데이터 필터를 결합한 하이브리드 검색에 대한 내용도 포함됩니다.

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

5.1 텍스트 청크의 언어적 의미를 수치적 표현으로 매핑하기

문제

단어와 문장의 의미적 의미를 수치적 표현으로 매핑하고자 합니다.

해결책

임베딩 모델( )을 사용하여 텍스트를 수치 벡터로 변환합니다. 다음 코드 예제는 OpenAI 및 오픈 소스 모델을 사용하여 이를 보여줍니다. 그림 5-1은 결과 벡터가 의미적으로 유사한 텍스트를 임베딩 공간에서 더 가깝게 배치하는 방식을 보여줍니다.

Diagram showing an embedding model converting phrases like "cat videos online" and "endless procrastination" into vectors, illustrating semantic similarity positioning in vector space.
그림 5-1. 벡터 공간에서 텍스트 청크 간의의미적 유사성

텍스트 청크의 최대 크기는 임베딩 모델이 지원하는 최대 토큰 길이를 초과할 수 없습니다. 표 5-1은 널리 사용되는 임베딩 모델의 최대 토큰 윈도우와 차원 수를 보여줍니다.

표 5-1. 최신 임베딩 모델
모델 회사 플랫폼 최대 토큰 수 차원

text-embedding-3-small

OpenAI

OpenAI API

8,191

1,536

voyage-large-2 instruct

Voyage AI

Voyage API

16,000

1,536

text-embedding-005

Google

Gemini API

2,048

768

all-MiniLM-L6-v2

오픈 소스

Hugging Face

512

384

이 레시피에는 두 가지 샘플 ...

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