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

Deduplication via Content Hashing

Why duplicates kill quality and cost. How to fix it with MD5.

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 Duplicate Tax2. Solution: Content Hashing3. RecordManager4. 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 Duplicate Tax2. Solution: Content Hashing3. RecordManager4. Summary

1. The Duplicate Tax

If you ingest a dataset twice, most naive RAG pipelines index it twice. Vector stores don't care. They will happily store 2 identical vectors.

The Cost:

  1. Storage $$: You pay double.
  2. Retrieval Logic: When you search, the top 5 results are just the same document 5 times. You lose diversity.

2. Solution: Content Hashing

Before embedding, hash the content string. Use the Hash as the ID.

hashing.py
import hashlib

def generate_id(content):
  return hashlib.md5(content.encode()).hexdigest()

doc.id = generate_id(doc.page_content)

# Upsert uses ID. If ID exists, it overwrites (doesn't duplicate).
vector_store.add_documents([doc])

3. RecordManager

LangChain has a RecordManager to handle this automatically for large datasets. It tracks which docs exist and handles updates/deletions.

4. Summary

An indexed document must be unique. If you don't deduplicate, your top-k results will be an echo chamber.

Key Intuition: "Idempotency prevents insanity."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonMetadata Enrichment StrategiesNext lesson →Lazy Loading & Generators