SingleStore.SemanticKernel
0.1.0
See the version list below for details.
dotnet add package SingleStore.SemanticKernel --version 0.1.0
NuGet\Install-Package SingleStore.SemanticKernel -Version 0.1.0
<PackageReference Include="SingleStore.SemanticKernel" Version="0.1.0" />
<PackageVersion Include="SingleStore.SemanticKernel" Version="0.1.0" />
<PackageReference Include="SingleStore.SemanticKernel" />
paket add SingleStore.SemanticKernel --version 0.1.0
#r "nuget: SingleStore.SemanticKernel, 0.1.0"
#:package SingleStore.SemanticKernel@0.1.0
#addin nuget:?package=SingleStore.SemanticKernel&version=0.1.0
#tool nuget:?package=SingleStore.SemanticKernel&version=0.1.0
SingleStore connector for Microsoft Semantic Kernel
Attention: The code in this repository is intended for experimental use only and is not fully tested, documented, or supported by SingleStore. Visit the SingleStore Forums to ask questions about this repository.
Repository for SingleStore.SemanticKernel, the official
SingleStore Vector Store Connector
for
Microsoft Semantic Kernel.
Introduction
Semantic Kernel is an SDK that integrates Large Language Models (LLMs) like OpenAI, Azure OpenAI, and Hugging Face with conventional programming languages like C#, Python, and Java. Semantic Kernel achieves this by allowing you to define plugins that can be chained together in just a few lines of code.
Semantic Kernel and .NET provide an abstraction for interacting with Vector Stores and a list of out-of-the-box connectors that implement these abstractions. Features include creating, listing, and deleting collections of records, and uploading, retrieving, and deleting records. The abstraction makes it easy to experiment with a free or locally hosted Vector Store and then switch to a service when there is a need to scale up.
This repository contains the official SingleStore Vector Store Connector implementation for Semantic Kernel.
Overview
The SingleStore Vector Store connector can be used to access and manage data in SingleStore.
The connector has the following characteristics.
| Feature Area | Support |
|---|---|
| Collection maps to | SingleStore table |
| Supported key property types | <ul><li>short</li><li>int</li><li>long</li><li>string</li><li>Guid</li></ul> |
| Supported data property types | <ul><li>bool</li><li>byte</li><li>sbyte</li><li>short</li><li>ushort</li><li>int</li><li>uint</li><li>long</li><li>ulong</li><li>float</li><li>double</li><li>decimal</li><li>string</li><li>DateTime</li><li>DateTimeOffset</li><li>DateOnly (.NET 8 and later only)</li><li>TimeOnly (.NET 8 and later only)</li><li>Guid</li><li>byte[]</li><li>string[]</li><li>List<string></li><li>and nullable variants of the above</li></ul> |
| Supported vector property types | <ul><li>ReadOnlyMemory<float></li><li>Embedding<float></li><li>float[]</li></ul> |
| Supported index types | <ul><li>Dynamic</li><li>Flat</li><li>IvfFlat</li><li>Hnsw</li></ul> |
| Supported distance functions | <ul><li>EuclideanDistance</li><li>EuclideanSquaredDistance</li><li>NegativeDotProductSimilarity</li><li>DotProductSimilarity</li></ul> |
| Supported filter clauses | <ul><li>==, !=</li><li><, <=, >, >=</li><li>&&, \|\|, !</li><li>Contains() over an inline or captured collection of values</li><li>Contains() and Any() over a string[] or List<string> data property</li></ul> |
| Supports multiple vectors in a record | Yes |
| IsIndexed supported? | Yes |
| IsFullTextIndexed supported? | Yes |
| StorageName supported? | Yes |
| HybridSearch supported? | Yes |
Limitations
When initializing SingleStoreDataSource manually, it is necessary to set AllowLoadLocalInfile=true. This enables
LOAD DATA LOCAL INFILE support. Without this, record uploading will fail.
Here is an example of how to set AllowLoadLocalInfile.
SingleStoreDataSource dataSource = new("Host=localhost;Port=3306;Username=root;Password=example;Database=db;AllowLoadLocalInfile=true");
When using the AddSingleStoreVectorStore dependency injection registration method with a connection string,
AllowLoadLocalInfile is enabled automatically.
Getting started
Add the SingleStore Vector Store connector NuGet package to your project.
dotnet add package SingleStore.SemanticKernel --prerelease
You can add the vector store to the IServiceCollection dependency injection container using extension methods provided
by the connector package.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using SingleStore.SemanticKernel;
var kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.Services.AddSingleStoreVectorStore("<Connection String>");
Where <Connection String> is a connection string to the SingleStore instance, in the format
that SingleStore .NET Connector
expects, for example Host=localhost;Port=3306;Database=db;Username=root;Password=secret.
Extension methods that take no parameters are also provided. These require an instance of SingleStoreDataSource to be
separately registered with the dependency injection container. To upload records, ensure that AllowLoadLocalInfile is
enabled:
using Microsoft.Extensions.DependencyInjection;
using SingleStore.SemanticKernel;
using SingleStoreConnector;
// Using IServiceCollection with ASP.NET Core.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<SingleStoreDataSource>(sp =>
new SingleStoreDataSource("<Connection String>;AllowLoadLocalInfile=true"));
builder.Services.AddSingleStoreVectorStore();
You can construct a SingleStore Vector Store instance directly with a custom data source or with a connection string.
using SingleStore.SemanticKernel;
using SingleStoreConnector;
SingleStoreDataSource dataSource = new("<Connection String>;AllowLoadLocalInfile=true");
var vectorStore = new SingleStoreVectorStore(dataSource, ownsDataSource: true);
using SingleStore.SemanticKernel;
var vectorStore = new SingleStoreVectorStore("<Connection String>");
It is possible to construct a direct reference to a named collection with a custom data source or with a connection string.
using SingleStore.SemanticKernel;
using SingleStoreConnector;
SingleStoreDataSource dataSource = new("<Connection String>;AllowLoadLocalInfile=true");
var collection = new SingleStoreCollection<int, Hotel>(dataSource, "skhotels", ownsDataSource: true);
using SingleStore.SemanticKernel;
var collection = new SingleStoreCollection<int, Hotel>("<Connection String>", "skhotels");
Data mapping
The SingleStore Vector Store connector provides a default mapper when mapping from the data model to storage. This mapper directly converts the list of properties defined in the data model to columns in SingleStore.
The following table shows the default key and data property type mapping:
| C# Data Type | SingleStore Type |
|---|---|
| bool | TINYINT |
| byte | TINYINT UNSIGNED |
| sbyte | TINYINT |
| short | SMALLINT |
| ushort | SMALLINT UNSIGNED |
| int | INT |
| uint | INT UNSIGNED |
| long | BIGINT |
| ulong | BIGINT UNSIGNED |
| float | FLOAT |
| double | DOUBLE |
| decimal | DECIMAL(65,30) |
| DateTime | DATETIME(6) |
| DateTimeOffset | DATETIME(6) |
| DateOnly | DATE |
| TimeOnly | TIME(6) |
| string | LONGTEXT |
| byte[] | LONGBLOB |
| Guid | CHAR(36) |
| string[] | JSON |
| List<string> | JSON |
Vector properties are mapped to VECTOR(dimensions, F32).
Property name override
You can specify a storage field name that differs from the corresponding property name in the data model. This allows you to match table column names even if they don't match the property names on the data model.
The property name override is done by setting the StorageName option via the data model attributes or record
definition.
Here is an example of a data model with StorageName set on its attributes and how it will be represented in
SingleStore as a table, assuming the Collection name is Hotels.
using System;
using Microsoft.Extensions.VectorData;
public class Hotel
{
[VectorStoreKey(StorageName = "hotel_id")]
public int HotelId { get; set; }
[VectorStoreData(StorageName = "hotel_name")]
public string HotelName { get; set; }
[VectorStoreData(StorageName = "hotel_description")]
public string Description { get; set; }
[VectorStoreVector(dimensions: 4, DistanceFunction = DistanceFunction.EuclideanDistance, IndexKind = IndexKind.Hnsw, StorageName = "hotel_description_embedding")]
public ReadOnlyMemory<float>? DescriptionEmbedding { get; set; }
}
CREATE TABLE IF NOT EXISTS `db`.`Hotels`
(
`hotel_id` INT NOT NULL,
`hotel_name` LONGTEXT NOT NULL,
`hotel_description` LONGTEXT NOT NULL,
`hotel_description_embedding` VECTOR(4, F32) NULL,
PRIMARY KEY (`hotel_id`),
VECTOR KEY (`hotel_description_embedding`) INDEX_OPTIONS '{ "metric_type":"EUCLIDEAN_DISTANCE", "index_type":"HNSW_FLAT" }'
);
Release process
Releasing a new version takes two steps.
1. Push a version tag
Push a version tag using semantic versioning with a v prefix (v<major>.<minor>.<patch>, for example v1.2.3):
git tag v1.0.1
git push origin v1.0.1
The package version is derived from the tag (the leading v is stripped). This triggers
the CI workflow, which:
- Runs the test matrix
- Builds the connector with the release version
- Signs
SingleStore.SemanticKernel.dllwith Azure Artifact Signing - Packs the signed assemblies into a NuGet package and publishes it to NuGet.org
- Creates a
draft GitHub Release
with auto-generated release notes and the package (
SingleStore.SemanticKernel.<version>.nupkg)
2. Publish the draft release
After the workflow succeeds, open the Releases page, review the draft release for the new tag (edit the notes if needed), and click Publish release.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.VectorData.Abstractions (>= 10.8.0)
- SingleStoreConnector (>= 1.4.0)
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.VectorData.Abstractions (>= 10.8.0)
- SingleStoreConnector (>= 1.4.0)
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.VectorData.Abstractions (>= 10.8.0)
- SingleStoreConnector (>= 1.4.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.VectorData.Abstractions (>= 10.8.0)
- SingleStoreConnector (>= 1.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.