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 30 of 68

Lazy Loading & Generators

Processing millions of docs without crashing RAM.

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. The Memory Wall2. Lazy Loading (Generators)3. Streaming Ingestion4. 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. The Memory Wall2. Lazy Loading (Generators)3. Streaming Ingestion4. Summary

1. The Memory Wall

If you have 1 million documents. loader.load() tries to pull all 1 million into a Python list in RAM. Your server crashes. OOM KilleD.

2. Lazy Loading (Generators)

LangChain loaders expose .lazy_load(). This returns a Generator, not a List. It reads one file, yields it, and forgets it.

lazy_loading.py
loader = DirectoryLoader("./huge_dataset")

# Bad (Eager)
# docs = loader.load() # Consumes 10GB RAM

# Good (Lazy)
for doc in loader.lazy_load():
  # Process one doc at a time
  vector_store.add_documents([doc])
  # RAM stays constant

3. Streaming Ingestion

In production pipelines, identifying "Lazy" operations is critical. Your ingestion script should be a pipeline of generators: Generator(Disk) -> Generator(Splitter) -> Generator(Embedder) -> Vector Store.

4. Summary

Don't buy more RAM. Write better pipelines. Lazy loading is the difference between a toy script and a production ETL job.

Key Intuition: "If it fits in RAM, it's not Big Data."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonDeduplication via Content HashingNext lesson →Embeddings: What Matters in Practice