ドキュメントローダーの統合

LangChainを使ったLLMアプリケーション開発

Jonathan Bennion

AI Engineer & LangChain Contributor

検索拡張生成(RAG)

  • 埋め込みを使用して、関連情報をプロンプト{{1}}に統合するために検索します

典型的なRAGワークフロー。

LangChainを使ったLLMアプリケーション開発

RAG開発のステップ

一般的なRAGワークフロー: ドキュメントローダー、ドキュメント分割器、保存と検索のプロセス。

LangChainを使ったLLMアプリケーション開発

LangChain ドキュメントローダー

  • システム統合のためにドキュメントを読み込み、構成するよう設計されたクラス
  • 一般的なファイル形式用のドキュメントローダー: .pdf, .csv
  • サードパーティ製ローダー: S3、.ipynb、.wav

document-loader.jpg

1 https://python.langchain.com/docs/integrations/document_loaders
LangChainを使ったLLMアプリケーション開発

PDFドキュメントローダー

  • pypdf パッケージのインストールが必要です: pip install pypdf
from langchain_community.document_loaders import PyPDFLoader

loader = PyPDFLoader("path/to/file/attention_is_all_you_need.pdf")
data = loader.load()
print(data[0])
Document(page_content='Provided proper attribution is provided, Google hereby grants 
permission to\nreproduce the tables and figures in this paper solely for use in [...]
LangChainを使ったLLMアプリケーション開発

CSVドキュメントローダー

from langchain_community.document_loaders.csv_loader import CSVLoader


loader = CSVLoader('fifa_countries_audience.csv')
data = loader.load()
print(data[0])
Document(page_content='country: United States\nconfederation: CONCACAF\npopulation_share: [...]
LangChainを使ったLLMアプリケーション開発

HTMLドキュメントローダー

  • unstructured パッケージのインストールが必要です: pip install unstructured
from langchain_community.document_loaders import UnstructuredHTMLLoader


loader = UnstructuredHTMLLoader("white_house_executive_order_nov_2023.html") data = loader.load()
print(data[0])
print(data[0].metadata)
page_content="To search this site, enter a search term\n\nSearch\n\nExecutive Order on the Safe, Secure,
and Trustworthy Development and Use of Artificial Intelligence\n\nHome\n\nBriefing Room\n\nPresidential
Actions\n\nBy the authority vested in me as President by the Constitution and the laws of the United
States of America, it is hereby ordered as follows: ..."

{'source': 'white_house_executive_order_nov_2023.html'}
LangChainを使ったLLMアプリケーション開発

練習しましょう!

LangChainを使ったLLMアプリケーション開発

Preparing Video For Download...