Retrievers (in LangChain)
A retriever is LangChain's RAG retrieval layer — a component with one job: given a query, return relevant documents. That's the whole interface. Because it's so simple, anything can be a retriever — a vector store, a keyword index, a database, a web search — and they all plug into chains and agents the same way.
💡 In one line: A LangChain retriever takes a query and returns relevant documents — a single interface over any retrieval source.
What is a Retriever?
A retriever is a component that accepts a query string and returns a list of Document objects. It's an interface, not an implementation — a vector store is the most common backing, but a retriever can wrap any source.
Retriever vs. Vector Store
- Vector store — stores and searches embeddings (
similarity_search). - Retriever — the standard interface that chains and agents use (
invoke).
Turn any vector store into a retriever with vectorstore.as_retriever() — the most common line in LangChain RAG.
Search Parameters
Configure retrieval at creation:
k— how many documents to return.search_type— similarity, MMR (diversity), or score threshold.filter— metadata filtering.
Retriever Types
LangChain ships many, mapping to the retrieval methods you've already met:
| Retriever | What it does |
|---|---|
| Vector store | Standard semantic search |
| MultiQueryRetriever | LLM generates query variations, merges results |
| ParentDocumentRetriever | Matches small chunks, returns the parent |
| ContextualCompressionRetriever | Reranks / compresses retrieved docs |
| SelfQueryRetriever | LLM extracts metadata filters from the query |
| EnsembleRetriever | Combines retrievers (hybrid search, RRF) |
| BM25Retriever | Keyword search, no embeddings |
Using a Retriever in a RAG Chain
The retriever is the first step of a RAG chain.Â
In LCEL that's roughly {"context": retriever, "question": passthrough} | prompt | model | parser.
Retrievers as Tools
You can also expose a retriever to an agent as a tool (create_retriever_tool) — then the agent decides when to search rather than retrieving on every turn. This is the difference between a fixed RAG chain and agentic RAG.
Why the Abstraction Helps
Because every retriever shares one interface, you can swap Chroma for Pinecone, or add reranking or hybrid search, without changing your chain. That composability is the whole point.
Best Practices
- Tune
kand use metadata filters. - Use MMR when results are too redundant.
- Add reranking via ContextualCompressionRetriever.
- Use EnsembleRetriever for hybrid search.
- For agents, wrap the retriever as a tool.
Summary
- A retriever turns a query into relevant documents — LangChain's retrieval interface.
vectorstore.as_retriever()is the common path; configurek,search_type, and filters.- Built-in types cover multi-query, parent-document, reranking, self-query, hybrid, and BM25.
- Retrievers slot into RAG chains — or become tools for agentic RAG.
- One interface means you can swap or upgrade retrieval without rewriting your chain. EOF echo created