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

The Document Object & Metadata

Why text alone is insufficient. Understanding attribution and filtering.

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. Why Ingestion Is a System Problem2. The Atomic Unit: Document3. The Role of Metadata 🏷️A. Provenance (Trust)B. Filtering (Precision)4. 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. Why Ingestion Is a System Problem2. The Atomic Unit: Document3. The Role of Metadata 🏷️A. Provenance (Trust)B. Filtering (Precision)4. Summary

1. Why Ingestion Is a System Problem

Most beginners treat RAG as a "Search" problem. Experienced engineers treat RAG as a "Data" problem.

If you load garbage into your vector store, no amount of prompt engineering will fix the output. Common failures include:

  • Context Contamination: Indexing navigation menus ("Home > About > Contact") as if they were content.
  • Loss of Hierarchy: Flattening a structured PDF into a stream of characters, losing the distinction between a "Section Header" and "Body Text."
  • Ghost Sources: Retrieving a paragraph but losing the URL it came from.

Data Ingestion is strict pipeline engineering. It determines the ceiling of your system's intelligence.

2. The Atomic Unit: Document

In LangChain (and LlamaIndex), text is never just a string. It is wrapped in a Document object.

document_schema.py
class Document:
  page_content: str
  metadata: dict

This separation is critical.

  • page_content: The vector embedding is generated from this. It is what we search against.
  • metadata: This is filtered before or after the search. It is never embedded (usually).

3. The Role of Metadata 🏷️

Metadata is not "extra" info. It is the control plane of your retrieval system.

A. Provenance (Trust)

If an LLM says "Revenue is up 20%," the user asks "According to what?" Metadata provides the citation.

metadata_provenance.py
metadata = {
  "source": "https://company.com/report-2023.pdf",
  "page": 14,
  "author": "CFO Office"
}

B. Filtering (Precision)

A user might ask: "What did the CEO say about AI in 2023?" If you rely only on vector similarity, you might retrieve the 2021 report because the words are similar.

With metadata, you enforce constraints: filter = { "year": 2023, "author": "CEO" }

This converts a "fuzzy" semantic search into a precise database query.

4. Summary

Never ingest raw strings. Ingest Documents. Your pipeline's first job is to extract content and attach rich, structural metadata.

Key Intuition: "Content is for the model. Metadata is for the system."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonStreaming Tokens & Async ChainsNext lesson →Loaders: PDF, HTML, Text, Web