RAG From Scratch: Part 1 (Overview)
Summary
TLDRランス氏は、新しいシリーズ「RAG from Scratch」を開始し、RAG(Retrieval-Augmented Generation)の基本原則から高度なトピックまで解説します。RAGの主な動機は、LLM(Large Language Models)が、プライベートデータや最新のデータなど、あなたが関心を持つかもしれないデータを見ているわけではないということです。また、LLMは、どんどん大きくなるコンテキストウィンドウを持っており、外部の情報を取り込むことができます。RAGは、インデックス作成、検索、生成という3つのステージを通じて行われます。まずは、外部文書をインデックス化し、入力クエリに基づいて簡単に検索できるようにします。次に、検索された文書をLLMにフィードし、検索された文書に基づいて回答を生成します。今後の動画では、これらの基本コンポーネントから派生する多くの興味深い方法やコツを詳細に説明します。また、コードウォークスルーも行い、実際にRAGパイプラインを構築する際に役立つlsmithキーを紹介します。
Takeaways
- 🚀 ランチェーンのLanceが、RAG(Retrieval-Augmented Generation)の基本原則を解説する新シリーズを開始します。
- 🔍 RAGの主な動機は、LLM(Large Language Models)が、プライベートデータや最新のデータを含むすべてのデータを見ているわけではないということです。
- 📈 LLMは、どんどん大きくなるコンテキストウィンドウを持っており、外部ソースからの情報を取り込める能力があります。
- 💡 RAGは、インデックス化、検索、生成の3つのステージを通じて、LLMに外部データを接続する一般的なパラダイムです。
- 📚 インデックス化の第1ステージでは、外部文書を入力クエリに基づいて簡単に検索できるようにします。
- 🔑 第2ステージの検索では、入力された質問に関連する文書を検索し、それらをLLMにフィードします。
- 📝 最後の生成ステージでは、検索された文書に基づいて答えが生成されます。
- 🌐 RAGは、新しいタイプのオペレーティングシステムのカーネルであり、外部データへの接続はその開発の中心的な能力です。
- 🛠️ ランチェーンは、RAGパイプラインの構築時にトレースと可視性のためにlsmithを使用することをお勧めしています。
- 📈 RAGのコードクイックスタートでは、文書を読み込み、分割、埋め込み、そしてベクトルストアにインデックス化します。
- 🔬 検索では、入力質問に基づいて関連文書を取得し、それらと質問をLLMに渡してフォーマットされた出力を生成します。
- 📊 lsmithを使用して、RAGの実行過程を可視化し、各ステップを確認できます。
Q & A
ランスが所属する組織の名前は何ですか?
-ランスは「Lang chain」という組織に所属しています。
「rag from scratch」というシリーズの目的は何ですか?
-「rag from scratch」は、RAG(Retrieval-Augmented Generation)の基本原則から高度なトピックまでを解説するシリーズです。
LLM(Large Language Models)が抱える主な課題は何ですか?
-LLMは、プライベートデータや最新のデータなど、あなたが関心を持つかもしれないデータを見ることができないという課題を抱えています。
LLMのコンテキストウィンドウが拡大する意味は何ですか?
-LLMのコンテキストウィンドウが拡大することで、外部の情報源から数十ページから数百ページまでの情報を取り込めるようになります。
RAGの3つの主要なステージは何ですか?
-RAGの3つの主要なステージは、インデックス作成、検索、そして生成です。
インデックス作成とは何を意味しますか?
-インデックス作成とは、外部ドキュメントを入力クエリに基づいて簡単に検索できるように整理するプロセスです。
ランスが使用しているベクトルストアの名前は何ですか?
-ランスが使用しているベクトルストアは「Chroma」です。
ドキュメントを分割することがなぜ重要ですか?
-ドキュメントを分割することは、各分割を埋め込み、ベクトルストアにインデックス登録するプロセスに重要です。
RAGのプロンプトとは何ですか?
-RAGのプロンプトとは、入力質問に応じて関連ドキュメントを取得し、それらをLLMにフィードして答えを生成するための指示です。
ランスが使用しているLLMの名前は何ですか?
-スクリプトにはLLMの名前が明示されていませんが、一般的に使用されるLLMの一例として、「Language Model」という名前にしておくことができます。
lsmithとは何ですか?
-lsmithは、RAGパイプラインのトレースや観測性向上に役立つツールです。
ランスが紹介するRAGクイックスタートのコードの目的は何ですか?
-RAGクイックスタートのコードは、RAGの基本的な動作を示すためで、ドキュメントの読み込み、分割、埋め込み、インデックス登録、検索、そして生成を実行するプロセスを示します。
Outlines
📚 ラグスクラッチシリーズ紹介
ランスが主催する「ラグスクラッチ」というシリーズが開始されます。このシリーズでは、RAG(Retrieval-Augmented Generation)の基本原則から高度なトピックまで解説していく予定です。RAGの主な動機は、LLM(Large Language Models)が扱えないプライベートデータや最新のデータを考慮しないという点にあります。また、LLMはどんどん広範囲のコンテキストウィンドウを持ち、外部データとの接続が重要な機能となっています。RAGには、インデックス作成、検索、生成という3つのステージが存在し、これからの動画ではこれらについて詳しく解説していく予定です。また、コードウォークスルーも行われ、実際にRAGパイプラインを構築する際に役立つlsmithというツールの使い方や、環境変数の設定方法も紹介されています。
🔍 RAGの仕組みと今後の予定
RAGの仕組みについて概要的に説明されており、今後の動画では各コンポーネントを詳しく解説する予定です。RAGは外部文書をインデックス化し、入力クエリに基づいて検索し、LLMにフィードして答えを生成するプロセスを経ます。また、今後の動画では、インデックス作成、検索、生成の各段階を詳細に解説し、さらに高度なトピックにも触れていく予定です。
Mindmap
Keywords
💡RAG(Retrieval-Augmented Generation)
💡LLM(Large Language Model)
💡検索(Retrieval)
💡生成(Generation)
💡インデックス(Indexing)
💡ベクトルストア(Vector Store)
💡プロンプト(Prompt)
💡ドキュメントプロセシング(Document Processing)
💡トークン(Token)
💡オープンAI埋め込み(OpenAI Embeddings)
💡lsmith
Highlights
Starting a new series called 'RAG from Scratch' to explore basic principles of Retrieval-Augmented Generation (RAG) and build up to advanced topics.
Motivation for RAG is to address the limitations of LLMs (Large Language Models) in handling private or very recent data not included in their pre-training.
LLMs have context windows that are increasing in size, allowing them to process more information from external sources.
RAG involves three stages: indexing, retrieval, and generation.
Indexing involves organizing external documents for easy retrieval based on input queries.
Retrieval stage fetches relevant documents to be used in the final generation stage of the LLM.
RAG is seen as a kernel of a new kind of operating system, with connecting to external data being a central capability.
The video series will cover various methods and tricks related to the three basic components of RAG.
Each video will be kept short, around five minutes, focusing on advanced topics.
Introduction to the basic ideas behind indexing, retrieval, and generation in the first three videos.
Interactive code walkthrough demonstrating a RAG quick start using a notebook and installed packages.
Explanation of using environment variables for LLM keys and the importance of tracing and observability in building RAG pipelines.
Loading and splitting documents into chunks for embedding and indexing into a vector store.
Use of OpenAI embeddings and Chroma for vector storage in a local setup.
Defining a prompt for RAG and setting up the LLM for document processing.
Chain setup to take input question, retrieve documents, and generate an answer grounded in retrieved documents.
Demonstration of using Llama (LLM) to trace and observe the RAG process.
Showcasing the retrieved documents and how they are used to answer the input question.
Providing a general overview of how RAG works with plans to break down each component in more detail in future videos.
Transcripts
hi this is Lance from Lang chain we're
starting a new series called rag from
scratch that's going to walk through
some of the basic principles for Rag and
kind of build up to Advanced
topics um so one of the main motivations
for rag is simply that llms haven't seen
all of the data that you may care about
so like private data or very recent data
would not be included in the
pre-training Run for these LMS and you
can see here on the graph on the xaxis
that the number of tokens that they're
pre-trained on which is of course very
large um but of course it's still always
going to be limited relative to private
data that you care about or for example
recent
data but there's another interesting
consideration is that llms have context
windows that are actually getting
increasingly large so you know coming
going from like thousands of tokens to
many thousands of tokens which
represents you know dozens of Pages up
to hundreds of pages we can fit
information into them from external
sources and a way to think about this is
llms are kind of a a kernel of a new
kind of operating system and connecting
them to external data is kind of a very
Central capability in the development of
this kind new emergent operating
system so retrieval alment to generation
or rag is a very popular kind of General
Paradigm for doing this which typically
involves three stages so the first stage
is indexing some external documents such
that they can be easily
retrieved based on an input query so for
example we ask a question we retrieve
documents that are relevant to that
question we feed those documents into an
llm in the final generation stage to
produce an answer that's grounded in
those retrieve
documents now we're starting from
scratch but we're going to kind of build
up to this broader view of rag you can
see here there's a lot of interesting
methods and tricks that kind of fan out
from those three basic components of
indexing retrieval and
generation and future videos are
actually going to walk through those in
detail we're going to try to keep each
video pretty short like five minutes but
we're going to spend a lot of time on
some of those more advanced
topics first over the next three videos
I'll just be laying out the very basic
kind of ideas behind indexing retrieval
and generation and then we'll kind of
build beyond that into those more
advanced
themes and now I want to show just a
quick code walkth through because we
want to make these videos also a little
bit
interactive so right here and this repo
will be shared it's public I have a a
notebook open and I've just just
basically installed a few
packages and I've set a few environment
variables for my lsmith keys which um I
personally do recommend it's really
useful for tracing
observability um particularly when
you're building rag
pipelines so what I'm going to show here
is the code for a rag quick start which
is linked here and I'm going to run this
but I'm then going to kind of walk
through everything that's going on so
actually if we think back to our diagram
all we're doing here is we're loading
documents in this case I'm loading a
blog post we're then splitting them and
we'll talk about that in future like uh
short videos on like why splitting is
important but just for now recognize
we're splitting them or setting a chunk
size of um you know a thousand
characters so we're splitting up our
documents every split is embedded and
indexed into this Vector store so we say
we picked open eye embeddings we're
using chromas our Vector storage runs
locally and now we' find this
retriever we then have defined a prompt
for
rag um we've defined our llm we've done
some minor document processing we set up
this
chain which will basically take our
input
question run our retriever to fetch
relevant documents put the retrieve
documents and our question into our
prompt pass it to the LM format the
output as a string and we can see here's
our
output now we can open up lsmith and we
can actually see
how this Ran So here was our question
and here's our output and we can
actually look here's our retriever here
is our retrieve documents so that's
pretty
nice and ultimately here was the prompt
that we actually passed into the LM
you're an assistant for QA task use the
following pieces of retrieve content to
answer the question here's our
question and then here's all the content
this we retrieved and that DRS
answer so this just gives a very general
overview of how rag works and in future
uh short videos we're going to like
break down each of these pieces and I in
in a lot more detail uh
thanks
Voir Plus de Vidéos Connexes
Reliable, fully local RAG agents with LLaMA3
RAG Evaluation (Document Relevance) | LangSmith Evaluations - Part 14
Building long context RAG with RAPTOR from scratch
「RAGは本当に必要か?」コンテキストウィンドウ拡大がRAGに与える影響とは(2024/3/20)
RAG Evaluation (Answer Correctness) | LangSmith Evaluations - Part 12
RAG (evaluate intermediate steps) | LangSmith Evaluations - Part 16
5.0 / 5 (0 votes)