Skip to content

Pinecone

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on official Pinecone OpenAPI specification using AutoSDK
  • Same day update to support new features
  • Updated and supported automatically if there are no breaking changes
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • Support .Net Framework/.Net Standard 2.0

Usage

1
2
3
using Pinecone;

using var client = new PineconeClient(apiKey);

Index Management

Manage Pinecone indexes -- list, describe, and inspect your vector database indexes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// List all indexes in the project.
using var client = new PineconeClient(apiKey);

var indexes = await client.ManageIndexes.ListIndexesAsync();

Console.WriteLine($"Found {indexes.Indexes?.Count ?? 0} indexes");
foreach (var index in indexes.Indexes ?? [])
{
    Console.WriteLine($"  {index.Name}: {index.Metric}, dim={index.Dimension}, host={index.Host}");
}

Embeddings

Generate vector embeddings using Pinecone's hosted embedding models.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
// Generate dense text embeddings using the multilingual-e5-large model.
using var client = new PineconeClient(apiKey);

var response = await client.Inference.EmbedAsync(
    model: "multilingual-e5-large",
    inputs:
    [
        new EmbedRequestInput { Text = "The quick brown fox jumps over the lazy dog." },
        new EmbedRequestInput { Text = "Pinecone is a vector database." },
    ]);

Console.WriteLine($"Model: {response.Model}, Vector type: {response.VectorType}");
foreach (var embedding in response.Data)
{
    if (embedding.IsDense)
    {
        Console.WriteLine($"  Dense embedding: {embedding.Dense!.Values.Count} dimensions");
    }
}

Reranking

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

 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}");
}

Models

List and inspect available Pinecone embedding and reranking models.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// List all available embedding and reranking models.
using var client = new PineconeClient(apiKey);

var response = await client.Inference.ListModelsAsync();

Console.WriteLine($"Found {response.Models?.Count ?? 0} models");
foreach (var model in response.Models ?? [])
{
    Console.WriteLine($"  {model.Model}: type={model.Type}, dim={model.DefaultDimension}");
}

MEAI Tools

Use Pinecone operations as AIFunction tools with any Microsoft.Extensions.AI IChatClient.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
// Create MEAI AIFunction tools for use with any IChatClient.
using var client = new PineconeClient(apiKey);

var tools = new List<AITool>
{
    client.AsListIndexesTool(),
    client.AsDescribeIndexTool(),
    client.AsEmbedTool(),
    client.AsRerankTool(),
    client.AsListModelsTool(),
    client.AsListCollectionsTool(),
};

foreach (var tool in tools.Cast<AIFunction>())
{
    Console.WriteLine($"  Tool: {tool.Name} - {tool.Description}");
}

Support

Priority place for bugs: https://github.com/tryAGI/Pinecone/issues
Priority place for ideas and general questions: https://github.com/tryAGI/Pinecone/discussions
Discord: https://discord.gg/Ca2xhfBf3v

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.