Method Rerank
- Namespace
- LMKit.Embeddings
- Assembly
- LM-Kit.NET.dll
Rerank(string, PartitionSimilarity, float, CancellationToken)
Reranks the similarity score of a single PartitionSimilarity synchronously by invoking the reranking model and updating its RerankedScore property with the new blended score.
public void Rerank(string query, PartitionSimilarity partitionSimilarity, float rerankedAlpha = 0.5, CancellationToken cancellationToken = default)
Parameters
query
stringThe input text query used for reranking. Must not be
null
.partitionSimilarity
PartitionSimilarityThe partition similarity object whose RerankedScore property will be updated. Must not be
null
.rerankedAlpha
floatA blending factor between the original similarity (top[i]) and the reranker model score (rerank[i]), in the range [0 - 1]. Computed as:
final_score = (α × top[i]) + ((1 − α) × rerank[i])
For example, with α = 0.5:
final_score = (0.5 × 0.95) + (0.5 × 0.07) = 0.475 + 0.035 = 0.510
A typical default is 0.5 for equal weighting.
cancellationToken
CancellationTokenA token to cancel the operation if needed.
Exceptions
- ArgumentNullException
Thrown if
query
orpartitionSimilarity
isnull
.
Rerank(string, IEnumerable<PartitionSimilarity>, float, CancellationToken)
Reranks the similarity scores of multiple PartitionSimilarity instances synchronously by invoking the reranking model and updating each instance’s RerankedScore property with its new blended score.
public void Rerank(string query, IEnumerable<PartitionSimilarity> partitionSimilarities, float rerankedAlpha = 0.5, CancellationToken cancellationToken = default)
Parameters
query
stringThe input text query used for reranking. Must not be
null
.partitionSimilarities
IEnumerable<PartitionSimilarity>A collection of partition similarity objects whose RerankedScore properties will be updated. Must not be
null
or empty.rerankedAlpha
floatA blending factor between the original similarity (top[i]) and the reranker model score (rerank[i]), in the range [0 - 1]. Computed as:
final_score = (α × top[i]) + ((1 − α) × rerank[i])
For example, with α = 0.5:
final_score = (0.5 × 0.95) + (0.5 × 0.07) = 0.475 + 0.035 = 0.510
A typical default is 0.5 for equal weighting.
cancellationToken
CancellationTokenA token to cancel the operation if needed.
Exceptions
- ArgumentNullException
Thrown if
query
isnull
orpartitionSimilarities
isnull
or empty.