![]() |
VOOZH | about |
dotnet add package TiDB.Vector --version 1.3.1
NuGet\Install-Package TiDB.Vector -Version 1.3.1
<PackageReference Include="TiDB.Vector" Version="1.3.1" />
<PackageVersion Include="TiDB.Vector" Version="1.3.1" />Directory.Packages.props
<PackageReference Include="TiDB.Vector" />Project file
paket add TiDB.Vector --version 1.3.1
#r "nuget: TiDB.Vector, 1.3.1"
#:package TiDB.Vector@1.3.1
#addin nuget:?package=TiDB.Vector&version=1.3.1Install as a Cake Addin
#tool nuget:?package=TiDB.Vector&version=1.3.1Install as a Cake Tool
Ergonomic C# SDK for TiDB Vector Search: upsert, search, and RAG with a fluent builder, OpenAI embeddings/chat integration, and DX-first defaults.
Repository: manasseh-zw/TiDB.Vector.NET
# Core package with OpenAI built-in (recommended)
dotnet add package TiDB.Vector
# Azure OpenAI integration (optional, extends core)
dotnet add package TiDB.Vector.AzureOpenAI
MySqlConnectorAskAsync) that cites sources.env support via dotenv.netTiDB.Vector - Core package with vector store functionality
TiDB.Vector.AzureOpenAI - Azure OpenAI integration (embeddings + chat)
TiDB.Vector (Core): store API, schema, SQL
TiDB.Vector.AzureOpenAI: Azure OpenAI providers (embeddings/chat)
TiDB.Vector.Samples: runnable examples (upsert, search, ask)
# Core package with OpenAI built-in (recommended)
dotnet add package TiDB.Vector
# Azure OpenAI integration (optional, extends core)
dotnet add package TiDB.Vector.AzureOpenAI
| Package | Vector Store | Embeddings | Chat/RAG | Notes |
|---|---|---|---|---|
TiDB.Vector |
✅ | ✅ | ✅ | Full functionality with OpenAI built-in |
TiDB.Vector + TiDB.Vector.AzureOpenAI |
✅ | ✅ | ✅ | Full functionality + Azure OpenAI support |
Note: The core package now provides everything you need! Azure OpenAI is an optional extension for Azure-specific features.
git clone https://github.com/manasseh-zw/TiDB.Vector.NET
cd TiDB.Vector.NET
.env file in TiDB.Vector.Samples/:# Required for all samples
TIDB_CONN_STRING=Server=<host>;Port=4000;User ID=<user>;Password=<pwd>;Database=<db>;SslMode=VerifyFull;
# For OpenAI samples
OPENAI_API_KEY=sk-...
# For Azure OpenAI samples
AZURE_AI_APIKEY=your-azure-key
AZURE_AI_ENDPOINT=https://your-resource.openai.azure.com/
dotnet run --project TiDB.Vector.Samples
The samples include:
Each sample will:
AskAsync to answer questions using retrieved contextusing TiDB.Vector.Core;
using TiDB.Vector.OpenAI.Builder; // Built into TiDB.Vector core package
var store = new TiDBVectorStoreBuilder(
Environment.GetEnvironmentVariable("TIDB_CONN_STRING")!)
.WithDefaultCollection("docs")
.WithDistanceFunction(DistanceFunction.Cosine)
.AddOpenAI(Environment.GetEnvironmentVariable("OPENAI_API_KEY")!)
.AddOpenAITextEmbedding("text-embedding-3-small", 1536)
.AddOpenAIChatCompletion("gpt-4o-mini")
.EnsureSchema(createVectorIndex: true)
.Build();
var store = new TiDBVectorStoreBuilder(connectionString)
.AddOpenAI("your-api-key", "https://your-local-model.com/v1")
.AddOpenAITextEmbedding("your-embedding-model", 1536)
.AddOpenAIChatCompletion("your-chat-model")
.Build();
var store = new TiDBVectorStoreBuilder(connectionString)
.AddAzureOpenAI("your-azure-key", "https://your-resource.openai.azure.com/")
.AddAzureOpenAITextEmbedding("your-embedding-deployment", 1536)
.AddAzureOpenAIChatCompletion("your-chat-deployment")
.Build();
await store.EnsureSchemaAsync();
await store.UpsertAsync(new UpsertItem
{
Id = "sample-1",
Collection = "docs",
Content = "Fish live in water and are known for their swimming abilities."
});
var results = await store.SearchAsync("a swimming animal", topK: 3);
var answer = await store.AskAsync("Name an animal that swims.");
The SDK supports powerful filtering capabilities for multi-tenant and fine-grained search:
Filter by a specific collection (one at a time for simplicity):
var results = await store.SearchAsync(
"query",
searchOptions: new SearchOptions { Collection = "engineering-docs" }
);
Type-safe tag filters using Tag and TagFilter:
using TiDB.Vector.Models;
var results = await store.SearchAsync(
"query",
searchOptions: new SearchOptions
{
TagFilter = new TagFilter(new[]
{
new Tag("OrganizationId", "org-123"),
new Tag("Department", "Engineering")
}, TagFilterMode.And)
}
);
var results = await store.SearchAsync(
"query",
searchOptions: new SearchOptions
{
Collection = "engineering-docs",
TagFilter = new TagFilter(new[]
{
new Tag("OrganizationId", "org-123"),
new Tag("Department", "Engineering")
}, TagFilterMode.And)
}
);
When upserting documents, use the dedicated tags column with Tag:
await store.UpsertAsync(new UpsertItem
{
Id = "doc-1",
Collection = "engineering-docs",
Content = "How to implement microservices...",
Source = "https://docs.company.com/guide.pdf",
Metadata = JsonDocument.Parse("""
{
"Category": "Architecture",
"Tags": ["microservices", "docker"]
}
"""),
Tags = new[] { new Tag("OrganizationId", "org-123"), new Tag("Department", "Engineering") }
});
Use filtering in RAG queries:
var answer = await store.AskAsync(
"What are the best practices for software development?",
topK: 3,
searchOptions: new SearchOptions
{
Collection = "engineering-docs",
TagFilter = new Tag("Department", "Engineering")
}
);
using TiDB.Vector.Core;
using TiDB.Vector.AzureOpenAI.Builder;
var store = new TiDBVectorStoreBuilder(
Environment.GetEnvironmentVariable("TIDB_CONN_STRING")!)
.WithDefaultCollection("docs")
.WithDistanceFunction(DistanceFunction.Cosine)
.AddAzureOpenAI(
Environment.GetEnvironmentVariable("AZURE_AI_APIKEY")!,
Environment.GetEnvironmentVariable("AZURE_AI_ENDPOINT")!)
.AddAzureOpenAITextEmbedding("your-embedding-deployment", 1536)
.AddAzureOpenAIChatCompletion("your-chat-deployment")
.EnsureSchema(createVectorIndex: true)
.Build();
tidb_vectors
collection VARCHAR(128) + id VARCHAR(64) as composite primary keyembedding VECTOR (variable dimensions supported)content TEXT, metadata JSON, source VARCHAR(512), tags JSON, timestampsCREATE VECTOR INDEX idx_tidb_vectors_embedding_cosine ON tidb_vectors ((VEC_COSINE_DISTANCE(embedding))) USING HNSW;CREATE VECTOR INDEX idx_tidb_vectors_embedding_l2 ON tidb_vectors ((VEC_L2_DISTANCE(embedding))) USING HNSW;Schema Features:
Filtering Performance:
Built into the core package using the official OpenAI .NET SDK 2.x:
EmbeddingClient (text-embedding-3-small 1536 dims, text-embedding-3-large 3072 dims)ChatClient (e.g., gpt-4o-mini)Ensure the table dimension matches the chosen embedding model’s dimension.
Use standard ADO.NET format (not URL form), e.g.:
Server=<host>;Port=4000;User ID=<user>;Password=<pwd>;Database=<db>;SslMode=VerifyFull;
If you must provide a custom CA bundle, append:
SslCa=C:\\path\\to\\isrgrootx1.pem;
The project now has OpenAI integration built into the core package:
TiDB.Vector - Core vector store functionality + OpenAI integration built-inTiDB.Vector.AzureOpenAI - Azure OpenAI integration (extends core capabilities)Note: Users now get full AI functionality with just the core package! Azure OpenAI is available as an optional extension.
We're planning to restructure the architecture for better user experience:
TiDB.Vector - Core + OpenAI integration built-in by defaultTiDB.Vector.AzureOpenAI - Azure-specific optimizationsTiDB.Vector.GoogleGemini - Google Gemini integrationTiDB.Vector.Anthropic - Anthropic Claude integrationTiDB.Vector.Custom - Template for custom provider implementationsAskAsync ✅We welcome issues and PRs! To contribute:
dotnet build before submitting your PROpen an issue to discuss larger proposals or provider integrations. Repo: manasseh-zw/TiDB.Vector.NET
| 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. |
Showing the top 2 NuGet packages that depend on TiDB.Vector:
| Package | Downloads |
|---|---|
|
TiDB.Vector.AzureOpenAI
Azure OpenAI integration for TiDB.Vector. Provides Azure OpenAI embeddings and chat completion capabilities. Requires TiDB.Vector core package. |
|
|
TiDB.Vector.OpenAI
OpenAI integration for TiDB.Vector. Provides OpenAI embeddings and chat completion capabilities. Requires TiDB.Vector core package. |
This package is not used by any popular GitHub repositories.