Table of Contents

Class CohereReranker

Namespace
Mythosia.AI.Rag.Reranking
Assembly
Mythosia.AI.Rag.dll

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

apiKey string

Cohere API key.

httpClient HttpClient

Optional HTTP client. If null, a new one is created.

model string

Model to use. Default: rerank-v3.5.

endpoint string

API 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

query string

The original text query.

results IReadOnlyList<VectorSearchResult>

The initial retrieval results to re-rank.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<IReadOnlyList<VectorSearchResult>>

All results re-scored and ordered by relevance (descending).