Senior LevelAI, LLMs, Embeddings & MCP
What is Parent-Document / Small-to-Big Retrieval in advanced RAG architectures?
❓ Interview Prompt: Explain small-to-big chunk retrieval, linking small embedding chunks to large parent documents, and resolving context trade-offs.
Traditional RAG faces a fundamental dilemma:
•
Small Chunks (100 tokens): Great for precise vector embedding search, but lack full context for answer generation.
•
Large Chunks (2,000 tokens): Contain full context for generation, but produce vague, diluted vector embeddings.
Parent-Document (Small-to-Big) Solution:
1
Split documents into Large Parent Documents (e.g. 1,500 tokens).
2
Sub-split each parent into multiple Small Child Chunks (e.g. 150 tokens).
3
Embed and index ONLY the small child chunks in the vector database for high search precision.
4
When a child chunk matches a query, retrieve and feed the full Parent Document to the LLM context window!
Code Implementation Example
typescript
// Parent-Child Document Store Mapping
interface ChildChunk { id: string; vector: number[]; parentDocId: string; }
interface ParentDoc { id: string; fullContent: string; }
async function smallToBigRetrieval(queryVector: number[]): Promise<string> {
// 1. Search small child chunks for precise vector match
const matchedChildren = await vectorStore.query({ vector: queryVector, topK: 3 });
// 2. Fetch full parent documents associated with matched child IDs
const parentIds = [...new Set(matchedChildren.map(c => c.parentDocId))];
const parentDocs = await docStore.getBatch(parentIds);
return parentDocs.map(p => p.fullContent).join('\n---\n');
}💡Parent-Child (Small-to-Big) retrieval mapping child vector matches to parent context.
🎯 Interview Key Takeaway
Small-to-Big retrieval embeds small child chunks for vector search precision, but passes the large parent document to the LLM for generation context.
#Parent-Child#Small-to-Big#RAG#Vector Search#Senior
Back to all AI, LLMs, Embeddings & MCP Questions→