Encamina.Enmarcha.SemanticKernel.Connectors.Memory 8.2.0

dotnet add package Encamina.Enmarcha.SemanticKernel.Connectors.Memory --version 8.2.0                
NuGet\Install-Package Encamina.Enmarcha.SemanticKernel.Connectors.Memory -Version 8.2.0                
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="Encamina.Enmarcha.SemanticKernel.Connectors.Memory" Version="8.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Encamina.Enmarcha.SemanticKernel.Connectors.Memory --version 8.2.0                
#r "nuget: Encamina.Enmarcha.SemanticKernel.Connectors.Memory, 8.2.0"                
#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.
// Install Encamina.Enmarcha.SemanticKernel.Connectors.Memory as a Cake Addin
#addin nuget:?package=Encamina.Enmarcha.SemanticKernel.Connectors.Memory&version=8.2.0

// Install Encamina.Enmarcha.SemanticKernel.Connectors.Memory as a Cake Tool
#tool nuget:?package=Encamina.Enmarcha.SemanticKernel.Connectors.Memory&version=8.2.0                

Semantic Kernel - Memory Connectors

Nuget package

Memory Connectors is a project that allows adding specific IMemoryStore instances. These IMemoryStore instances are used for storing and retrieving embeddings.

Setup

Nuget package

First, install NuGet. Then, install Encamina.Enmarcha.SemanticKernel.Connectors.Memory from the package manager console:

PM> Install-Package Encamina.Enmarcha.SemanticKernel.Connectors.Memory

.NET CLI:

Install .NET CLI. Next, install Encamina.Enmarcha.SemanticKernel.Connectors.Memory from the .NET CLI:

dotnet add package Encamina.Enmarcha.SemanticKernel.Connectors.Memory

How to use

First, if you want use Qdrant memory provider you need to add the QdrantOptions 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:

// ...
  "QdrantOptions": {
    "Host": "https://sample-qdrant.azurewebsites.net/", // Endpoint protocol and host
    "Port": 6333, // Endpoint port
    "VectorSize": 1536, // Vector size
    "ApiKey": "xxxxxxxxxx" // API Key used by Qdrant as a form of client authentication.
  },
// ...

If you want to use Azure AI Search as a memory provider, you need to add the AzureSearchOptions to your project configuration. You can achieve this by using any configuration provider. The following code is an example of how the settings would appear using the appsettings.json file:

// ...
  "AzureSearchOptions": {
    "Endpoint": "https://sample-searchendpoint/", // Endpoint
    "Key": "xxxxxxxxxx" // API Key used by Azure Search AI as a form of client authentication.
  },
// ...


Next, in `Program.cs` or a similar entry point file in your project, add the following code:

```csharp
// Entry point
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
   // ...
});

// ...

// Or others configuration providers...
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); 

builder.Services.AddOptions<QdrantOptions>().Bind(builder.Configuration.GetSection(nameof(QdrantOptions)))
    .ValidateDataAnnotations()
    .ValidateOnStart();

// Adds Qdrant as IMemoryStore
services.AddQdrantMemoryStore();

// Or adds Azure AI Search as IMemoryStore
services.AddAzureAISearchMemoryStore();

If you need add both memory providers, you can use the following code:


   
   services.AddAzureAISearchNamedMemoryStore("AzureAISearchMemoryStore");  //AzureAISearchMemoryStore is the name of the memory store that you can use in the future to inject the IMemoryStore
   services.AddQdrantNamedMemoryStore("QdrantMemoryStore"); //QdrantMemoryStore is the name of the memory store that you can use in the future to inject the IMemoryStore

In the previous code, it can be observed that in the first part is necessary to add certain Qdrant configurations that are available in the Encamina.Enmarcha.Data.Qdrant.Abstractions nuget package. The last line of code corresponds to an extension method that will add the specified implementation of the IMemoryStore interface as a singleton. With this, you have Qdrant configured as the storage to save and retrieve embeddings.

After the initial configuration, we typically configure Semantic Kernel as Scoped.

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>", "<YOUR API KEY>")
        /// ...
        .Build();

    // ...

    return kernel;
});

Once configured, you can now use Semantic Kernel, and it will utilize the Qdrant storage we have previously set up (in addition to generating the embeddings).

public class MyClass
{
    private readonly Kernel kernel;

    public MyClass(Kernel kernel)
    {
        this.kernel = kernel;
    }

    public async Task MyTestMethodAsync()
    {
        await kernel.Memory.SaveInformationAsync("my-collection", "my dummy text", Guid.NewGuid().ToString());
        var memoryQueryResult = await kernel.Memory.SearchAsync("my-collection", "my similar dummy text")
            .ToListAsync(); // ToListAsync method is provided by System.Linq.Async nuget https://www.nuget.org/packages/System.Linq.Async
    }
}

If you prefer, you can inject the ISemanticTextMemory interface directly.

public class MyClass
{   
    private readonly ISemanticTextMemory semanticTextMemory;

    public MyClass(ISemanticTextMemory semanticTextMemory)
    {
        this.semanticTextMemory = semanticTextMemory;
    }

    public async Task MyTestMethodAsync()
    {
        await semanticTextMemory.SaveInformationAsync("my-collection", "my dummy text", Guid.NewGuid().ToString());
        var memoryQueryResult = await semanticTextMemory.SearchAsync("my-collection", "my similar dummy text")
            .ToListAsync(); // ToListAsync method is provided by System.Linq.Async nuget https://www.nuget.org/packages/System.Linq.Async
    }
}

If use NamedKeys, you can use the following code:


    internal class YourClassWithAzureSearch 
    {
        private readonly Kernel kernel;

        public YourClass([FromKeyedServices("Your Provider Name , fe: 'AzureAISearchMemoryStore'")]Kernel kernel)
        {
            this.kernel = kernel;
        }
    }

    internal class YourClassWithQdrant
    {
        private readonly Kernel kernel;

        public YourClass([FromKeyedServices("Your Provider Name , fe: 'QdrantMemoryStore'")]Kernel kernel)
        {
            this.kernel = kernel;
        }
    }

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. 
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
8.2.0 143 10/22/2024
8.2.0-preview-01-m01 137 9/17/2024
8.1.9-preview-03 61 11/19/2024
8.1.9-preview-02 64 10/22/2024
8.1.9-preview-01 187 10/4/2024
8.1.8 146 9/23/2024
8.1.8-preview-07 253 9/12/2024
8.1.8-preview-06 142 9/11/2024
8.1.8-preview-05 89 9/10/2024
8.1.8-preview-04 217 8/16/2024
8.1.8-preview-03 129 8/13/2024
8.1.8-preview-02 101 8/13/2024
8.1.8-preview-01 100 8/12/2024
8.1.7 109 8/7/2024
8.1.7-preview-09 125 7/3/2024
8.1.7-preview-08 83 7/2/2024
8.1.7-preview-07 89 6/10/2024
8.1.7-preview-06 82 6/10/2024
8.1.7-preview-05 101 6/6/2024
8.1.7-preview-04 83 6/6/2024
8.1.7-preview-03 93 5/24/2024
8.1.7-preview-02 86 5/10/2024
8.1.7-preview-01 115 5/8/2024
8.1.6 1,269 5/7/2024
8.1.6-preview-08 61 5/2/2024
8.1.6-preview-07 94 4/29/2024
8.1.6-preview-06 263 4/26/2024
8.1.6-preview-05 94 4/24/2024
8.1.6-preview-04 107 4/22/2024
8.1.6-preview-03 91 4/22/2024
8.1.6-preview-02 123 4/17/2024
8.1.6-preview-01 185 4/15/2024
8.1.5 114 4/15/2024
8.1.5-preview-15 97 4/10/2024
8.1.5-preview-14 125 3/20/2024
8.1.5-preview-13 90 3/18/2024
8.1.5-preview-12 101 3/13/2024
8.1.5-preview-11 91 3/13/2024
8.1.5-preview-10 128 3/13/2024
8.1.5-preview-09 82 3/12/2024
8.1.5-preview-08 85 3/12/2024
8.1.5-preview-07 100 3/8/2024
8.1.5-preview-06 200 3/8/2024
8.1.5-preview-05 91 3/7/2024
8.1.5-preview-04 96 3/7/2024
8.1.5-preview-03 95 3/7/2024
8.1.5-preview-02 140 2/28/2024
8.1.5-preview-01 132 2/19/2024
8.1.4 216 2/15/2024
8.1.3 125 2/13/2024
8.1.3-preview-07 88 2/13/2024
8.1.3-preview-06 103 2/12/2024
8.1.3-preview-05 99 2/9/2024
8.1.3-preview-04 103 2/8/2024
8.1.3-preview-03 97 2/7/2024
8.1.3-preview-02 98 2/2/2024
8.1.3-preview-01 95 2/2/2024
8.1.2 157 2/1/2024
8.1.2-preview-9 101 1/22/2024
8.1.2-preview-8 94 1/19/2024
8.1.2-preview-7 93 1/19/2024
8.1.2-preview-6 87 1/19/2024
8.1.2-preview-5 92 1/19/2024
8.1.2-preview-4 89 1/19/2024
8.1.2-preview-3 85 1/18/2024
8.1.2-preview-2 90 1/18/2024
8.1.2-preview-16 96 1/31/2024
8.1.2-preview-15 96 1/31/2024
8.1.2-preview-14 205 1/25/2024
8.1.2-preview-13 91 1/25/2024
8.1.2-preview-12 101 1/23/2024
8.1.2-preview-11 97 1/23/2024
8.1.2-preview-10 79 1/22/2024
8.1.2-preview-1 81 1/18/2024
8.1.1 133 1/18/2024
8.1.0 108 1/18/2024
8.0.3 156 12/29/2023
8.0.1 153 12/14/2023
8.0.0 156 12/7/2023
6.0.4.3 167 12/29/2023
6.0.4.2 149 12/20/2023
6.0.4.1 193 12/19/2023
6.0.4 166 12/4/2023
6.0.3.20 138 11/27/2023
6.0.3.19 145 11/22/2023