DEV Community

Aftab Bashir
Aftab Bashir

Posted on

BlazorMemory v0.8.0: Semantic Kernel adapter, Ollama embeddings, and memory decay

Four things shipped in v0.8.0. I will go through each one.

Semantic Kernel integration

The most requested feature since I published the library. BlazorMemory now implements SK's IMemoryStore interface directly.

dotnet add package BlazorMemory.SemanticKernel
Enter fullscreen mode Exit fullscreen mode
builder.Services
    .AddBlazorMemory()
    .UseInMemoryStorage()
    .UseOpenAiEmbeddings(apiKey)
    .UseOpenAiExtractor(apiKey)
    .UseSemanticKernelMemoryStore(userId: "alice");
Enter fullscreen mode Exit fullscreen mode

That registers BlazorMemoryMemoryStore as SK's IMemoryStore in DI. You can now pass it to SK's SemanticTextMemory or any SK plugin that takes an IMemoryStore.

One design decision worth explaining: SK has no concept of userId, but BlazorMemory requires one for every store operation. The adapter takes a userId parameter (defaults to "sk") and uses it for all operations. If you are building a multi-user app, create one adapter per user or pass the userId at registration time.

SK collections map to BlazorMemory namespaces. So CreateCollectionAsync("work") creates a namespace called "work" and all records in that collection are scoped to it.

Ollama embeddings

dotnet add package BlazorMemory.Embeddings.Ollama
Enter fullscreen mode Exit fullscreen mode
builder.Services
    .AddBlazorMemory()
    .UseOllamaEmbeddings()
    .UseOpenAiExtractor(apiKey);
Enter fullscreen mode Exit fullscreen mode

No API key. No cost per request. Runs against a local Ollama instance at http://localhost:11434. Default model is nomic-embed-text which produces 768-dimensional embeddings.

You can configure it:

builder.UseOllamaEmbeddings(options =>
{
    options.Model = "mxbai-embed-large";
    options.BaseUrl = "http://my-server:11434";
    options.Dimensions = 1024;
});
Enter fullscreen mode Exit fullscreen mode

The package has zero external dependencies. It uses System.Net.Http.Json directly. No Ollama SDK to pull in.

The obvious use case is development. Run Ollama locally, pull a model, and test your AI assistant without spending money on embeddings. Switch to OpenAI embeddings in production by changing one line.

Memory decay and summarization

This solves a real problem. A user who chats with your assistant every day for a month can accumulate hundreds of memories. Most of them are redundant or stale. The memory panel becomes noise.

SummarizeOldMemoriesAsync collapses old memories into a summary entry:

await memory.SummarizeOldMemoriesAsync(
    userId,
    maxMemories: 50,
    keepRecent: 20);
Enter fullscreen mode Exit fullscreen mode

If the user has fewer than 50 memories, nothing happens. If they have more, the oldest ones (count minus 20) get passed to the LLM extractor for summarization, then deleted. A new memory is stored with the summary, prefixed with [Summary].

The summary prompt is: "Summarize these facts about a user into a single concise paragraph. Start with 'User background:'. Facts: ..."

You can call this on a schedule or after each conversation. It is a no-op when memory count is below the threshold so calling it frequently is safe.

Verbatim mode importance scoring

Thumbs up and down now work in verbatim mode too. Previously they only showed in Smart mode. The MemoryPanel component dispatches to the right service method based on the current mode automatically.

await memory.MarkVerbatimImportantAsync(memoryId);
await memory.MarkVerbatimUnimportantAsync(memoryId);
await memory.ResetVerbatimImportanceAsync(memoryId);
Enter fullscreen mode Exit fullscreen mode

Same scoring logic as Smart mode. Important memories get a 1.5x multiplier on relevance. Unimportant ones drop to 0.3x.

Current state

11 packages on NuGet, 108 tests passing.

dotnet add package BlazorMemory
dotnet add package BlazorMemory.SemanticKernel
dotnet add package BlazorMemory.Embeddings.Ollama
dotnet add package BlazorMemory.Components
Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/aftabkh4n/BlazorMemory

Top comments (0)