microsoft / kernel-memory

RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
https://microsoft.github.io/kernel-memory
MIT License
1.52k stars 291 forks source link

[Question] How to use a kernel memory plugin with other plugins? #421

Closed rborosak closed 3 months ago

rborosak commented 5 months ago

Context / Scenario

Hi, I was able to implement a memory kernel plugin. The idea is to have a chatbot that answers only to questions from internal documents. If the user ask something that is not related to our documents the bot replies "I don't know".

I have registered the memory plugin and my prompt looks something like this. My project is based on this blog entry https://www.developerscantina.com/p/semantic-kernel-memory/

var prompt = $@" Question to Kernel Memory: {question}

Kernel Memory Answer: {{memory.ask}}

If the answer is empty say 'I don't know', otherwise reply with the answer. ";

This works as expected.

Now I would like to add a new plugin so the users can book an appointment. I have registered this new plugin but when the user asks something like "How can I make an appointment" or "I would like to make an appointment" the answer is "I don't know" because it was not found in memory.

Question

How should I change my prompt so that the bot can answer ONLY questions based on our internal documents and still use another plugin (and check if all the input arguments are provided by the user like time, date, place for the appointment)?

Can this be done in a single project or do I need to have two chatbot?

luismanez commented 4 months ago

If I'm understanding correctly, I think you need to use a SemanticKernel planner. In a planner, you register your 2 plugins: the appointment plugin, but also your semantic plugin (the prompt you posted that is calling the Memory plugin). When the user does the request, the SK planner infers the user intent, and runs the best suited plugin found.

I did some SK samples here for a community event: https://github.com/luismanez/gab-bcn-2024/blob/main/src/CozyKitchen/HostedServices/Demo04/PlannerHostedService.cs

Hope it helps.