Retrievers
An object that answers "give me the top K chunks for this query". It wraps the vector search from Part 5.
Last updated
Analogy
A repository class: one method, and it hides the SQL behind it.
In an agent
Wrap a retriever in a tool and the agent can search docs on demand.
Questions people ask
What is a retriever in LangChain?
A retriever is an object with one job: given a query, return the most relevant chunks. It usually wraps a vector store search and hides the details, like a repository class hides SQL. You call retriever.invoke with the question and get documents back, ready to put in a prompt.
How do I let an agent search my documents with a retriever?
Wrap the retriever in a tool, for example searchDocs with a query string argument, and give that tool to the agent. The agent then decides when to search and with what query. This turns classic RAG into agentic RAG, where retrieval is just one more tool in the loop.