Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
K

kernel-memory

> AI 编程
Open source

Research project. A Memory solution for users, teams, and applications.

2.2K stars0 likes1 views
WebsiteGitHub

About

Research project. A Memory solution for users, teams, and applications.

[!CAUTION] This is an archived research project. The code serves as a learning resource, not production software. Use it with caution, and at your own risk. No support is provided.

Kernel Memory

This repository presents best practices and a reference implementation for Memory in specific AI and LLMs application scenarios. Please note that the code provided serves as a demonstration and is not an officially supported Microsoft offering.

Kernel Memory (KM) is a multi-modal AI Service specialized in the efficient indexing of datasets through custom continuous data hybrid pipelines, with support for Retrieval Augmented Generation (RAG), synthetic memory, prompt engineering, and custom semantic memory processing.

KM is available as a Web Service, as a Docker container, a Plugin for ChatGPT/Copilot/Semantic Kernel, and as a .NET library for embedded applications.

Utilizing advanced embeddings and LLMs, the system enables Natural Language querying for obtaining answers from the indexed data, complete with citations and links to the original sources.

Kernel Memory is designed for seamless integration as a Plugin with Semantic Kernel, Microsoft Copilot and ChatGPT.

Kernel Memory Service on Azure

Kernel Memory can be deployed in various configurations, including as a Service in Azure. To learn more about deploying Kernel Memory in Azure, please refer to the Azure deployment guide. For detailed instructions on deploying to Azure, you can check the infrastructure documentation.

If you are already familiar with these resources, you can quickly deploy by clicking the following button. See also: Kernel Memory via Docker and Serverless Kernel Memory with Azure services example.

Running Kernel Memory with Aspire

Kernel Memory can be easily run and imported in other projects also via .NET Aspire. For example:

csharp
var builder = DistributedApplication.CreateBuilder();

builder.AddContainer("kernel-memory", "kernelmemory/service")
    .WithEnvironment("KernelMemory__TextGeneratorType", "OpenAI")
    .WithEnvironment("KernelMemory__DataIngestion__EmbeddingGeneratorTypes__0", "OpenAI")
    .WithEnvironment("KernelMemory__Retrieval__EmbeddingGeneratorType", "OpenAI")
    .WithEnvironment("KernelMemory__Services__OpenAI__APIKey", "...your OpenAI key...");

builder.Build().Run();

Data Ingestion using Kernel Memory OpenAPI Web Service

The example show the default documents ingestion pipeline:

  1. Extract text: automatically recognize the file format and extract the information
  2. Partition the text in small chunks, ready for search and RAG prompts
  3. Extract embeddings using any LLM embedding generator
  4. Save embeddings into a vector index such as Azure AI Search, Qdrant or other DBs.

The example shows how to safeguard private information specifying who owns each document, and how to organize data for search and faceted navigation, using Tags.

C#

csharp
#r "nuget: Microsoft.KernelMemory.WebClient"

var memory = new MemoryWebClient("http://127.0.0.1:9001"); // <== URL of KM web service

// Import a file
await memory.ImportDocumentAsync("meeting-transcript.docx");

// Import a file specifying Document ID and Tags
await memory.ImportDocumentAsync("business-plan.docx",
    new Document("doc01")
        .AddTag("user", "[email protected]")
        .AddTag("collection", "business")
        .AddTag("collection", "plans")
        .AddTag("fiscalYear", "2025"));

Python

python
import requests

# Files to import
files = {
          "file1": ("business-plan.docx", open("business-plan.docx", "rb")),
        }

# Tags to apply, used by queries to filter memory
data = { "documentId": "doc01",
         "tags": [ "user:[email protected]",
                   "collection:business",
                   "collection:plans",
                   "fiscalYear:2025" ]
       }

response = requests.post("http://127.0.0.1:9001/upload", files=files, data=data)

Direct Data Ingestion using embedded Serverless .NET component

csharp
var memory = new KernelMemoryBuilder()
    .WithOpenAIDefaults(Environment.GetEnvironmentVariable("OPENAI_API_KEY"))
    .Build<MemoryServerless>();

// Import a file
await memory.ImportDocumentAsync("meeting-transcript.docx");

// Import a file specifying Document ID and Tags
await memory.ImportDocumentAsync("business-plan.docx",
    new Document("doc01")
        .AddTag("collection", "business")
        .AddTag("collection", "plans")
        .AddTag("fiscalYear", "2025"));

Memory retrieval and RAG

Asking questions, running RAG prompts, and filtering by user and other criteria is simple, with answers including citations and all the information needed to verify their accuracy, pointing to which documents ground the response.

C#

Asking questions:

Questions can be asked targeting the entire memory set, or a subset using filters, e.g. to implement security filters.

csharp
var answer1 = await memory.AskAsync("How many people attended the meeting?");

var answer2 = await memory.AskAsync("what's the project timeline?",
                                    filter: MemoryFilters.ByTag("user", "[email protected]"));

Token usage:

When generating answers with LLMs, the result includes a token usage report.

csharp
foreach (var report in tokenUsage)
{
    Console.WriteLine($"{report.ServiceType}: {report.ModelName} ({report.ModelType})");
    Console.WriteLine($"- Input : {report.ServiceTokensIn}");
    Console.WriteLine($"- Output: {report.ServiceTokensOut}");
}

Output:

Azure OpenAI: gpt-4o (TextGeneration)

  • Input : 24356 tokens
  • Output: 103 tokens

Data lineage, citations, referencing sources:

csharp
await memory.ImportFileAsync("NASA-news.pdf");

var answer = await memory.AskAsync("Any news from NASA about Orion?");

Console.WriteLine(answer.Result + "/n");

foreach (var x in answer.RelevantSources)
{
    Console.WriteLine($"  * {x.SourceName} -- {x.Partitions.First().LastUpdate:D}");
}

Yes, there is news from NASA about the Orion spacecraft. NASA has invited the media to see a new test version [......] For more information about the Artemis program, you can visit the NASA website.

  • NASA-news.pdf -- Tuesday, August 1, 2023

Python

Asking questions:

python
import requests
import json

data = {
    "question": "what's the project timeline?",
    "filters":  [ {"user": ["[email protected]"]} ]
}

response = requests.post(
    "http://127.0.0.1:9001/ask",
    headers={"Content-Type": "application/json"},
    data=json.dumps(data),
).json()

print(response["text"])

OpenAPI

bash
curl http://127.0.0.1:9001/ask -d'{"query":"Any news from NASA about Orion?"}' -H 'Content-Type: application/json'
…

The OpenAPI schema ("swagger") is available at http://127.0.0.1:9001/swagger/index.html when running the service locally with OpenAPI enabled. Here's a copy.

See also:

  • Full example with ingestion, search and RAG queries.
  • Full example using serverless .NET component.

Kernel Memory Docker image

If you want to give the service a quick test, use the following command to start the Kernel Memory Service using OpenAI:

bash
docker run -e OPENAI_API_KEY="..." -it --rm -p 9001:9001 kernelmemory/service

If you prefer using custom settings and services such as Azure OpenAI, Azure Document Intelligence, etc., you should create an appsettings.Development.json file overriding the default values set in appsettings.json, or using the configuration wizard included:

bash
cd service/Service
dotnet run setup

Then run this command to start the Docker image with the configuration just created:

on Windows:

bash
docker run --volume .\appsettings.Development.json:/app/appsettings.Production.json -it --rm -p 9001:9001 kernelmemory/service

on Linux / macOS:

bash
docker run --volume ./appsettings.Development.json:/app/appsettings.Production.json -it --rm -p 9001:9001 kernelmemory/service

See also:

  • How to configure KM service
  • Deploy Kernel Memory to Azure.

Memory as a Service: Data Ingestion Pipelines + RAG Web Service

Depending on your scenarios, you might want to run all the code remotely through an asynchronous and scalable service, or locally inside your process.

If you're importing small files, and use only .NET and can block the application process while importing documents, then local-in-process execution can be fine, using the MemoryServerless described below.

However, if you are in one of these scenarios:

  • My app is written in TypeScript, Java, Rust, or some other language
  • I'd just like a web service to import data and send questions to answer
  • I'm importing big documents that can require minutes to process, and I don't want to block the user interface
  • I need memory import to run independently, supporting failures and retry logic
  • I want to define custom pipelines mixing multiple languages like Python, TypeScript, etc

then you're likely looking for a Memory Service, and you can deploy Kernel Memory as a backend service, using the default ingestion logic, or your custom workflow including steps coded in Python/TypeScript/Java/etc., leveraging the asynchronous non-blocking memory encoding process, uploading documents and asking questions using the MemoryWebClient.

Here you can find a complete set of instruction about how to run the Kernel Memory service.

Embedded Memory Component (aka "serverless")

Kernel Memory works and scales at best when running as an asynchronous Web Service, allowing to ingest thousands of documents and information without blocking your app.

However, Kernel Memory can also run in serverless mode, embedding MemoryServerless class instance in .NET backend/console/desktop apps in synchronous mode. Each request is processed immediately, although calling clients are responsible for handling transient errors.

Extensions

Kernel Memory relies on external services to run stateful pipelines, store data, handle embeddings, and generate text responses. The project includes extensions that allow customization of file storage, queues, vector stores, and LLMs to fit specific requirements.

  • AI: Azure OpenAI, OpenAI, ONNX, Ollama, Anthropic, Azure AI Document Intelligence, Azure AI Content Safety
  • Vector Store: Azure AI Search, Postgres, SQL Server, Elasticsearch, Qdrant, Redis, MongoDB Atlas,

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#indexingllmmemoryrag

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryAI 编程
PricingOpen source

> Related tools

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.