Serina.TagMemory 1.0.2

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Serina.TagMemory" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Serina.TagMemory" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Serina.TagMemory" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Serina.TagMemory --version 1.0.2
                    
#r "nuget: Serina.TagMemory, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Serina.TagMemory&version=1.0.2
                    
Install Serina.TagMemory as a Cake Addin
#tool nuget:?package=Serina.TagMemory&version=1.0.2
                    
Install Serina.TagMemory as a Cake Tool

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

  1. Install the required NuGet packages:
    dotnet add package Serina.TagMemory.Plugin
    dotnet add package Serina.Semantic.Ai.Pipelines.SemanticKernel
    
  2. 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

  1. Receives a Natural Language Query from the user.
  2. Uses Semantic Kernel Pipelines to generate an SQL query.
  3. Executes the SQL Query against the configured database.
  4. 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

  1. Fork the repository.
  2. Create a new branch (feature-xyz).
  3. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 144 4/8/2025
1.0.2 132 4/4/2025