kernel-memory icon indicating copy to clipboard operation
kernel-memory copied to clipboard

[Question] Using semantic kernel plug-in with parameters?

Open FreBon opened this issue 5 months ago • 5 comments

Context / Scenario

Hi,

I'm using Semantic Kernel with Azure Open AI services to build a chat solution. This works great, but now I want to add Memory to handle when users paste URLS in the prompts, I'm extracting the URLs and I add them to the KernelMemory. I'm using it in serverless mode so i use the MemoryServerless instance that i get from the KernelMemoryBuilder to import the URLs.

This is how the memory builder looks:

        var kernelMemory = new KernelMemoryBuilder()
            .WithAzureOpenAITextGeneration(chatConfig)
            .WithAzureOpenAITextEmbeddingGeneration(embeddingConfig)
            .WithAzureAISearchMemoryDb(memorySettings.AzureAiSearchUri, memorySettings.AzureAiSearchKey)
            .WithSearchClientConfig(new SearchClientConfig {MaxAskPromptSize = aiSettings.MaxTokenLength, AnswerTokens = 4096})
            .Build<MemoryServerless>();

I also add the momory plug-in:

    var memoryPlugin = new MemoryPlugin(kernelMemory);
    kernel.ImportPluginFromObject(memoryPlugin, "memory");

When the user sends a prompt I'm using the Memory Plugin with a prompt template that looks like this:

 var prompt = $@"
        User Question: {question}

        Kernel Memory Answer: {{memory.ask}}

        Respond in a well formatted Markdown syntax";

Question

  1. Without any filters and specified index, it seems like the prompt is not asking the memory, How do I know if the memory is used? Any logging?
  2. I want to add tags to the pages I add to have them filtered by conversation, I got this to work using the MemoryServerless instance, but how do I pass the filter to the plug-in?
  3. What is the recommended way to use Kernel Memory with Semantic kernel? Got the solution to work by using MemoryServerless.AskAsync but there is no streaming version so the user experience is not the best ..

Greatfull for any guidence :)

FreBon avatar Jan 23 '24 13:01 FreBon