Encamina.Enmarcha.SemanticKernel
8.2.0-preview-01-m01
See the version list below for details.
dotnet add package Encamina.Enmarcha.SemanticKernel --version 8.2.0-preview-01-m01
NuGet\Install-Package Encamina.Enmarcha.SemanticKernel -Version 8.2.0-preview-01-m01
<PackageReference Include="Encamina.Enmarcha.SemanticKernel" Version="8.2.0-preview-01-m01" />
paket add Encamina.Enmarcha.SemanticKernel --version 8.2.0-preview-01-m01
#r "nuget: Encamina.Enmarcha.SemanticKernel, 8.2.0-preview-01-m01"
// Install Encamina.Enmarcha.SemanticKernel as a Cake Addin #addin nuget:?package=Encamina.Enmarcha.SemanticKernel&version=8.2.0-preview-01-m01&prerelease // Install Encamina.Enmarcha.SemanticKernel as a Cake Tool #tool nuget:?package=Encamina.Enmarcha.SemanticKernel&version=8.2.0-preview-01-m01&prerelease
Semantic Kernel
This project provides extended functionality for Semantic Kernel and additional features related to Semantic Kernel.
Setup
Nuget package
First, install NuGet. Then, install Encamina.Enmarcha.SemanticKernel from the package manager console:
PM> Install-Package Encamina.Enmarcha.SemanticKernel
.NET CLI:
Install .NET CLI](https://learn.microsoft.com/en-us/dotnet/core/tools/). Next, install Encamina.Enmarcha.SemanticKernel from the .NET CLI:
dotnet add package Encamina.Enmarcha.SemanticKernel
How to use
MemoryManager
MemoryManager provides some CRUD operations over memories with multiple chunks that need to be managed IMemoryManager
, using batch operations.
Starting from a Program.cs
or a similar entry point file in your project, add the following code:
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
// ...
});
// ...
builder.Services.AddScoped(sp =>
{
var kernel = new KernelBuilder()
.WithAzureTextEmbeddingGenerationService("<YOUR DEPLOYMENT NAME>", "<YOUR AZURE ENDPOINT>", "<YOUR API KEY>")
//.WithOpenAITextEmbeddingGenerationService("<YOUR MODEL ID>", "<YOUR API KEY>")
// ...
.Build();
// ...
return kernel;
});
// Here use the desired implementation (Qdrant, Volatile...)
builder.Services.AddSingleton<IMemoryStore, VolatileMemoryStore>();
builder.Services.AddMemoryManager();
This extension method will add the default implementation of the IMemoryManager interface as a singleton. The default implementation is MemoryManager. With this, we can resolve the IMemoryManager
via constructor.
public class MyClass
{
private readonly IMemoryManager memoryManager;
public MyClass(IMemoryManager memoryManager)
{
this.memoryManager = memoryManager;
}
public async Task TestMemoryManagerAsync()
{
await memoryManager.UpsertMemoryAsync("123456", "my-collection", new List<string>() { "First chunk", "Second chunk", "Third chunk" }, CancellationToken.None);
var memoryContent = await memoryManager.GetMemoryAsync("123456", "my-collection", CancellationToken.None);
// memoryContent.Chunks contains "First chunk", "Second chunk", "Third chunk" chunks
}
}
EphemeralMemoryStoreHandler
EphemeralMemoryStoreHandler is a memory store handler that removes collections from memory after a configured time (thus ephemeral) of inactivity. First, you need to add the EphemeralMemoryStoreHandlerOptions to your project configuration. You can achieve this by using any configuration provider. The followng code is an example of how the settings would appear using the appsettings.json file:
{
// ...
"EphemeralMemoryStoreHandlerOptions": {
"IdleTimeoutMinutes": 60, // Idle time in minutes after which a memory is considered inactive and can be removed from the memory store.
"InactivePollingTimeMinutes": 10, // Time in minutes to wait before polling for inactive memories
},
// ...
}
Next, in Program.cs
or a similar entry point file in your project, add the following code:
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
// ...
});
// ...
// Or others configuration providers...
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
builder.Services.AddOptions<EphemeralMemoryStoreHandlerOptions>().Bind(builder.Configuration.GetSection(nameof(EphemeralMemoryStoreHandlerOptions)))
.ValidateDataAnnotations()
.ValidateOnStart();
// Here use the desired implementation (Qdrant, Volatile...)
builder.Services.AddSingleton<IMemoryStore, VolatileMemoryStore>();
builder.Services.AddEphemeralMemoryStoreHandler(builder.Configuration);
This extension method will add EphemeralMemoryStoreHandler as implementation of the IMemoryStoreHandler interface as a singleton. Now you can inject IMemoryStoreHandler
via constructor.
public class MyClass
{
private readonly IMemoryStoreHandler memoryStoreHandler;
public MyClass(IMemoryStoreHandler memoryStoreHandler)
{
this.memoryStoreHandler = memoryStoreHandler;
}
public async Task TestGetCollectionnameAsync()
{
var collectionName = await memoryStoreHandler.GetCollectionNameAsync("my-collection", CancellationToken.None);
}
}
This allows the my-collection collection stored in memory to be tracked, and after EphemeralMemoryStoreHandlerOptions.IdleTimeoutMinutes since the last access to the collection through the GetCollectionNameAsync
method, it will be deleted.
KernelExtensions
Contains extension methods for Kernel. You can see all available extension methods in the KernelExtensions class.
var mySemanticFunction = kernel.Skills.GetFunction("MyFunctionName");
var myContextVariables = new ContextVariables();
myContextVariables.Set(@"input", "Dummy input");
// Calculates the current total number of tokens used in generating a prompt of a mySemanticFunction from embedded resources in an assembly, using myContextVariables.
var mySemanticFunctionUsedTokens = await kernel.GetSemanticFunctionUsedTokensAsync(mySemanticFunction, Assembly.GetExecutingAssembly(), myContextVariables, ILengthFunctions.LengthByTokenCount, CancellationToken.None);
// ...
// Imports plugins with semantic functions from embedded resources in an assembly that represents their prompt and configuration files.
kernel.ImportSemanticPluginsFromAssembly(Assembly.GetExecutingAssembly());
// More extensions methods availables...
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 was computed. 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. |
-
net6.0
- CommunityToolkit.Diagnostics (>= 8.2.2)
- Encamina.Enmarcha.Core (>= 8.2.0-preview-01-m01)
- Encamina.Enmarcha.Data.Abstractions (>= 8.2.0-preview-01-m01)
- Encamina.Enmarcha.SemanticKernel.Abstractions (>= 8.2.0-preview-01-m01)
- Microsoft.Extensions.Hosting (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 8.0.0)
- System.Linq.Async (>= 6.0.1)
- System.Numerics.Tensors (>= 8.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Encamina.Enmarcha.SemanticKernel:
Package | Downloads |
---|---|
Encamina.Enmarcha.SemanticKernel.Plugins.Memory
Package Description |
|
Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering
Package Description |
|
Encamina.Enmarcha.SemanticKernel.Plugins.Text
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.2.0 | 346 | 10/22/2024 |
8.2.0-preview-01-m01 | 127 | 9/17/2024 |
8.1.9-preview-03 | 87 | 11/19/2024 |
8.1.9-preview-02 | 97 | 10/22/2024 |
8.1.9-preview-01 | 279 | 10/4/2024 |
8.1.8 | 230 | 9/23/2024 |
8.1.8-preview-07 | 398 | 9/12/2024 |
8.1.8-preview-06 | 218 | 9/11/2024 |
8.1.8-preview-05 | 122 | 9/10/2024 |
8.1.8-preview-04 | 308 | 8/16/2024 |
8.1.8-preview-03 | 178 | 8/13/2024 |
8.1.8-preview-02 | 138 | 8/13/2024 |
8.1.8-preview-01 | 143 | 8/12/2024 |
8.1.7 | 146 | 8/7/2024 |
8.1.7-preview-09 | 210 | 7/3/2024 |
8.1.7-preview-08 | 122 | 7/2/2024 |
8.1.7-preview-07 | 118 | 6/10/2024 |
8.1.7-preview-06 | 115 | 6/10/2024 |
8.1.7-preview-05 | 140 | 6/6/2024 |
8.1.7-preview-04 | 118 | 6/6/2024 |
8.1.7-preview-03 | 133 | 5/24/2024 |
8.1.7-preview-02 | 110 | 5/10/2024 |
8.1.7-preview-01 | 134 | 5/8/2024 |
8.1.6 | 1,377 | 5/7/2024 |
8.1.6-preview-08 | 98 | 5/2/2024 |
8.1.6-preview-07 | 127 | 4/29/2024 |
8.1.6-preview-06 | 403 | 4/26/2024 |
8.1.6-preview-05 | 118 | 4/24/2024 |
8.1.6-preview-04 | 129 | 4/22/2024 |
8.1.6-preview-03 | 116 | 4/22/2024 |
8.1.6-preview-02 | 158 | 4/17/2024 |
8.1.6-preview-01 | 219 | 4/15/2024 |
8.1.5 | 127 | 4/15/2024 |
8.1.5-preview-15 | 134 | 4/10/2024 |
8.1.5-preview-14 | 157 | 3/20/2024 |
8.1.5-preview-13 | 97 | 3/18/2024 |
8.1.5-preview-12 | 141 | 3/13/2024 |
8.1.5-preview-11 | 117 | 3/13/2024 |
8.1.5-preview-10 | 148 | 3/13/2024 |
8.1.5-preview-09 | 112 | 3/12/2024 |
8.1.5-preview-08 | 124 | 3/12/2024 |
8.1.5-preview-07 | 124 | 3/8/2024 |
8.1.5-preview-06 | 282 | 3/8/2024 |
8.1.5-preview-05 | 117 | 3/7/2024 |
8.1.5-preview-04 | 133 | 3/7/2024 |
8.1.5-preview-03 | 130 | 3/7/2024 |
8.1.5-preview-02 | 206 | 2/28/2024 |
8.1.5-preview-01 | 175 | 2/19/2024 |
8.1.4 | 277 | 2/15/2024 |
8.1.3 | 168 | 2/13/2024 |
8.1.3-preview-07 | 102 | 2/13/2024 |
8.1.3-preview-06 | 126 | 2/12/2024 |
8.1.3-preview-05 | 133 | 2/9/2024 |
8.1.3-preview-04 | 131 | 2/8/2024 |
8.1.3-preview-03 | 121 | 2/7/2024 |
8.1.3-preview-02 | 109 | 2/2/2024 |
8.1.3-preview-01 | 110 | 2/2/2024 |
8.1.2 | 256 | 2/1/2024 |
8.1.2-preview-9 | 133 | 1/22/2024 |
8.1.2-preview-8 | 117 | 1/19/2024 |
8.1.2-preview-7 | 111 | 1/19/2024 |
8.1.2-preview-6 | 116 | 1/19/2024 |
8.1.2-preview-5 | 113 | 1/19/2024 |
8.1.2-preview-4 | 112 | 1/19/2024 |
8.1.2-preview-3 | 110 | 1/18/2024 |
8.1.2-preview-2 | 126 | 1/18/2024 |
8.1.2-preview-16 | 122 | 1/31/2024 |
8.1.2-preview-15 | 118 | 1/31/2024 |
8.1.2-preview-14 | 233 | 1/25/2024 |
8.1.2-preview-13 | 112 | 1/25/2024 |
8.1.2-preview-12 | 117 | 1/23/2024 |
8.1.2-preview-11 | 120 | 1/23/2024 |
8.1.2-preview-10 | 98 | 1/22/2024 |
8.1.2-preview-1 | 111 | 1/18/2024 |
8.1.1 | 172 | 1/18/2024 |
8.1.0 | 134 | 1/18/2024 |
8.0.3 | 193 | 12/29/2023 |
8.0.1 | 149 | 12/14/2023 |
8.0.0 | 189 | 12/7/2023 |
6.0.4.3 | 241 | 12/29/2023 |
6.0.4.2 | 219 | 12/20/2023 |
6.0.4.1 | 271 | 12/19/2023 |
6.0.4 | 235 | 12/4/2023 |
6.0.3.20 | 218 | 11/27/2023 |
6.0.3.19 | 210 | 11/22/2023 |