Class LlmReranker
Re-ranker that uses an existing LLM (AIService) to score and reorder search results. Sends a prompt asking the LLM to rate each document's relevance on a 0โ10 scale.
public class LlmReranker : IReranker
- Inheritance
-
LlmReranker
- Implements
- Inherited Members
Constructors
LlmReranker(IAIService)
Creates an LLM-based re-ranker using the provided AI service. The service should be configured (model, temperature, etc.) before passing in. A low temperature (e.g., 0.0โ0.2) is recommended for consistent scoring.
public LlmReranker(IAIService aiService)
Parameters
aiServiceIAIServiceThe AI service to use for scoring.
Methods
RerankAsync(string, IReadOnlyList<VectorSearchResult>, CancellationToken)
Re-ranks the given search results based on their relevance to the query. Returns all results with updated scores, ordered by relevance (descending).
public Task<IReadOnlyList<VectorSearchResult>> RerankAsync(string query, IReadOnlyList<VectorSearchResult> results, CancellationToken cancellationToken = default)
Parameters
querystringThe original text query.
resultsIReadOnlyList<VectorSearchResult>The initial retrieval results to re-rank.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<IReadOnlyList<VectorSearchResult>>
All results re-scored and ordered by relevance (descending).