0Pricing
LLM Apps in Production (RAG + Vector DB + Caching) · บทเรียน

การโหลดเอกสารหลากหลายรูปแบบ

สำรวจวิธีนำเข้าข้อมูลจากแหล่งต่าง ๆ เช่น PDF หน้าเว็บ ฐานข้อมูล และไฟล์รูปแบบกำหนดเอง

การโหลดเอกสารหลากหลายรูปแบบ เป็นบทเรียน LLM Apps in Production (RAG + Vector DB + Caching) ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน LLM Apps in Production (RAG + Vector DB + Caching) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส LLM Apps in Production (RAG + Vector DB + Caching) มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Ingesting Diverse Document Types

Welcome! In RAG, your LLM needs information from various sources. This lesson explores how to load data from different document formats into your application.

The goal is to get raw text from places like web pages, PDFs, and databases, preparing it for the next steps in your RAG pipeline.

Loading Web Pages (HTML)

Web pages are a common source of information. To ingest them, you typically:

  • Fetch the HTML: Use an HTTP client to download the page content from a URL.
  • Parse the HTML: Extract the main text and discard navigation, ads, and other irrelevant elements.

Libraries like requests for fetching and BeautifulSoup for parsing are very popular in Python.

Web Page Loading Example

This Python snippet demonstrates fetching a simple web page and extracting its title. Imagine doing this for many pages to build your knowledge base!

import requests
from bs4 import BeautifulSoup

def main():
    url = "http://quotes.toscrape.com/"
    try:
        response = requests.get(url)
        response.raise_for_status() # Raise HTTPError for bad responses
        soup = BeautifulSoup(response.text, 'html.parser')
        title = soup.find('title').get_text()
        print(f"Page Title: {title}")
    except requests.exceptions.RequestException as e:
        print(f"Error fetching URL: {e}")

if __name__ == "__main__":
    main()

Extracting Text from PDFs

PDFs (Portable Document Format) are widely used for reports and documents. Extracting text from PDFs can be tricky due to their complex structure, which combines text, images, and formatting.

Fortunately, programming libraries exist to help. They can read the PDF structure and pull out the textual content, often page by page.

PDF Text Extraction Example

This conceptual Python code shows how you might extract text from the first page of a PDF using a library like pypdf. For a real run, you'd need a sample.pdf file.

from pypdf import PdfReader

def main():
    # In a real scenario, 'sample.pdf' would exist
    # For this example, we'll simulate the output
    pdf_file_path = "sample.pdf"
    print(f"Attempting to read from: {pdf_file_path}")
    print("\n--- Simulated PDF Content ---")
    print("This is some text from the first page of a sample PDF document.")
    print("It contains important information for our RAG system.")
    print("-----------------------------")
    # Actual code might look like this:
    # reader = PdfReader(pdf_file_path)
    # page = reader.pages[0]
    # text = page.extract_text()
    # print(text)

if __name__ == "__main__":
    main()

Loading Data from Databases

Databases, both SQL (like PostgreSQL, MySQL) and NoSQL (like MongoDB, Cassandra), store structured data that can be valuable for RAG.

To ingest from databases:

  • Connect: Establish a connection using database drivers.
  • Query: Write queries (e.g., SQL statements) to retrieve relevant data.
  • Process: Extract text fields from the query results.

Database Loading Example

Here's a Python example using SQLite, an embedded SQL database. It creates a simple table, inserts data, and then retrieves it. This is a common pattern for database ingestion.

import sqlite3

def main():
    # Connect to an in-memory SQLite database
    conn = sqlite3.connect(':memory:')
    cursor = conn.cursor()

    # Create a simple table
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS documents (
            id INTEGER PRIMARY KEY,
            title TEXT,
            content TEXT
        )
    ''')

    # Insert some data
    cursor.execute("INSERT INTO documents (title, content) VALUES (?, ?)", 
                   ("RAG Overview", "RAG enhances LLMs by retrieving relevant docs."))
    cursor.execute("INSERT INTO documents (title, content) VALUES (?, ?)", 
                   ("Vector DBs", "Store embeddings for fast similarity search."))
    conn.commit()

    # Retrieve data
    cursor.execute("SELECT title, content FROM documents")
    rows = cursor.fetchall()

    print("--- Retrieved Documents ---")
    for row in rows:
        print(f"Title: {row[0]}, Content: {row[1]}")
    print("---------------------------")

    conn.close()

if __name__ == "__main__":
    main()

Handling Plain Text & Custom Files

Beyond specific formats, you'll often deal with plain text files (.txt, .md) or custom formats (e.g., CSV, JSON). For these:

  • Plain Text: Read directly, paying attention to encoding (UTF-8 is common).
  • Custom Formats: Use libraries specific to the format (e.g., csv, json modules in Python) to parse and extract text fields.

The key is transforming the data into a usable text string.

Unified Data Loading with Libraries

For complex RAG systems, you don't always need to write custom loaders for every format. Libraries like LlamaIndex and LangChain offer 'Document Loaders' that abstract away much of this complexity.

  • They provide connectors for many data sources (web, PDF, databases, cloud storage).
  • They often handle basic parsing and text extraction automatically.

These tools simplify the initial ingestion step, letting you focus on retrieval and generation.

Check Your Knowledge

Which of the following is typically a primary challenge when extracting text content from PDF documents for a RAG system?

Recap: Loading Diverse Data

Great job! You've learned the fundamentals of loading diverse document formats for your RAG system.

  • We covered fetching and parsing web pages.
  • Discussed extracting text from complex PDFs.
  • Explored querying databases for structured content.
  • Touched upon handling plain text and other custom files.
  • Recognized the value of unified data loading libraries.

The next step is to prepare this raw text for effective retrieval!

คำถามที่พบบ่อย

บทเรียน “การโหลดเอกสารหลากหลายรูปแบบ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การโหลดเอกสารหลากหลายรูปแบบ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส LLM Apps in Production (RAG + Vector DB + Caching) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส LLM Apps in Production (RAG + Vector DB + Caching) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การโหลดเอกสารหลากหลายรูปแบบ”

สำรวจวิธีนำเข้าข้อมูลจากแหล่งต่าง ๆ เช่น PDF หน้าเว็บ ฐานข้อมูล และไฟล์รูปแบบกำหนดเอง คุณปฏิบัติ LLM Apps in Production (RAG + Vector DB + Caching) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน LLM Apps in Production (RAG + Vector DB + Caching) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน LLM Apps in Production (RAG + Vector DB + Caching) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “การโหลดเอกสารหลากหลายรูปแบบ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน LLM Apps in Production (RAG + Vector DB + Caching) นี้ได้ไหม

ได้ บทเรียน LLM Apps in Production (RAG + Vector DB + Caching) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การโหลดเอกสารหลากหลายรูปแบบ
  2. กลยุทธ์การแบ่งข้อความตามบริบท
  3. การจัดการและกรองข้อมูลเมทาดาทา
  4. ทำความสะอาดและลบข้อมูลต้นฉบับที่ซ้ำกัน
← กลับไปที่ LLM Apps in Production (RAG + Vector DB + Caching)