Skip to content
derpx06Notes on systems, models & learning
3. Data Ingestion & Preparation · lesson 22 of 68 · 1 min · January 10, 2026

Loaders: PDF, HTML, Text, Web

Why loading is lossy. Handling format ambiguities.

A "Loader" in LangChain connects to a data source (File, API, Database) and returns a list of Document objects.

This sounds simple, but it is lossy. When you load a PDF, you lose vector graphics, exact positioning, and font sizes. When you load HTML, you lose CSS visibility rules (hidden text might be loaded).

You are translating "Visual Layout" into "Linear Text."

The simplest loader. It reads a file .txt and returns one Document.

loader_text.py
from langchain_community.document_loaders import TextLoader

loader = TextLoader("./note.txt")
docs = loader.load()

Use Case: Code, Markdown,logs. 1:1 fidelity.

Extracting text from the web is messy. Websites have navbars, ads, and footers. Using WebBaseLoader (packaged with BeautifulSoup) allows you to target specific <div> tags.

loader_web.py
from langchain_community.document_loaders import WebBaseLoader

loader = WebBaseLoader("https://example.com")
docs = loader.load()
# Warning: This often loads "Privacy Policy" and "Login" text.

Pro Tip: Always post-process web content. The "noise" ratio is high.

PDF is a print format, not a data format. It doesn't know what a "paragraph" is; it only knows "character 'A' at position x=10, y=20".

Loaders try to reconstruct the text flow, but they fail on:

  1. Multi-column layouts: It might read across columns (combining line 1 of col A with line 1 of col B).
  2. Tables: It extracts cell contents locally, destroying the row/column relationship.
loader_pdf.py
from langchain_community.document_loaders import PyPDFLoader

loader = PyPDFLoader("./report.pdf")
docs = loader.load_and_split() 
# By default, it splits by Page number.

Loading is not passive. It is an active choice about what to keep and what to throw away. For PDFs and Complex HTML, "Standard" loaders are rarely enough for production. You often need specialized tools (like Unstructured.io or Azure Layout).

Key Intuition: "Fidelity lost at loading is lost forever."