{"id":31789298,"url":"https://github.com/kbeaugrand/semantickernel.rankers","last_synced_at":"2025-10-10T14:50:42.272Z","repository":{"id":310661049,"uuid":"1040163795","full_name":"kbeaugrand/SemanticKernel.Rankers","owner":"kbeaugrand","description":"A robust C# library for reranking search results using Semantic Kernel","archived":false,"fork":false,"pushed_at":"2025-10-03T10:42:24.000Z","size":161,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-05T13:36:14.844Z","etag":null,"topics":["ai","bm25","gpt","llm","reranking","semantickernel"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kbeaugrand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-18T14:50:47.000Z","updated_at":"2025-10-03T10:41:20.000Z","dependencies_parsed_at":"2025-08-19T14:37:06.333Z","dependency_job_id":"3b6c24ee-154c-478d-90f7-00a3cec59323","html_url":"https://github.com/kbeaugrand/SemanticKernel.Rankers","commit_stats":null,"previous_names":["kbeaugrand/semantickernel.reranker","kbeaugrand/semantickernel.rankers"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/kbeaugrand/SemanticKernel.Rankers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbeaugrand%2FSemanticKernel.Rankers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbeaugrand%2FSemanticKernel.Rankers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbeaugrand%2FSemanticKernel.Rankers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbeaugrand%2FSemanticKernel.Rankers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kbeaugrand","download_url":"https://codeload.github.com/kbeaugrand/SemanticKernel.Rankers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kbeaugrand%2FSemanticKernel.Rankers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004183,"owners_count":26083689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","bm25","gpt","llm","reranking","semantickernel"],"created_at":"2025-10-10T14:50:31.898Z","updated_at":"2025-10-10T14:50:42.265Z","avatar_url":"https://github.com/kbeaugrand.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build \u0026 Test](https://github.com/kbeaugrand/SemanticKernel.Rankers/actions/workflows/build_tests.yml/badge.svg)\n![Create Release](https://github.com/kbeaugrand/SemanticKernel.Rankers/actions/workflows/publish.yml/badge.svg)\n![Version](https://img.shields.io/github/v/release/kbeaugrand/SemanticKernel.Rankers)\n![License](https://img.shields.io/github/license/kbeaugrand/SemanticKernel.Rankers)\n\n# Semantic Kernel Rankers\n\n**A robust C# library for reranking search results using Semantic Kernel**\n\n---\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Ranking Pipelines](#ranking-pipelines)\n- [Usage Examples](#usage-examples)\n- [License](#license)\n\n---\n\n## Introduction\n\nThis project provides a flexible C# implementation of Rankers for Microsoft's Semantic Kernel, including:\n\n- **BM25Ranker**: A classic ranking function widely used in search engines, based on term frequency and document length normalization.\n\u003e This ranker supports sophisticated tokenization, lemmatization, stop word removal, and multi-language support through the Catalyst NLP library.\n- **LMRanker**: A neural ranker leveraging advanced language models for semantic reranking.\n- **Ranking Pipelines**: Powerful pipeline implementations that chain multiple rankers in cascade for optimal retrieval performance.\n\n---\n\n## Installation\n\nYou can install the individual packages based on your needs:\n\n```shell\n# For BM25 ranking\ndotnet add package SemanticKernel.Rankers.BM25\n\n# For LM-based ranking  \ndotnet add package SemanticKernel.Rankers.LMRanker\n\n# For ranking pipelines\ndotnet add package SemanticKernel.Rankers.Pipelines\n```\n\n---\n\n## Ranking Pipelines\n\nFor production RAG systems, combining multiple ranking approaches often yields better results than using a single ranker. This library provides powerful pipeline implementations:\n\n### CascadeRerankPipeline\n\nA flexible pipeline 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.\n\n**Key Features:**\n\n- **Multi-stage Filtering**: Each ranker stage processes and filters results for the next stage\n- **Configurable Parameters**: Support for score thresholds, top-K, and top-M filtering\n- **Type Safety**: Full generic support for different document types including `VectorSearchResult\u003cT\u003e`\n- **Async Streaming**: Efficient processing for large document sets\n\n### BM25ThenLMRankerPipeline\n\nA specialized two-stage retrieval pipeline optimized for RAG systems:\n\n1. **BM25 Retrieval**: High-recall lexical retrieval to fetch top-K candidates\n2. **LM Re-ranking**: LLM-based semantic scoring and filtering to select top-M high-precision passages\n\nThis approach balances recall (BM25) and precision (LM re-ranking) while keeping latency and cost within budget.\n\n**Benefits:**\n\n- Improved answerability and reduced hallucinations\n- Configurable trade-offs between recall and precision\n- Built-in observability with timings, token usage, and scores\n\n---\n\n## Usage Examples\n\n### BM25Ranker\n\n```shell\ndotnet add package SemanticKernel.Rankers.BM25\n```\n\n```csharp\nusing SemanticKernel.Rankers.BM25;\n\n// Prepare your documents and query\nvar documents = new List\u003cstring\u003e { \"The quick brown fox\", \"Jumps over the lazy dog\" };\nvar query = \"quick fox\";\n\n// Create and use the BM25Ranker\nvar ranker = new BM25Ranker();\nvar rankedResults = ranker.Rank(query, documents);\n\n// rankedResults is a list of documents ordered by relevance\n```\n\n### LMRanker\n\n```shell\ndotnet add package SemanticKernel.Rankers.LMRanker\n```\n\n```csharp\nusing SemanticKernel.Rankers.LMRanker;\n\n// Prepare your documents and query\nvar documents = new List\u003cstring\u003e { \"The quick brown fox\", \"Jumps over the lazy dog\" };\nvar query = \"quick fox\";\n\n// Create and use the LMRanker\nvar ranker = new LMRanker();\nvar rankedResults = await ranker.RankAsync(query, documents);\n\n// rankedResults is a list of documents ordered by semantic relevance\n```\n\n### Pipeline Usage Examples\n\n```shell\ndotnet add package SemanticKernel.Rankers.Pipelines\n```\n\n#### Using CascadeRerankPipeline\n\n```csharp\nusing SemanticKernel.Rankers.Pipelines;\nusing SemanticKernel.Rankers.BM25;\nusing SemanticKernel.Rankers.LMRanker;\n\n// Create rankers\nvar bm25Ranker = new BM25Reranker();\nvar lmRanker = new LMRanker(/* configuration */);\n\n// Configure pipeline\nvar config = new CascadeRerankPipelineConfig\n{\n    TopK = 20,           // Pass top 20 from each stage to next\n    TopM = 5,            // Final output: top 5 results\n    ScoreThreshold = 0.1 // Minimum score threshold\n};\n\n// Create pipeline\nvar pipeline = new CascadeRerankPipeline(\n    new List\u003cIRanker\u003e { bm25Ranker, lmRanker }, \n    config);\n\n// Use for ranking\nvar documents = new[] { \"The quick brown fox\", \"Jumps over the lazy dog\", \"Another document\" };\nvar query = \"quick fox\";\n\nawait foreach (var (docText, score) in pipeline.RankAsync(query, documents.ToAsyncEnumerable(), topN: 3))\n{\n    Console.WriteLine($\"Document: {docText}, Score: {score}\");\n}\n```\n\n#### Using BM25ThenLMRankerPipeline\n\n```csharp\nusing SemanticKernel.Rankers.Pipelines;\n\n// Create specialized pipeline\nvar bm25 = new BM25Reranker();\nvar lmRanker = new LMRanker();\nvar config = new BM25ThenLMRankerPipelineConfig { TopK = 20, TopM = 5 };\nvar pipeline = new BM25ThenLMRankerPipeline(bm25, lmRanker, config);\n\n// Retrieve and rank with observability\nvar result = await pipeline.RetrieveAndRankAsync(query, corpus);\nConsole.WriteLine($\"Retrieved {result.TopMResults.Count} results in {result.BM25Time + result.LMTime}ms\");\n```\n\n---\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbeaugrand%2Fsemantickernel.rankers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkbeaugrand%2Fsemantickernel.rankers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkbeaugrand%2Fsemantickernel.rankers/lists"}