Skip to main content
Parent document retrieval solves the chunk size tradeoff: small chunks match queries precisely, but lack surrounding context needed for good answers. This technique indexes small chunks for accurate retrieval, then returns their larger parent documents for generation.

The chunk size dilemma

When indexing documents, you face a trade-off:

Small chunks (128-256 tokens)

Pros:
  • Precise semantic matching
  • Low false positive rate
  • Better retrieval accuracy
Cons:
  • Missing surrounding context
  • Incomplete information
  • Poor for generation

Large chunks (512-1024 tokens)

Pros:
  • Rich context for generation
  • Complete information
  • Better for Q&A
Cons:
  • Noisy retrieval
  • Higher false positives
  • Worse precision
Parent document retrieval gives you the best of both worlds.

How it works

  1. Split documents into parent and child chunks
    • Parents: Large chunks (512-1024 tokens) with full context
    • Children: Small chunks (128-256 tokens) for precise matching
  2. Index only child chunks
    • Store child embeddings in vector database
    • Each child has metadata linking to its parent ID
  3. Store parent documents separately
    • ParentDocumentStore maintains parent text in memory
    • Maps child IDs to parent IDs and full parent text
  4. During search
    • Retrieve top-k child chunks from vector DB
    • Map child IDs to parent IDs
    • Return unique parent documents (deduplicated)

Basic usage

Configuration

ParentDocumentStore

The parent store maintains chunk-to-parent mappings in memory:

Indexing pipeline internals

Here’s how the LangChain indexing pipeline works:

Search pipeline internals

How search retrieves children but returns parents:

Why over-fetch children?

The search pipeline retrieves top_k * 2 children because:
  • Multiple children may belong to the same parent
  • After deduplication, you might have fewer than top_k unique parents
  • Over-fetching ensures you have enough unique parents
Example:

Chunk size recommendations

Works well for articles, documentation, and general content.

Trade-offs

  • Child chunks are indexed in vector DB (normal storage)
  • Parent documents stored in ParentDocumentStore (in-memory pickle file)
  • Total storage: ~1.5-2x standard indexing
  • Mitigation: Parent store can be compressed or moved to Redis/database
  • ParentDocumentStore loads into memory during search
  • For 1M parents with 1KB text each: ~1GB RAM
  • Mitigation: Use database-backed parent store for production
  • Need to track which parents have been returned
  • Over-fetching required to ensure enough unique parents
  • Benefit: Handled automatically by ParentDocumentStore

Production considerations

1

Persist parent store

Save ParentDocumentStore to disk after indexing:
Load during search:
2

Scale parent storage

For large datasets, use a database instead of pickle:
3

Monitor deduplication rate

Track how many children map to unique parents:
4

Combine with RAG

Use parent documents for answer generation:

See also