Installation
What is a Retriever?
A retriever is an interface that returns documents given an unstructured query. It doesn’t store documents - it only retrieves them. Retrievers can:- Wrap vector stores
- Implement custom search logic
- Call external APIs
- Combine multiple sources
- Rerank results
Using Vector Stores as Retrievers
The simplest way to create a retriever is from a vector store:Search API Retrievers
Retrievers that use external search APIs.Tavily Search API Retriever
Retrieve web search results using Tavily’s search API.@langchain/community/retrievers/tavily_search_api
Features:
- Web search with AI-powered relevance
- Basic or advanced search depth
- Domain filtering
- Raw content and image retrieval
- Generated answer inclusion
Arxiv Retriever
Retrieve research papers from Arxiv.@langchain/community/retrievers/arxiv
Hybrid Search Retrievers
Retrievers that combine multiple search strategies.BM25 Retriever
Keyword-based retrieval using the BM25 algorithm.@langchain/community/retrievers/bm25
Use Cases:
- Keyword search
- Exact term matching
- Combine with vector search for hybrid retrieval
Vespa Retriever
Retrieve from Vespa, which supports hybrid search. Module:@langchain/community/retrievers/vespa
Features:
- Hybrid semantic and keyword search
- Scalable distributed search
- Rich querying capabilities
Specialized Retrievers
Retrievers for specific use cases or platforms.Chaindesk Retriever
Retrieve from Chaindesk knowledge bases.@langchain/community/retrievers/chaindesk
Metal Retriever
Retrieve from Metal’s managed vector database.@langchain/community/retrievers/metalRequires:
@getmetal/metal-sdk
Supabase Hybrid Search Retriever
Combine full-text and vector search in Supabase.@langchain/community/retrievers/supabaseRequires:
@supabase/supabase-js
Features:
- Combines semantic (vector) and keyword (full-text) search
- Configurable result counts for each method
- Built on PostgreSQL with pgvector and pg_trgm
Vectara Summary Retriever
Retrieve and summarize results from Vectara. Module:@langchain/community/retrievers/vectara_summary
Features:
- Retrieval with automatic summarization
- Configurable summary length
- Citation tracking
Zep Retriever
Retrieve from Zep memory store for conversational AI.@langchain/community/retrievers/zep- Self-hosted Zep@langchain/community/retrievers/zep_cloud- Zep Cloud
@getzep/zep-js or @getzep/zep-cloud
Use Cases:
- Conversational memory retrieval
- User context for chatbots
- Session-based information
Azion EdgeSQL Retriever
Retrieve from Azion’s edge SQL database. Module:@langchain/community/retrievers/azion_edgesqlRequires:
azion
Features:
- Edge computing for low latency
- SQL-based retrieval with vector support
- Global distribution
Remote Retrievers
Retrievers that connect to remote services.Remote LangChain Retriever
Connect to a remote LangChain server. Module:@langchain/community/retrievers/remote/base
Use Cases:
- Centralized retrieval service
- Shared knowledge base
- Microservices architecture
Custom Retrievers
You can create custom retrievers by extendingBaseRetriever:
Combining Retrievers
Use ensemble retrievers to combine multiple retrieval strategies:Retriever Chains
Retrievers work seamlessly with LangChain’s LCEL:Retrieval QA
Use retrievers for question-answering:Contextual Compression
Compress retrieved documents for better relevance:Multi-Query Retrieval
Generate multiple queries for better coverage:Time-Weighted Retrieval
Retrieve with recency bias:Best Practices
-
Choose the right retriever - Match retriever to your use case:
- Vector search: Semantic similarity
- BM25: Keyword/exact matching
- Hybrid: Best of both worlds
- API-based: Real-time external data
-
Optimize k value - Balance between relevance and context length:
- Start with k=4
- Increase for broader context
- Decrease for focused results
-
Use filters - Narrow scope with metadata filters:
- Implement reranking - Use compression or custom scoring
-
Monitor performance - Track retrieval quality:
- Relevance scores
- Response time
- User feedback
-
Handle failures gracefully - Retrievers may fail or return no results:
- Cache when appropriate - Cache frequent queries
Advanced Patterns
Parent Document Retrieval
Self-Query Retrieval
Performance Considerations
- Latency: API-based retrievers add network overhead
- Cost: External APIs charge per request
- Rate limits: Implement backoff and retries
- Batch operations: Some retrievers support batching
- Caching: Cache frequent queries locally
Next Steps
- Vector Stores - Store documents for retrieval
- Document Loaders - Load documents into your system
- RAG Tutorial - Build retrieval-augmented generation apps
- Chains - Combine retrievers with LLMs
