การรวม document loaders

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

Jonathan Bennion

AI Engineer & LangChain Contributor

Retrieval Augmented Generation (RAG)

  • ใช้ embeddings เพื่อ ดึง ข้อมูลที่เกี่ยวข้องมาผสานใน prompt

ขั้นตอนการทำงานของ RAG โดยทั่วไป

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

ขั้นตอนการพัฒนา RAG

ขั้นตอนการทำงานของ RAG: document loader, document splitter และกระบวนการจัดเก็บและเรียกข้อมูล

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

LangChain document loaders

  • คลาสที่ออกแบบมาเพื่อ โหลด และ กำหนดค่า เอกสารสำหรับการรวมเข้ากับระบบ
  • Document loaders สำหรับประเภทไฟล์ทั่วไป: .pdf, .csv
  • Loader ของบุคคลที่สาม: S3, .ipynb, .wav

document-loader.jpg

1 https://python.langchain.com/docs/integrations/document_loaders
การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

PDF document loader

  • ต้องติดตั้งแพ็กเกจ 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 [...]
การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

CSV document loader

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: [...]
การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

HTML document loader

  • ต้องติดตั้งแพ็กเกจ 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'}
การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

มาฝึกกันเถอะ!

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

Preparing Video For Download...