Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 4 · 3. Data Ingestion & Preparation
Lesson 22 of 68

Loaders: PDF, HTML, Text, Web

Why loading is lossy. Handling format ambiguities.

Derpx0610 Jan · 1 min read
LangChain Mastery
The Document Object & MetadataLoaders: PDF, HTML, Text, WebCleaning & NormalizationChunking: Why It ExistsRecursiveCharacterTextSplitterToken-Aware & Syntax-Aware SplittingMarkdown & Code SplittingMetadata Enrichment StrategiesDeduplication via Content HashingLazy Loading & Generators
Contents
1. Loading is Interpretation2. TextLoader (The Baseline)3. WebBaseLoader (The Scraper)4. PyPDFLoader (The Nightmare)5. Summary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
The Document Object & MetadataLoaders: PDF, HTML, Text, WebCleaning & NormalizationChunking: Why It ExistsRecursiveCharacterTextSplitterToken-Aware & Syntax-Aware SplittingMarkdown & Code SplittingMetadata Enrichment StrategiesDeduplication via Content HashingLazy Loading & Generators
Contents
1. Loading is Interpretation2. TextLoader (The Baseline)3. WebBaseLoader (The Scraper)4. PyPDFLoader (The Nightmare)5. Summary

1. Loading is Interpretation

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."

2. TextLoader (The Baseline)

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.

3. WebBaseLoader (The Scraper)

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.

4. PyPDFLoader (The Nightmare)

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.

5. Summary

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."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonThe Document Object & MetadataNext lesson →Cleaning & Normalization