AIKernel.Providers.Reranker 0.1.4

dotnet add package AIKernel.Providers.Reranker --version 0.1.4
                    
NuGet\Install-Package AIKernel.Providers.Reranker -Version 0.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AIKernel.Providers.Reranker" Version="0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AIKernel.Providers.Reranker" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="AIKernel.Providers.Reranker" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AIKernel.Providers.Reranker --version 0.1.4
                    
#r "nuget: AIKernel.Providers.Reranker, 0.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AIKernel.Providers.Reranker@0.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AIKernel.Providers.Reranker&version=0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=AIKernel.Providers.Reranker&version=0.1.4
                    
Install as a Cake Tool

AIKernel local reranker

LocalRerankerProvider runs the mMARCO multilingual MiniLM cross-encoder on the CPU. It accepts a query and text candidates, then returns raw relevance logits and the original zero-based candidate indices. Use the indices to retrieve the source URL or excerpt from the original search result. Higher scores rank first, ties follow input order, and all candidates are scored before applying TopK.

Model files

Download onnx/model.onnx and tokenizer.json from revision 1427fd652930e4ba29e8149678df786c240d8825. Put both files in ModelDirectory as model.onnx and tokenizer.json. The provider verifies the SHA-256 of both files on initialization.

Model files are distributed separately under Apache-2.0. When redistributing model files, include the license text and follow the applicable attribution and modification notice requirements.

Configuration and use

Create LocalRerankerSettings directly or bind the host's Reranker configuration section using Microsoft.Extensions.Configuration.Binder. Create a new provider instance to apply changes.

{
  "Reranker": {
    "ModelDirectory": "models/mmarco-mMiniLMv2-L12-H384-v1",
    "MaxCandidates": 16,
    "MaxQueryTokens": 128,
    "MaxCandidateTokens": 380,
    "MaxPairTokens": 512,
    "InferenceBatchSize": 4,
    "CpuThreads": 4,
    "MaxRequestBytes": null
  }
}

Query and candidate token limits exclude the four special tokens introduced by pairing. The pair limit includes them and cannot exceed 512. MaxRequestBytes optionally limits the UTF-8 size of all input texts together, counting the query once. An exceeded limit fails the entire request.

InferenceBatchSize limits how many pairs are scored per ONNX invocation. Each provider instance runs one request at a time. CpuThreads defaults to four or the number of available logical processors, whichever is smaller. Use zero for ONNX Runtime's default.

using AIKernel.Dtos.Providers.Reranking;
using AIKernel.Providers.Reranker;
using Microsoft.Extensions.Configuration;

var settings = configuration.GetRequiredSection("Reranker").Get<LocalRerankerSettings>()
    ?? throw new InvalidOperationException("Missing reranker configuration.");
await using var provider = new LocalRerankerProvider(settings);
await provider.InitializeAsync();

var result = await provider.RerankAsync(new RerankRequest
{
    Query = "日本の首都はどこですか?",
    Candidates = [new("京都はかつて日本の都でした。"), new("日本の首都は東京です。")],
    TopK = 1
}, cancellationToken);
var bestCandidateIndex = result.Scores.Items[0].Index;

Check GetCapabilityDescriptor() for model registration, effective limits, CPU precision and score semantics. Scores are model-specific and have no declared numeric range. An empty query or candidate list, or TopK outside the candidate count, fails with provider.invalid_request. Cancellation throws OperationCanceledException without returning partial results.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.4 62 11/23/2026

Adds cross-encoder relevance ranking with configurable limits and CPU threads.