microsoft / kernel-memory

RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.

Home Page:https://microsoft.github.io/kernel-memory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How to implement Short Term Memory

roldengarm opened this issue · comments

Context / Scenario

We are building a chat bot and would like to use Kernel Memory to allow users to ask questions. How can we implement a short term memory / chat context?
The docs list this as a feature (Short Term Memory (partially implemented/work in progress), but I can't find any documentation about how to use it.
Semantic Kernel has some documentation about it.

We're using the Kernel Memory Webclient from our chat bot.

Question

How can I add a context / short term memory when using the Kernel Memory Webclient package and the AskAsync method to ask questions?

Hi @roldengarm!

I have implemented a simple solution in my Kernel Memory Service repository: https://github.com/marcominerva/KernelMemoryService. In particular, take a look to the ChatService.cs file and how it is used.

@marcominerva thanks for the tip. So you're using Semantic Kernel to do that.
We're running the complete Kernel Memory service, so not sure where to inject/add that.

You just need to use it just before calling AskAsync or SearchAsync.

here's another take on long term and short term memory: https://github.com/microsoft/kernel-memory/tree/main/examples/302-dotnet-sk-km-chat

  • short term: the chat history acts as short term memory, so it's maintained only while the chat is active
  • long term: KM memory records provide long term information, which is injected in the initial system message. to avoid polluting the short term memory, the initial system message contains long term memory records relevant only to the last chat message