Retrievers and RAG chains
A Retriever turns a query into relevant Source Documents using embeddings, vector search and ranking strategies.
In plain terms
The user's question becomes a Query Embedding. Each stored Chunk already has a Document Embedding. Similarity Search compares vectors with Cosine Similarity, Top-K Retrieval returns the best matches, and MMR Retrieval trades a little relevance for more diversity.
Why it matters
RAG quality depends on finding the right context before generation. LangChain gives common chain shapes for connecting retrieval to an LLM.
How it works
Index Document Embedding vectors in a Vector Store or Vector Database such as FAISS, Chroma, Qdrant or Pinecone. At question time, the Retriever returns Source Documents. A Retriever Chain connects retrieval to the model. A Stuff Chain puts all retrieved docs into one prompt. A Map Reduce Chain processes documents separately then combines them. A Refine Chain improves an answer step by step.
When you use it
Use retriever chains for document QA, citation bots, research assistants, support assistants and agents that need grounded context.
Common mistakes
- Only checking the final answer instead of inspecting retrieved Source Documents.
- Using Top-K Retrieval without testing K.
- Ignoring MMR Retrieval when results are repetitive.
Best practices
- Evaluate retrieval separately from generation.
- Show retrieved chunks in a debug panel.
- Use metadata filters before semantic ranking when permissions or categories matter.
Try it yourself
Build the same docs question-answering flow as a Stuff Chain, then try a Refine Chain on longer documents and compare quality.