Retrieval quality dominates. A great LLM on bad chunks < an average LLM on the right chunks.
Three levers give ~80% of gains: good chunking, good embeddings/similarity, and ==top-k + re-ranking==.
Recall Feynman: explain to a 12-year-old
Imagine an open-book exam. Instead of trying to remember everything, you first flip to the right
page in your notebook, then write the answer using that page. RAG does the same for a chatbot:
it finds the right page (retrieval) from a big pile of notes, tapes it next to the question, and
then the chatbot answers by reading it. That way it doesn't make stuff up, and if you add a new
page to the pile, it instantly knows the new thing — no need to send the chatbot back to school.
Stale knowledge, hallucination, and lack of source provenance — by grounding answers in externally retrieved documents.
Write the RAG probabilistic decomposition.
p(y∣x)=∑zp(z∣x)p(y∣x,z) — retriever times generator, summed over latent passages.
Why use cosine similarity instead of raw dot product for retrieval?
Cosine removes vector magnitude, so ranking depends on topical direction, not document length — unless vectors are pre-normalised (then dot product is equivalent).
Dekho, ek normal LLM ek closed-book student ki tarah hai — jo training ke time yaad kiya bas
wahi jaanta hai. Problem yeh hai ki uska gyaan purana ho jaata hai, aur jab confidence nahi hota toh
woh confidently galat cheez bana deta hai (hallucination). RAG ka idea simple hai: pehle question ke
hisaab se relevant documents dhoondo (retrieve karo), unko prompt me daal do, phir model unhi ko
padh kar answer de. Matlab open-book exam! Isse facts model ke andar (weights me) store nahi hote,
balki bahar ek database me rehte hai — naya document add karo, system turant smart ho jaata hai, bina
dobara train kiye.
Pipeline yaad rakhne ke liye mnemonic hai CERG: pehle documents ko Chunk karo (chhote pieces),
har chunk ko Embed karo (vector bana do), phir query aane par top-k similar chunks Retrieve karo,
aur end me LLM se Generate karwao. Retrieval me hum cosine similarity use karte hai —
kyunki hum topic match chahte hai, document ki length nahi. Dot product magnitude ko mila deta hai,
isliye normalise karke sirf direction (angle) dekhte hai. Cosine = 1 matlab bilkul same topic.
Sabse important baat — 80/20 rule: retrieval quality hi sab kuch hai. Best LLM bhi galat chunks
par galat answer dega, aur average LLM bhi sahi chunks mile toh sahi answer dega. Isliye chunking,
embeddings, aur top-k + re-ranking par mehnat karo. Aur yeh galatfehmi mat rakhna ki "zyada chunks do
toh better" — bade context me model beech ka text ignore kar deta hai (lost-in-the-middle), cost badhti
hai, aur distractor chunks confuse karte hai. Chhota k (3–8) rakho aur re-rank karo. Yahi asli RAG hai.