ElBruno.Reranking 0.5.1

dotnet add package ElBruno.Reranking --version 0.5.1
                    
NuGet\Install-Package ElBruno.Reranking -Version 0.5.1
                    
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="ElBruno.Reranking" Version="0.5.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ElBruno.Reranking" Version="0.5.1" />
                    
Directory.Packages.props
<PackageReference Include="ElBruno.Reranking" />
                    
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 ElBruno.Reranking --version 0.5.1
                    
#r "nuget: ElBruno.Reranking, 0.5.1"
                    
#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 ElBruno.Reranking@0.5.1
                    
#: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=ElBruno.Reranking&version=0.5.1
                    
Install as a Cake Addin
#tool nuget:?package=ElBruno.Reranking&version=0.5.1
                    
Install as a Cake Tool

ElBruno.Reranking

GitHub Actions NuGet Downloads License

Semantic reranking for .NET: Local-first ONNX, cloud-ready APIs, and extensible backends.

ElBruno.Reranking improves search result relevance through intelligent semantic reordering. It provides a unified interface for multiple reranking backends:

  • BGE-Reranker (ONNX): Fast local reranking (~15ms, CPU)
  • Claude API: High-precision cloud reranking (98%+ R@5, <1s)
  • Ollama: Flexible local LLMs (free, offline)
  • Custom: Bring your own reranker

Features

Simple API — Single RerankAsync() method for all backends
Fast ONNX inference — BGE reranker: <100ms for 100 docs
🧠 Cloud-ready Claude backend — Leverage LLMs for high-precision reranking
🎯 Pluggable architecture — Extend with custom backends
🔄 Async/await throughout — Built for high-concurrency .NET applications
🛠️ Production-ready — Error handling, retry logic, timeouts

Installation

dotnet add package ElBruno.Reranking

Or via NuGet Package Manager:

Install-Package ElBruno.Reranking

Quick Start (3 minutes)

ONNX Backend (Local Reranking)

using ElBruno.Reranking;

// Documents to rerank
var documents = new[]
{
    "Machine learning is a subset of artificial intelligence.",
    "Deep learning uses neural networks with many layers.",
    "The weather is sunny today.",
    "Natural language processing enables text understanding.",
};

// Create reranker (requires BGE model file)
var reranker = new OnnxReranker("./models/bge-reranker-base.onnx");

// Rerank
var result = await reranker.RerankAsync(
    query: "What is machine learning?",
    documents: documents,
    options: new RerankOptions { TopK = 5 }
);

// Results
foreach (var score in result.Scores)
{
    Console.WriteLine($"Score: {score.Score:F3}, Text: {score.Item.Text}");
}

Output:

Score: 0.918, Text: Machine learning is a subset of artificial intelligence.
Score: 0.876, Text: Deep learning uses neural networks with many layers.
Score: 0.654, Text: Natural language processing enables text understanding.
Score: 0.142, Text: The weather is sunny today.

Claude Backend (Cloud Reranking)

using ElBruno.Reranking;

var documents = new[]
{
    "The capital of France is Paris.",
    "Paris is a city known for the Eiffel Tower.",
    "The capital of Germany is Berlin.",
};

// Create Claude reranker
var reranker = new ClaudeReranker(apiKey: Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY"));

// Rerank with explanation
var result = await reranker.RerankAsync(
    query: "What is the capital of France?",
    documents: documents,
    options: new RerankOptions { TopK = 3, EnableRetry = true }
);

foreach (var score in result.Scores)
{
    Console.WriteLine($"Score: {score.Score:F3}, Text: {score.Item.Text}");
}

Documentation

Performance Benchmarks

Backend Latency (100 docs) Throughput Cost Privacy
BGE (ONNX) ~15ms 67 QPS Free Local only
Claude API <1s (incl. network) 5-10 QPS ~$0.0008/call Cloud
Ollama 200ms–5s ~100 QPS Free Local only

Full benchmarks in docs/benchmarks.md

Core Concepts

RerankItem (Input)

public class RerankItem
{
    public string? Id { get; set; }                          // Caller-provided ID
    public string Text { get; set; }                         // Content to rerank
    public Dictionary<string, object>? Metadata { get; set; } // Custom metadata
}

RerankScore (Output Item)

public class RerankScore
{
    public RerankItem Item { get; }                 // Original item
    public float Score { get; }                     // Relevance score [0.0, 1.0]
    public int Rank { get; }                        // 1-based rank (1 = highest)
    public string? Explanation { get; }             // Optional reasoning (Claude backend)
}

RerankResult (Output)

public class RerankResult
{
    public IReadOnlyList<RerankScore> Scores { get; }             // Sorted by score (highest first)
    public int TotalItems { get; }                                // Total reranked
    public string Query { get; }                                  // Query used for reranking
    public string BackendName { get; }                            // Backend that produced result
    public long ElapsedMilliseconds { get; }                      // Time taken
    public Dictionary<string, string>? Diagnostics { get; }       // Diagnostics info
}

RerankOptions (Configuration)

public class RerankOptions
{
    public int TopK { get; set; } = int.MaxValue;           // Return top-k only
    public double MinScore { get; set; } = 0.0;             // Filter by threshold
    public int TimeoutMs { get; set; } = 30000;             // Request timeout
    public bool EnableRetry { get; set; } = true;           // Retry transient errors
    public int MaxRetries { get; set; } = 3;                // Max retry attempts
}

When to Use Each Backend

Choose BGE (ONNX) if you need:

  • ✅ Fast local reranking (<100ms)
  • ✅ Offline operation (no API key)
  • ✅ Lower cost (free inference)
  • ✅ Privacy (data stays local)

Choose Claude API if you need:

  • ✅ High precision (98%+ R@5)
  • ✅ Complex semantic reasoning
  • ✅ Explanations for rankings
  • ✅ Handling complex queries

Choose Custom if you need:

  • ✅ Proprietary models
  • ✅ Ensemble reranking
  • ✅ Domain-specific scoring

Common Use Cases

Search Result Reranking — Improve BM25 or Elasticsearch rankings

var search = await elasticsearch.SearchAsync(query);
var reranked = await reranker.RerankAsync(query, search.Documents);

RAG Pipeline Enhancement — Improve retrieval quality for LLM context

var retrieved = vectorDb.Search(query, k=50);  // Get many candidates
var refined = await reranker.RerankAsync(query, retrieved, new RerankOptions { TopK = 5 });
var context = refined.Scores.Select(s => s.Item.Text);

Content Ranking — Reorder recommendations by query relevance

var candidates = await db.GetCandidates();
var ranked = await reranker.RerankAsync(userQuery, candidates);

Error Handling

try
{
    var result = await reranker.RerankAsync(query, documents);
}
catch (ArgumentException ex)
{
    // Input validation error (empty query, too many documents)
    Console.WriteLine($"Invalid input: {ex.Message}");
}
catch (RerankerException ex)
{
    // Backend-specific error
    Console.WriteLine($"Reranker failed: {ex.ErrorCode} - {ex.Message}");
}

Contributing

We welcome contributions! Please read CONTRIBUTING.md for guidelines.

License

MIT License — see LICENSE for details.

Author

ElBruno — AI/ML engineer passionate about semantic search and .NET

Acknowledgments

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on ElBruno.Reranking:

Package Downloads
MemPalace.Search

Semantic and hybrid search for MemPalace.NET with vector similarity, keyword boosting, and optional reranking.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.1 396 4/29/2026
0.5.0 110 4/28/2026