![]() |
VOOZH | about |
dotnet add package SemanticKernel.Rankers.Pipelines --version 1.3.5
NuGet\Install-Package SemanticKernel.Rankers.Pipelines -Version 1.3.5
<PackageReference Include="SemanticKernel.Rankers.Pipelines" Version="1.3.5" />
<PackageVersion Include="SemanticKernel.Rankers.Pipelines" Version="1.3.5" />Directory.Packages.props
<PackageReference Include="SemanticKernel.Rankers.Pipelines" />Project file
paket add SemanticKernel.Rankers.Pipelines --version 1.3.5
#r "nuget: SemanticKernel.Rankers.Pipelines, 1.3.5"
#:package SemanticKernel.Rankers.Pipelines@1.3.5
#addin nuget:?package=SemanticKernel.Rankers.Pipelines&version=1.3.5Install as a Cake Addin
#tool nuget:?package=SemanticKernel.Rankers.Pipelines&version=1.3.5Install as a Cake Tool
This project provides reusable pipeline implementations for RAG systems with support for chaining multiple rankers in cascade.
A flexible pipeline implementation that chains multiple rankers in cascade. Each stage filters the top-K results for the next stage until the final top-M results are produced.
Features:
IRanker interface with support for both string documents and VectorSearchResult<T> objectsA specialized two-stage retrieval pipeline for RAG systems:
The CascadeRerankPipeline implements all IRanker methods:
IAsyncEnumerable<(string DocumentText, double Score)> RankAsync(
string query,
IAsyncEnumerable<string> documents,
int topN = 5)
IAsyncEnumerable<(VectorSearchResult<T> Result, double Score)> RankAsync<T>(
string query,
IAsyncEnumerable<VectorSearchResult<T>> documents,
Expression<Func<T, string>> textProperty,
int topN = 5)
IAsyncEnumerable<(string DocumentText, double Score)> ScoreAsync(
string query,
IAsyncEnumerable<string> documents)
IAsyncEnumerable<(VectorSearchResult<T> Result, double Score)> ScoreAsync<T>(
string query,
IAsyncEnumerable<VectorSearchResult<T>> searchResults,
Expression<Func<T, string>> textProperty)
using SemanticKernel.Rankers.Pipelines;
using SemanticKernel.Rankers.BM25;
using SemanticKernel.Rankers.LMRanker;
// Create rankers
var bm25Ranker = new BM25Reranker();
var lmRanker = new LMRanker(/* configuration */);
// Configure pipeline
var config = new CascadeRerankPipelineConfig
{
TopK = 20, // Pass top 20 from each stage to next
TopM = 5, // Final output: top 5 results
ScoreThreshold = 0.1 // Minimum score threshold
};
// Create pipeline
var pipeline = new CascadeRerankPipeline(
new List<IRanker> { bm25Ranker, lmRanker },
config);
// Use for ranking
var documents = new[] { "doc1", "doc2", "doc3" };
var query = "search query";
await foreach (var (docText, score) in pipeline.RankAsync(query, ToAsyncEnumerable(documents), topN: 3))
{
Console.WriteLine($"Document: {docText}, Score: {score}");
}
// For custom document types
public class MyDocument
{
public string Content { get; set; }
public string Title { get; set; }
}
// Rank using content property
await foreach (var (result, score) in pipeline.RankAsync(
query,
ToAsyncEnumerable(searchResults),
doc => doc.Content, // Extract text using this property
topN: 5))
{
Console.WriteLine($"Document: {result.Record.Title}, Score: {score}");
}
Configure K, M, batching, model, thresholds, and prompts via pipeline-specific configuration classes.
The BM25ThenLMRankerPipeline is a specialized implementation using the cascade pipeline with BM25 and LM rankers.
var bm25 = new BM25Reranker(...);
var lmRanker = new LMRanker(...);
var config = new BM25ThenLMRankerPipelineConfig { TopK = 20, TopM = 5 };
var pipeline = new BM25ThenLMRankerPipeline(bm25, lmRanker, config);
var result = await pipeline.RetrieveAndRankAsync(query, corpus);
Console.WriteLine($"Top {result.TopMResults.Count} results retrieved in {result.BM25Time + result.LMTime}");
BM25ThenLMRankerPipeline.RetrieveAndRankAsync(query, corpus) to get top-M results.PipelineResult.| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.