Tích hợp bộ tải tài liệu

Phát triển ứng dụng LLM với LangChain

Jonathan Bennion

AI Engineer & LangChain Contributor

Retrieval Augmented Generation (RAG)

  • Dùng embeddings để truy xuất thông tin liên quan và đưa vào prompt

Một quy trình RAG điển hình.

Phát triển ứng dụng LLM với LangChain

Các bước phát triển RAG

Quy trình RAG tổng quát: bộ tải tài liệu, bộ chia tài liệu, và quá trình lưu trữ/truy xuất.

Phát triển ứng dụng LLM với LangChain

Bộ tải tài liệu LangChain

  • Các lớp dùng để tảicấu hình tài liệu cho tích hợp hệ thống
  • Bộ tải cho định dạng phổ biến: .pdf, .csv
  • Bộ tải bên thứ ba: S3, .ipynb, .wav

document-loader.jpg

1 https://python.langchain.com/docs/integrations/document_loaders
Phát triển ứng dụng LLM với LangChain

Bộ tải tài liệu PDF

  • Yêu cầu cài gói 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 [...]
Phát triển ứng dụng LLM với LangChain

Bộ tải tài liệu 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: [...]
Phát triển ứng dụng LLM với LangChain

Bộ tải tài liệu HTML

  • Yêu cầu cài gói 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'}
Phát triển ứng dụng LLM với LangChain

Ayo berlatih!

Phát triển ứng dụng LLM với LangChain

Preparing Video For Download...