Encamina.Enmarcha.SemanticKernel.Connectors.Memory 8.1.6

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Encamina.Enmarcha.SemanticKernel.Connectors.Memory --version 8.1.6
NuGet\Install-Package Encamina.Enmarcha.SemanticKernel.Connectors.Memory -Version 8.1.6
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.1.6" />
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.1.6
#r "nuget: Encamina.Enmarcha.SemanticKernel.Connectors.Memory, 8.1.6"
#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.1.6

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

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.1.7-preview-02 62 5/10/2024
8.1.7-preview-01 81 5/8/2024
8.1.6 136 5/7/2024
8.1.6-preview-08 37 5/2/2024
8.1.6-preview-07 66 4/29/2024
8.1.6-preview-06 96 4/26/2024
8.1.6-preview-05 70 4/24/2024
8.1.6-preview-04 75 4/22/2024
8.1.6-preview-03 63 4/22/2024
8.1.6-preview-02 98 4/17/2024
8.1.6-preview-01 159 4/15/2024
8.1.5 84 4/15/2024
8.1.5-preview-15 76 4/10/2024
8.1.5-preview-14 85 3/20/2024
8.1.5-preview-13 54 3/18/2024
8.1.5-preview-12 62 3/13/2024
8.1.5-preview-11 57 3/13/2024
8.1.5-preview-10 79 3/13/2024
8.1.5-preview-09 44 3/12/2024
8.1.5-preview-08 45 3/12/2024
8.1.5-preview-07 58 3/8/2024
8.1.5-preview-06 163 3/8/2024
8.1.5-preview-05 54 3/7/2024
8.1.5-preview-04 56 3/7/2024
8.1.5-preview-03 56 3/7/2024
8.1.5-preview-02 104 2/28/2024
8.1.5-preview-01 115 2/19/2024
8.1.4 184 2/15/2024
8.1.3 96 2/13/2024
8.1.3-preview-07 57 2/13/2024
8.1.3-preview-06 71 2/12/2024
8.1.3-preview-05 62 2/9/2024
8.1.3-preview-04 71 2/8/2024
8.1.3-preview-03 59 2/7/2024
8.1.3-preview-02 58 2/2/2024
8.1.3-preview-01 54 2/2/2024
8.1.2 128 2/1/2024
8.1.2-preview-9 79 1/22/2024
8.1.2-preview-8 65 1/19/2024
8.1.2-preview-7 62 1/19/2024
8.1.2-preview-6 57 1/19/2024
8.1.2-preview-5 62 1/19/2024
8.1.2-preview-4 65 1/19/2024
8.1.2-preview-3 62 1/18/2024
8.1.2-preview-2 64 1/18/2024
8.1.2-preview-16 56 1/31/2024
8.1.2-preview-15 57 1/31/2024
8.1.2-preview-14 164 1/25/2024
8.1.2-preview-13 58 1/25/2024
8.1.2-preview-12 60 1/23/2024
8.1.2-preview-11 56 1/23/2024
8.1.2-preview-10 57 1/22/2024
8.1.2-preview-1 58 1/18/2024
8.1.1 100 1/18/2024
8.1.0 76 1/18/2024
8.0.3 129 12/29/2023
8.0.1 125 12/14/2023
8.0.0 123 12/7/2023
6.0.4.3 134 12/29/2023
6.0.4.2 118 12/20/2023
6.0.4.1 169 12/19/2023
6.0.4 141 12/4/2023
6.0.3.20 116 11/27/2023
6.0.3.19 114 11/22/2023