Class CohereReranker
Re-ranker that uses the Cohere Rerank API to reorder search results by relevance. Requires a Cohere API key. See: https://docs.cohere.com/reference/rerank
public class CohereReranker : IReranker
- Inheritance
-
CohereReranker
- Implements
- Inherited Members
Constructors
CohereReranker(string, HttpClient?, string, string)
Creates a Cohere-based re-ranker.
public CohereReranker(string apiKey, HttpClient? httpClient = null, string model = "rerank-v3.5", string endpoint = "https://api.cohere.com/v2/rerank")
Parameters
apiKeystringCohere API key.
httpClientHttpClientOptional HTTP client. If null, a new one is created.
modelstringModel to use. Default: rerank-v3.5.
endpointstringAPI endpoint override.
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).