Skip to content

Reranking

Rerank documents by relevance to a query using Pinecone's hosted reranking models.

This example assumes using Pinecone; is in scope and apiKey contains your Pinecone API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Rerank documents by relevance to a query.
using var client = new PineconeClient(apiKey);

var doc1 = new Document();
doc1.AdditionalProperties["text"] = "Paris is the capital of France.";

var doc2 = new Document();
doc2.AdditionalProperties["text"] = "Berlin is the capital of Germany.";

var doc3 = new Document();
doc3.AdditionalProperties["text"] = "The Eiffel Tower is in Paris.";

var response = await client.Inference.RerankAsync(
    model: "bge-reranker-v2-m3",
    query: "What is the capital of France?",
    documents: [doc1, doc2, doc3],
    topN: 3,
    returnDocuments: true);

Console.WriteLine($"Reranking model: {response.Model}");
foreach (var result in response.Data)
{
    Console.WriteLine($"  Index: {result.Index}, Score: {result.Score:F4}");
}