Skip to content

Commit 8fe03f9

Browse files
authored
Memory Plugin for .NET and new nuget packages (#146)
## Motivation and Context (Why the change? What's the scenario?) Major milestone: Plugin for Semantic Kernel, show how to leverage Kernel Memory as a Plugin. ## High level description (Approach, Design) * Reorganized code, examples, nugets * New nugets: * Microsoft.KernelMemory.WebClient * Microsoft.KernelMemory.SemanticKernelPlugin * Microsoft.KernelMemory.Abstractions * Deprecated nuget Microsoft.KernelMemory.Client (renamed) * Example showing how to use the memory plugin * Upgraded some dependencies
1 parent a26407b commit 8fe03f9

File tree

316 files changed

+1151
-304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

316 files changed

+1151
-304
lines changed

KernelMemory.sln

Lines changed: 151 additions & 66 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![License: MIT](https://img.shields.io/github/license/microsoft/kernel-memory)](https://github.com/microsoft/kernel-memory/blob/main/LICENSE)
44
[![Discord](https://img.shields.io/discord/1063152441819942922?label=Discord&logo=discord&logoColor=white&color=d82679)](https://aka.ms/SKDiscord)
55

6-
**Kernel Memory** (KM) is an open-source [service](dotnet/Service/README.md) and
6+
**Kernel Memory** (KM) is an open-source [service](service/Service/README.md) and
77
[plugin](https://www.microsoft.com/en-us/microsoft-365/blog/2023/05/23/empowering-every-developer-with-plugins-for-microsoft-365-copilot/)
88
specialized in the efficient indexing of datasets through custom continuous data
99
hybrid pipelines. For some scenarios KM is also available as a library, and soon
@@ -22,19 +22,40 @@ Designed for seamless integration as a Plugin with
2222
Copilot and ChatGPT, Kernel Memory enhances data-driven features in applications
2323
built for most popular AI platforms.
2424

25-
### Packages
2625

27-
Multiple variants are available on NuGet:
26+
### Packages for Python, Java and other languages
2827

29-
* **Microsoft.KernelMemory.Core:** The core library, can be used to build custom pipelines and handlers
28+
A python package with a Web Client and Semantic Kernel plugin will soon be available.
29+
We also welcome PR contributions to support more languages.
30+
31+
In the meantime you can easily connect to Kernel Memory web service following the
32+
existing **OpenAPI** swagger at http://127.0.0.1:9001/swagger/index.html.
33+
34+
### .NET packages
35+
36+
* **Microsoft.KernelMemory.WebClient:** The web client library, can be used to call
37+
a running instance of the Memory web service. .NET Standard 2.0 compatible.
38+
39+
[![Nuget package](https://img.shields.io/nuget/vpre/Microsoft.KernelMemory.WebClient)](https://www.nuget.org/packages/Microsoft.KernelMemory.WebClient/)
40+
[![Example code](https://img.shields.io/badge/example-code-blue)](examples/002-dotnet-WebClient)
41+
42+
* **Microsoft.KernelMemory.SemanticKernelPlugin:** a Memory plugin for Semantic Kernel,
43+
replacing the original Semantic Memory available in SK. .NET Standard 2.0 compatible.
44+
45+
[![Nuget package](https://img.shields.io/nuget/vpre/Microsoft.KernelMemory.SemanticKernelPlugin)](https://www.nuget.org/packages/Microsoft.KernelMemory.SemanticKernelPlugin/)
46+
[![Example code](https://img.shields.io/badge/example-code-blue)](examples/011-dotnet-using-MemoryPlugin)
47+
48+
* **Microsoft.KernelMemory.Core:** The core library, can be used to build custom
49+
pipelines and handlers, and contains a serverless client to use memory in a
50+
synchronous way, without the web service. .NET 6+.
3051

3152
[![Nuget package](https://img.shields.io/nuget/vpre/Microsoft.KernelMemory.Core)](https://www.nuget.org/packages/Microsoft.KernelMemory.Core/)
3253
[![Example code](https://img.shields.io/badge/example-code-blue)](examples/001-dotnet-Serverless)
3354

34-
* **Microsoft.KernelMemory.Client:** The client library, can be used to call an already running instance of the service
55+
* **Microsoft.KernelMemory.Abstractions:** The internal interfaces and models
56+
shared by all packages. .NET Standard 2.0 compatible.
3557

36-
[![Nuget package](https://img.shields.io/nuget/vpre/Microsoft.KernelMemory.Client)](https://www.nuget.org/packages/Microsoft.KernelMemory.Client/)
37-
[![Example code](https://img.shields.io/badge/example-code-blue)](examples/002-dotnet-WebClient)
58+
[![Nuget package](https://img.shields.io/nuget/vpre/Microsoft.KernelMemory.Abstractions)](https://www.nuget.org/packages/Microsoft.KernelMemory.Abstractions/)
3859

3960
### Supported data formats
4061

@@ -52,15 +73,18 @@ Multiple variants are available on NuGet:
5273
### Supported backends
5374

5475
* ↗️ Vector storage
55-
* Azure Cognitive Search
76+
* Azure AI Search
5677
* Qdrant
78+
* In memory KNN vectors (volatile)
5779
* 📀 Content storage
5880
* Azure Blobs
5981
* Local file system
82+
* In memory, volatile content
6083
* ⏳ Asynchronous ingestion queues
6184
* Azure Queues
6285
* RabbitMQ
6386
* Local file based queue
87+
* In memory queues (volatile)
6488

6589
> ℹ️ **NOTE**: the documentation below is work in progress, will evolve quickly
6690
> as is not fully functional yet.
@@ -176,8 +200,8 @@ default handlers or your custom Python/TypeScript/Java/etc. handlers,
176200
and leveraging the asynchronous non-blocking memory encoding process,
177201
sending documents and asking questions using the **MemoryWebClient**.
178202

179-
[Here](dotnet/Service/README.md) you can find a complete set of instruction
180-
about [how to run the Kernel Memory service](dotnet/Service/README.md).
203+
[Here](service/Service/README.md) you can find a complete set of instruction
204+
about [how to run the Kernel Memory service](service/Service/README.md).
181205

182206
If you want to give the service a quick test, use the following command
183207
to **start the Kernel Memory Service**:
@@ -286,16 +310,22 @@ running the service locally with OpenAPI enabled.
286310
287311
## Examples
288312
289-
1. [Collection of Jupyter notebooks with various tests](examples/000-notebooks)
290-
2. [Importing files and asking question without running the service (serverless mode)](examples/001-dotnet-Serverless)
291-
3. [Using the Kernel Memory web service](examples/002-dotnet-WebClient)
292-
4. [How to upload files from command line with curl](examples/003-curl-calling-webservice)
313+
1. [Collection of Jupyter notebooks with various scenarios](examples/000-notebooks)
314+
2. [Using Kernel Memory web service to upload documents and answer questions](examples/001-dotnet-WebClient)
315+
3. [Using KM Plugin for Semantic Kernel](examples/002-dotnet-SemanticKernelPlugin)
316+
4. [Importing files and asking question without running the service (serverless mode)](examples/003-dotnet-Serverless)
293317
5. [Processing files with custom steps](examples/004-dotnet-ServerlessCustomPipeline)
294-
6. [Using a custom pipeline handler with serverless memory class](examples/005-dotnet-InProcessMemoryWithCustomHandler)
295-
7. [Writing a custom async pipeline handler](examples/006-dotnet-CustomHandlerAsAService)
296-
8. [Integrating Memory with ASP.NET applications and controllers](examples/007-aspnet-mvc-integration)
297-
9. [Partioning/Chunking documents with custom settings](examples/008-dotnet-custom-partitioning-options)
298-
10. [Using Llama and other custom LLMs](009-dotnet-custom-LLM)
318+
6. [Upload files and ask questions from command line using curl](examples/005-curl-calling-webservice)
319+
7. [Customizing RAG and summarization prompts](examples/101-dotnet-custom-Prompts)
320+
8. [Custom partitioning/text chunking options](examples/102-dotnet-custom-partitioning-options)
321+
9. [Using a custom embedding/vector generator](examples/103-dotnet-custom-EmbeddingGenerator)
322+
10. [Using Llama and other custom LLMs](examples/104-dotnet-custom-LLM)
323+
11. [Natural language to SQL examples](examples/200-dotnet-nl2sql)
324+
12. [Writing and using a custom ingestion handler](examples/201-dotnet-InProcessMemoryWithCustomHandler)
325+
13. [Running a single asynchronous pipeline handler as a standalone service](examples/202-dotnet-CustomHandlerAsAService)
326+
14. [Test project linked to KM package from nuget.org](examples/203-dotnet-using-core-nuget)
327+
15. [Integrating Memory with ASP.NET applications and controllers](examples/204-dotnet-ASP.NET-MVC-integration)
328+
16. [Sample code showing how to extract text from files](examples/205-dotnet-extract-text-from-docs)
299329
300330
## Tools
301331
@@ -304,4 +334,5 @@ running the service locally with OpenAPI enabled.
304334
3. [Curl script to search documents](tools/search.sh)
305335
4. [Script to start Qdrant for development tasks](tools/run-qdrant.sh)
306336
5. [Script to start RabbitMQ for development tasks](tools/run-rabbitmq.sh)
337+
6. [.NET appsettings.json generator](tools/InteractiveSetup)
307338
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
using System.Globalization;
7+
using System.Text.Json;
8+
9+
namespace Microsoft.KernelMemory.SemanticKernelPlugin.Internals;
10+
11+
[TypeConverter(typeof(TypeConverter))]
12+
public class TagCollectionWrapper : TagCollection
13+
{
14+
}
15+
16+
[TypeConverter(typeof(TypeConverter))]
17+
public class ListOfStringsWrapper : List<string>
18+
{
19+
}
20+
21+
#pragma warning disable CA1812 // required by SK
22+
internal sealed class TypeConverter : System.ComponentModel.TypeConverter
23+
{
24+
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) => true;
25+
26+
/// <summary>
27+
/// This method is used to convert object from string to actual type. This will allow to pass object to
28+
/// native function which requires it.
29+
/// </summary>
30+
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
31+
{
32+
return JsonSerializer.Deserialize<TagCollectionWrapper>((string)value);
33+
}
34+
35+
/// <summary>
36+
/// This method is used to convert actual type to string representation, so it can be passed to AI
37+
/// for further processing.
38+
/// </summary>
39+
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
40+
{
41+
return JsonSerializer.Serialize(value);
42+
}
43+
}
44+
#pragma warning restore CA1812

0 commit comments

Comments
 (0)