Rerankers
Rerankers enhance the relevance of search results by refining and reordering them after initial retrieval. The Vectara Python SDK enables you to apply various reranker types in queries to optimize result quality for different use casesβfrom improving precision with neural models to adding diversity or custom business logic.
This section shows how to integrate different reranker types into your queries and configure them for optimal performance in various scenarios. For more information about the available rerankers, see Reranking.
This guide assumes you have a corpus called my-docs
. If you haven't created a corpus yet, follow
the Quick Start guide to set up your first corpus.
Basic query with rerankerβ
Improve result ordering in a query by specifying a reranker configuration. This ensures the most relevant, business-critical results appear at the top according to your chosen ranking logic.
1
This example demonstrates using Vectara's multilingual reranker, which provides advanced neural ranking capabilities for both English and multilingual content, making it ideal for improving result quality in RAG applications.
Key Benefits:
- Enhanced relevance scoring using neural models
- Multilingual support for global applications
- Optimized for RAG and question-answering scenarios
MMR reranker for diversityβ
Use Maximal Marginal Relevance (MMR) reranking to balance relevance with diversity, reducing redundancy in search results while maintaining high quality.
1
MMR Configuration Parameters:
diversity_bias
: Float between 0-1 controlling relevance vs diversity balancelimit
: Maximum number of results to rerankcutoff
: Minimum relevance score threshold for results
Use Cases:
- Product search where you want variety in results
- Research queries requiring diverse perspectives
- Content discovery applications
- Recommendation systems
User Defined Function (UDF) rerankerβ
Implement custom scoring logic using User Defined Functions to boost or filter results based on metadata, business rules, or dynamic conditions.
1
UDF Function Examples:
1
1
1
Use Cases:
- E-commerce inventory management
- Content freshness prioritization
- User preference personalization
- Business rule enforcement
Chain reranker for complex rankingβ
Combine multiple rerankers sequentially to implement sophisticated ranking strategies that incorporate relevance, diversity, and custom business logic.
1
Chain Reranker Strategy:
- Neural Ranking: Start with multilingual reranker for semantic precision
- Diversity: Apply MMR with low bias to reduce redundancy while preserving relevance
- Business Logic: Boost results with high customer ratings for business optimization
Advanced Chain Examplesβ
1
1
Streaming queries with rerankersβ
Apply rerankers in streaming scenarios for real-time applications while maintaining improved result quality as each chunk is received.
1
Streaming with Rerankers Benefits:
- Real-time response generation with improved relevance
- Better user experience for interactive applications
- Optimized result quality for chatbots and live search
- Enhanced performance for long-form content generation
List available rerankersβ
Discover available rerankers in your Vectara instance to identify their names and configurations for use in queries.
1
Listing Parameters:
filter
: Regular expression to match reranker names or descriptionslimit
: Maximum number of rerankers to return per pagepage_key
: Pagination token for retrieving additional results
Use the reranker names from this list in your customer_reranker
configurations.
Best practices and optimizationβ
Reranker Selection Guidelines:
1
Performance Guidelines:
- Use single rerankers for high-volume, low-latency scenarios
- Apply chain rerankers for complex ranking requirements
- Set appropriate
limit
values to balance quality and performance - Monitor query latency when adding multiple rerankers
- Use
cutoff
parameters to filter low-relevance results
Error Handling Best Practices:
- Validate reranker names using the list endpoint
- Implement fallback queries without rerankers for reliability
- Handle reranker failures gracefully in production systems
- Test UDF functions thoroughly before deployment
Error handling and troubleshootingβ
Common Issues and Solutions:
1
Common Error Scenarios:
- 400 Bad Request: Invalid reranker name or configuration
- 403 Forbidden: Insufficient permissions for reranker access
- 404 Not Found: Reranker not available in your instance
- 429 Rate Limit: Too many reranking requests
Resolution Strategies:
- Validate reranker availability using
client.rerankers.list()
- Implement graceful degradation to basic search
- Use appropriate error handling for production reliability
- Monitor reranker performance and adjust configurations
Next stepsβ
After understanding rerankers:
- Query optimization: Combine rerankers with metadata filtering for precise results
- Performance tuning: Monitor and optimize reranker configurations for your use case
- Custom business logic: Develop sophisticated UDF functions for domain-specific ranking
- A/B testing: Compare different reranker configurations to optimize user experience