RAGToolkit.AI.DataRetrieval.Cohere
1.0.0
dotnet add package RAGToolkit.AI.DataRetrieval.Cohere --version 1.0.0
NuGet\Install-Package RAGToolkit.AI.DataRetrieval.Cohere -Version 1.0.0
<PackageReference Include="RAGToolkit.AI.DataRetrieval.Cohere" Version="1.0.0" />
<PackageVersion Include="RAGToolkit.AI.DataRetrieval.Cohere" Version="1.0.0" />
<PackageReference Include="RAGToolkit.AI.DataRetrieval.Cohere" />
paket add RAGToolkit.AI.DataRetrieval.Cohere --version 1.0.0
#r "nuget: RAGToolkit.AI.DataRetrieval.Cohere, 1.0.0"
#:package RAGToolkit.AI.DataRetrieval.Cohere@1.0.0
#addin nuget:?package=RAGToolkit.AI.DataRetrieval.Cohere&version=1.0.0
#tool nuget:?package=RAGToolkit.AI.DataRetrieval.Cohere&version=1.0.0
RAGToolkit.AI.DataRetrieval.Cohere
Cohere Rerank API 的 IReranker 实现 —— 手写线格式,不引官方 Cohere SDK。
用法
using System.Net.Http.Headers;
using RAGToolkit.AI.DataRetrieval.Cohere;
var httpClient = new HttpClient { BaseAddress = new Uri("https://api.cohere.com") };
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
var reranker = new CohereReranker(httpClient);
pipeline.ResultProcessors.Add(new RerankingResultProcessor(reranker));
认证归 HttpClient 管 —— 这个类不碰凭据。用 IHttpClientFactory 时把 BaseAddress 和
Authorization 配在注册里即可。
API
public sealed class CohereReranker(
HttpClient httpClient,
string model = "rerank-v3.5",
string requestPath = "/v2/rerank",
int maxDocumentsPerBatch = 1000) : IReranker
线格式
POST /v2/rerank,Authorization: Bearer <token>。
// 请求
{ "model": "rerank-v3.5", "query": "...", "documents": ["...", "..."] }
// 响应
{ "id": "...", "results": [ { "index": 3, "relevance_score": 0.999071 } ], "meta": { /* 忽略 */ } }
不发 top_n。 截断归调用方(TopNResultProcessor);而分批时按批设上限,会在两批合并之前
就把候选丢掉 —— 某批里排第 6、全局其实排第 3 的那条会直接消失。Rag.NET 踩过这个坑:他们的
TopN 一度默认 5,把管线的 TopK 悄悄截掉了(issue #94)。
分批
Cohere 建议单次不要超过 1,000 个文档,所以按 MaxDocumentsPerBatch 分批。
分数跨批可比(cross-encoder 是同一把尺子量每一对 query/document),合并就是一次降序排序,
不是 rank fusion。批内返回的下标会加回偏移量再落回调用方的列表。
没被打分的块保留原位和原分数。
与 TEI 那版的关系
RAGToolkit.AI.DataRetrieval.Tei 是同一套形状 ——
HttpClient 进、分批、合并 —— 只是线格式不同。两个都是手写 HTTP:私有线格式才值得补 provider 包,
标准协议(/v1/chat/completions)就不必了,IChatClient 已经覆盖。
依赖
RAGToolkit.AI.DataRetrieval.Abstractions- 无第三方依赖
许可证
MIT —— 见 LICENSE。
| Product | Versions 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. |
-
net10.0
- RAGToolkit.AI.DataRetrieval.Abstractions (>= 1.0.0)
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 |
|---|---|---|
| 1.0.0 | 41 | 10/9/2026 |