RerankerBase<T>

Base Classes · AiDotNet.RetrievalAugmentedGeneration.Rerankers

Provides a base implementation for document rerankers with common functionality.

Implements: IReranker<T>

Known derived types: CohereReranker<T>, ColbertReranker<T>, CrossEncoderReranker<T>, DiversityReranker<T>, IdentityReranker<T>, LLMBasedReranker<T>, LostInTheMiddleReranker<T>, MaximalMarginalRelevanceReranker<T>, OnnxCrossEncoderReranker<T>, ReciprocalRankFusion<T>

For Beginners

This is the foundation that all reranking methods build upon.

Think of it like a template for improving search results:

  • It handles common tasks (checking inputs, limiting results, normalizing scores)
  • Specific reranking methods (cross-encoder, LLM-based) just fill in how they score documents
  • This ensures all rerankers work consistently

How It Works

This abstract class implements the IReranker interface and provides common functionality for reranking strategies. It handles validation, result limiting, and score normalization while allowing derived classes to focus on implementing the core reranking algorithm.

Properties

Property Summary
bool ModifiesScores { get; } Gets a value indicating whether this reranker modifies relevance scores.

Methods

Method Summary
IEnumerable<Document<T>> Rerank(string query, IEnumerable<Document<T>> documents) Reranks a collection of documents based on their relevance to a query.
IEnumerable<Document<T>> Rerank(string query, IEnumerable<Document<T>> documents, int topK) Reranks documents and returns only the top-k highest scoring results.
Task<IEnumerable<Document<T>>> RerankAsync(string query, IEnumerable<Document<T>> documents, CancellationToken cancellationToken) Asynchronously reranks a collection of documents based on their relevance to a query.
Task<IEnumerable<Document<T>>> RerankAsync(string query, IEnumerable<Document<T>> documents, int topK, CancellationToken cancellationToken) Asynchronously reranks documents and returns only the top-k highest scoring results.