Sql Server Vector
Description
SQL Server can be used as the backing implementation for Flex vector similarity search. Your application code should depend on IFlexVectorStore, while the provider implementation handles table access and SQL details.
Important concepts
IFlexVectorStoreis the contract: app code performs upserts and similarity search through the shared interface.Upsert + search: generated handlers typically call
UpsertAsync(id, vector, metadata, content), and generated queries callSearchAsync(queryVector, topK, filter, minScore).Collections (optional): the SQL Server vector provider also supports
IFlexVectorStoreWithCollectionsfor provisioning operations (e.g., creating a table/collection).
Configuration in DI
Add the provider in your DI composition root (commonly in EndPoints/...CommonConfigs/OtherApplicationServicesConfig.cs or wherever you centralize registrations).
// using Sumeru.Flex; // IFlexVectorStore
public static class OtherApplicationServicesConfig
{
public static IServiceCollection AddOtherApplicationServices(
this IServiceCollection services,
IConfiguration configuration)
{
var section = configuration.GetSection("FlexBase:DataStores:Vector:SqlServer");
var connectionString = section.GetValue<string>("ConnectionString");
var tableName = section.GetValue<string>("TableName");
var dimensions = section.GetValue<int?>("Dimensions") ?? 1536;
services.AddFlexSqlServerVectorStore(
connectionString: connectionString!,
tableName: tableName!,
dimensions: dimensions);
// Flex auto-wires generated Queries/Handlers/Plugins that *use* IFlexVectorStore.
return services;
}
}appsettings.json
Configuration is read from FlexBase:DataStores:Vector:SqlServer.
Examples (template-based)
These examples mirror the generated Query and PostBus handler templates. You do not register these types manually—Flex discovers and wires generated Queries/Handlers/Plugins automatically.
Similarity search (Query)
Upsert a vector record (PostBus handler)
SQL Server considerations
Ensure your SQL Server version supports vector operations for your chosen approach.
If you want Flex to create the table on startup, use
AddFlexSqlServerVectorStoreWithAutoCreate(...)and choose aFlexVectorDistanceMetric.Dimensionsmust match the embedding model you use.
Last updated