Serina.TagMemory
1.0.2
See the version list below for details.
dotnet add package Serina.TagMemory --version 1.0.2
NuGet\Install-Package Serina.TagMemory -Version 1.0.2
<PackageReference Include="Serina.TagMemory" Version="1.0.2" />
<PackageVersion Include="Serina.TagMemory" Version="1.0.2" />
<PackageReference Include="Serina.TagMemory" />
paket add Serina.TagMemory --version 1.0.2
#r "nuget: Serina.TagMemory, 1.0.2"
#addin nuget:?package=Serina.TagMemory&version=1.0.2
#tool nuget:?package=Serina.TagMemory&version=1.0.2
Semantic Kernel Database Query Plugin
Overview
This plugin enables natural language interaction with databases using Large Language Models (LLMs) via Semantic Kernel. It translates user queries into SQL and executes them against a configured database, supporting PostgreSQL, SQL Server, and more.
Features
- Natural Language to SQL: Converts user descriptions into executable SQL queries.
- LLM Model Integration: Works with models like Ollama.
- Schema Scanning: Can introspect database structure for improved query generation.
- Configurable Pipelines: Leverages Semantic Kernel with customizable AI pipelines.
- Multiple Database Support: Works with PostgreSQL, SQL Server, etc.
- Dependency Injection: Seamlessly integrates with .NET applications.
Installation
- Install the required NuGet packages:
dotnet add package Serina.TagMemory.Plugin dotnet add package Serina.Semantic.Ai.Pipelines.SemanticKernel
- Ensure you have a compatible LLM model (e.g., Ollama running at a local or remote endpoint).
Configuration
To use this plugin, configure dependency injection in your .NET 8 application:
var serviceProvider = new ServiceCollection()
.AddSingleton(new MemoryConfig
{
ModelName = "dolphin-llama3:8b",
Endpoint = "http://192.168.88.104:11434",
EngineType = EngineType.Ollama,
EngineTypeDescription = "This is SQLServer use T-SQL syntax",
ScanSchema = true,
Examples = new()
{
@"SELECT TOP (1000) [UserId], [Username], [Email] FROM [shared].[dbo].[Users]"
}
})
.AddSingleton(new DbConnectionConfig
{
ConnectionString = "Host=localhost;Database=mydb;Username=user;Password=pass",
DbType = "PostgreSQL",
EnableScaffolding = true
})
.AddScoped<SqlMemoryPlugin>()
.AddTagMemory()
.AddTransient<IDbConnector>(x => new SqlServerConnector("Server=192.168.88.230;Database=shared;User Id=sa;Password=yourpassword;Encrypt=False;TrustServerCertificate=True;"))
.AddSingleton<TestService>()
.BuildServiceProvider();
Usage
Running a Query from Natural Language Input
var testService = serviceProvider.GetRequiredService<TestService>();
await testService.RunTestAsync();
Inside TestService
, queries are processed as follows:
public async Task RunTestAsync()
{
var plugin = _factory.WithMemoryConfig(_config)
.WithDbConnector(_connector).Result
.BuildPlugin();
while (true)
{
Console.WriteLine("Enter a query description:");
string userInput = Console.ReadLine() ?? "Show me all shipped orders";
string jsonResult = await plugin.ProcessQueryAsync(userInput);
Console.WriteLine("\nGenerated JSON Result:");
Console.WriteLine(jsonResult);
}
}
How It Works
- Receives a Natural Language Query from the user.
- Uses Semantic Kernel Pipelines to generate an SQL query.
- Executes the SQL Query against the configured database.
- Returns Results as a JSON object.
Building AI Pipelines
The plugin builds Semantic Kernel pipelines for query generation and refinement:
PipelineBuilder.New().New(new SimpleChatStep())
.WithKernel(new SemanticKernelOptions
{
Models = new List<SemanticModelOption>
{
new SemanticModelOption
{
Endpoint = _config.Endpoint,
Name = _config.ModelName,
Key = _config.Key,
EngineType = (int)_config.EngineType
}
}
})
.AttachKernel()
.AddReducer(new PairedSlidingWindowReducer())
.WithName("SqlGenerator")
.Build();
Supported Databases
- PostgreSQL
- SQL Server
- (More coming soon...)
Contributing
- Fork the repository.
- Create a new branch (
feature-xyz
). - Submit a pull request. https://github.com/pashkovdenis/serina-tag-memory
License
MIT License - Free for personal and commercial use.
Contact & Support
For questions or issues, open an issue on GitHub or reach out via [your contact details].
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- Dapper (>= 2.1.66)
- Dapper.Extensions.NetCore (>= 5.2.0)
- Dapper.Extensions.PostgreSQL (>= 5.2.0)
- Dapper.SqlBuilder (>= 2.1.66)
- Microsoft.Data.SqlClient (>= 6.0.1)
- Npgsql (>= 9.0.3)
- Serina.Semantic.Ai.Pipelines (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.