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:

RetrieverWhat it does
Vector storeStandard semantic search
MultiQueryRetrieverLLM generates query variations, merges results
ParentDocumentRetrieverMatches small chunks, returns the parent
ContextualCompressionRetrieverReranks / compresses retrieved docs
SelfQueryRetrieverLLM extracts metadata filters from the query
EnsembleRetrieverCombines retrievers (hybrid search, RRF)
BM25RetrieverKeyword search, no embeddings

Using a Retriever in a RAG Chain

The retriever is the first step of a RAG chain. 

Whiteboard
Whiteboard diagram

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 k and 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; configure k, 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