Lesson 13 of 30
Embed a whole document and you get one vague, averaged-out meaning — chunking is what turns 'this book is roughly about X' into 'this exact paragraph answers your question.'
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
Why can't you just embed a whole long document as a single vector instead of splitting it into chunks first?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Before a document goes into a vector store, it gets split into smaller pieces called chunks. Each chunk gets its own embedding and is retrieved independently. This isn't an implementation detail you could skip — it's necessary for two concrete reasons:
The real design decision is chunk size, and it's a genuine tradeoff, not a "bigger is safer" default:
// Rough sketch of chunking with overlap
function chunkText(text: string, chunkSize: number, overlap: number) {
const chunks: string[] = [];
let start = 0;
while (start < text.length) {
chunks.push(text.slice(start, start + chunkSize));
start += chunkSize - overlap; // step forward less than a full chunk — that's the overlap
}
return chunks;
}
A document, and one sentence that happens to fall right where a chunk boundary would land.
Chunk overlap — where each chunk shares a bit of text with its neighbor, rather than chunks butting up cleanly end-to-end — exists to solve a specific failure mode: a sentence that happens to fall right at a chunk boundary otherwise gets awkwardly split in half, with neither resulting chunk containing the full sentence's meaning. Overlap makes it far more likely that any given sentence appears whole in at least one chunk, even if its "natural" position straddles a boundary.
"A RAG feature keeps retrieving irrelevant or incomplete-feeling context — what would you check?" is a real diagnostic question, and chunk size and overlap are two of the first, cheapest things to inspect before assuming the embedding model or the vector database is the problem.