Real-world examples — click to preview:
The Document is the universal container in LangChain's RAG pipeline — it carries raw text
(page_content) and
traceability data (metadata)
from ingestion all the way to retrieval.
01 · Foundation
Every file you ingest — PDF, webpage, CSV row, or API response — becomes one or more
Document objects. These are the atomic units
passed to embedders, vector stores, and retrievers. LangChain v0.3+ splits packages: core types live in
langchain_core, loaders in
langchain_community, splitters in
langchain_text_splitters.
A lightweight dataclass with three fields. You rarely subclass it — instead, loaders and splitters produce Documents automatically.
02 · Anatomy
Click any example or metadata field below to see how a real Document object is assembled. Good metadata design is often more important than chunk size for production RAG quality.
Real-world examples — click to preview:
Click fields to toggle in live preview:
chunk_index and parent_id
when splitting — helps reconstruct full sections and debug retrieval gaps.
id prevents duplicate vectors.
Convention: {source}-p{page}-chunk{index}
This is the exact object shape your vector store receives after loading and splitting.
03 · Context
Documents are the handoff format between every stage. Understanding this flow clarifies why loaders, splitters, and metadata design all matter.
Read raw files (PDF, HTML, CSV) and output List[Document]
Break large docs into chunk-sized Documents. Metadata is inherited + enriched.
embeddings.embed_documents([d.page_content])
Stores vectors + metadata. Chroma, Pinecone, FAISS, pgvector.
Top-k chunks injected into prompt. Metadata shown as citations.
04 · Ingestion
Loaders handle the "messy" part — parsing binary formats, fetching URLs, walking directories.
They all return the same Document type.
pip install langchain langchain-community langchain-core langchain-text-splitters pypdf pymupdf docx2txt jq tiktoken unstructured networkx msoffcrypto-tool.
Each loader implements .load() → list of Documents
or .lazy_load() for memory-efficient streaming on large corpora.
Click a card for details. Cards below map to this week's notebooks.
glob="**/*.txt" to batch-load a folder.
Always set encoding="utf-8" on Windows.
metadata["source"] and metadata["page"].
PyMuPDFLoader is faster with richer metadata. Clean ligatures/whitespace before chunking
(see SmartPDFProcessor in notebook 2).
data/pdf/attention.pdfpassword=mode="elements".
metadata["row"].
For Excel, use pandas per-sheet docs or UnstructuredExcelLoader.
Custom processing adds rich metadata (category, price) for filtering.
pip install jq. The jq_schema extracts subtrees (e.g. each employee).
For complex nesting, flatten to natural-language profiles with custom Python (see notebook 5).
SQLDatabase exposes schema for Text-to-SQL agents. For RAG ingestion, convert tables
and JOIN results into readable Documents (employee–project relationships).
Also in the ecosystem (not covered this week):
05 · Chunking
Embedding models have token limits. Splitters convert one large Document into many smaller ones while preserving metadata — each child chunk knows its source file and page.
pip install langchain-text-splitters tiktoken.
Import from langchain_text_splitters (not deprecated langchain.text_splitter).
RecursiveCharacterTextSplitter is the default choice for most RAG apps.
Click a splitter to simulate chunking on your preview text above.
06 · Lab
Each Jupyter notebook installs dependencies via a Colab-ready %pip install cell,
then walks through one data format. No .env or API keys required — ingestion is fully local.
| # | Notebook | Focus |
|---|---|---|
| 1 | 1-dataingestion.ipynb | Document model, TextLoader, DirectoryLoader, splitters |
| 2 | 2-dataparsingpdf.ipynb | PyPDFLoader, PyMuPDFLoader, SmartPDFProcessor |
| 3 | 3-dataparsingdoc.ipynb | Docx2txtLoader, UnstructuredWordDocumentLoader |
| 4 | 4-csvexcelparsing.ipynb | CSVLoader, pandas/Excel, UnstructuredExcelLoader |
| 5 | 5-jsonparsing.ipynb | JSONLoader + jq_schema, custom flattening |
| 6 | 6-databaseparsing.ipynb | SQLDatabase, sql_to_documents() with JOINs |
See also: RAG Architecture ·
Vector Store vs Database ·
RAG & Agents (Part 2) ·
Run all locally: python scripts/run_notebooks.py