Overview
Retrievers returnDocument objects given a text query. They provide a standard interface for retrieving relevant documents from various sources.
BaseRetriever
Abstract base class for document retrieval systems. Source:langchain_core.retrievers:55
Inherits: RunnableSerializable[str, list[Document]]
Type Aliases
Properties
Optional tags associated with the retriever for callbacks and tracing
Optional metadata associated with the retriever for callbacks and tracing
Core Methods
invoke
The query string
Configuration for callbacks, tags, metadata
Additional arguments passed to the retriever
List of relevant documents
ainvoke
invoke.
batch
List of query strings
List of document lists, one per query
abatch
Implementation Methods
When subclassingBaseRetriever, implement these methods:
_get_relevant_documents (Required)
The query string
Callback manager for the retriever run
List of relevant documents
_aget_relevant_documents (Optional)
_get_relevant_documents. Override for native async support.
Example Implementation
VectorStoreRetriever
Retriever that uses a vector store for similarity search. Source:langchain_core.vectorstores.base
Inherits: BaseRetriever
Properties
The vector store to retrieve from
Type of search to perform:
'similarity': Standard similarity search'mmr': Maximum marginal relevance (diverse results)'similarity_score_threshold': Filter by minimum similarity score
Additional keyword arguments for search. Common keys:
k: Number of documents to retrievescore_threshold: Minimum similarity score (for'similarity_score_threshold')fetch_k: Number of documents to fetch before MMR (for'mmr')lambda_mult: Diversity parameter for MMR (for'mmr')
Example
MultiQueryRetriever
Generate multiple queries and retrieve documents for each. Source:langchain.retrievers.multi_query
Inherits: BaseRetriever
Generates multiple perspectives on a query and retrieves documents for each, combining results.
Properties
The base retriever to use for each generated query
LLM chain to generate alternative queries
Key to extract queries from LLM output
ContextualCompressionRetriever
Compress retrieved documents using a document compressor. Source:langchain.retrievers.contextual_compression
Inherits: BaseRetriever
Properties
The base retriever to get initial documents
Compressor to filter or compress retrieved documents
ParentDocumentRetriever
Retrieve smaller chunks but return larger parent documents. Source:langchain.retrievers.parent_document_retriever
Inherits: BaseRetriever
Retrieves small chunks for better search, but returns full parent documents for context.
Properties
Vector store containing child chunks
Store containing parent documents
Splitter to create child chunks
Optional splitter to create parent documents
EnsembleRetriever
Combine multiple retrievers using weighted reciprocal rank fusion. Source:langchain.retrievers.ensemble
Inherits: BaseRetriever
Properties
List of retrievers to combine
Weights for each retriever (must sum to 1.0)
Constant for reciprocal rank fusion
RetrieverLike
Type alias for objects that can act as retrievers. Source:langchain_core.retrievers
Runnable that takes a string and returns documents can be used as a retriever.
LangSmithRetrieverParams
Parameters for LangSmith tracing of retrievers. Source:langchain_core.retrievers:39
Name of the retriever for tracing
Vector store provider name
Embedding provider name
Embedding model name