Closed mallo2 closed 4 months ago
@mallo2 I think your are trying to use this memory plugin as a NL2SQL feature.
This plugin (and kernel memory itself) is about using SQL server as vector database for R.A.G (Retrieval Augmented Generation). Take a look at https://learn.microsoft.com/en-us/azure/azure-sql/database/ai-artificial-intelligence-intelligent-applications?view=azuresql for more information about how use SQL server database for an intelligent application.
Take also a look at https://github.com/microsoft/kernel-memory for more information about using kernel memory to save records and ask them through natural language.
Thank you for the reply. I understood this code is the memory as the vector database. I need to link it with a kernel to browse my database.
I'm having this code now but I'm holding the same issue, I will need to understand why.
using KernelMemory.MemoryStorage.SqlServer;
using Microsoft.KernelMemory;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
var memory = new KernelMemoryBuilder()
.WithAzureOpenAITextGeneration(new AzureOpenAIConfig
{
Endpoint = "ENDPOINT",
Deployment = "gpt-4-32k",
APIKey = "API_KEY"
})
.WithAzureOpenAITextEmbeddingGeneration(new AzureOpenAIConfig
{
Endpoint ="ENDPOINT,
Deployment = "model-embedding",
APIKey = "API_KEY"
})
.WithSqlServerMemoryDb("CONNECTION STRING")
.Build<MemoryServerless>();
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion("gpt-4-32k", "ENDPOINT", "API_KEY")
.Build();
var promptOptions = new OpenAIPromptExecutionSettings { ChatSystemPrompt = "Answer or say \"I don't know\".", MaxTokens = 300, Temperature = 0, TopP = 0 };
var skPrompt = """
Question: {{$input}}
Tool call result: {{memory.ask $input}}
If the answer is empty say "I don't know", otherwise reply with a preview of the answer, truncated to 15 words.
""";
var myFunction = kernel.CreateFunctionFromPrompt(skPrompt, promptOptions);
kernel.ImportPluginFromObject(new MemoryPlugin(memory, waitForIngestionToComplete: true), "memory");
var question = "Combien ai-je de client ?";
Console.WriteLine("---------");
Console.WriteLine(question);
var answer = await myFunction.InvokeAsync(kernel, question);
Console.WriteLine("Answer: " + answer);
Thank you for the reply. I understood this code is the memory as the vector database. I need to link it with a kernel to browse my database.
I'm having this code now but I'm holding the same issue, I will need to understand why.
using KernelMemory.MemoryStorage.SqlServer; using Microsoft.KernelMemory; using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Connectors.OpenAI; var memory = new KernelMemoryBuilder() .WithAzureOpenAITextGeneration(new AzureOpenAIConfig { Endpoint = "ENDPOINT", Deployment = "gpt-4-32k", APIKey = "API_KEY" }) .WithAzureOpenAITextEmbeddingGeneration(new AzureOpenAIConfig { Endpoint ="ENDPOINT, Deployment = "model-embedding", APIKey = "API_KEY" }) .WithSqlServerMemoryDb("CONNECTION STRING") .Build<MemoryServerless>(); var kernel = Kernel.CreateBuilder() .AddAzureOpenAIChatCompletion("gpt-4-32k", "ENDPOINT", "API_KEY") .Build(); var promptOptions = new OpenAIPromptExecutionSettings { ChatSystemPrompt = "Answer or say \"I don't know\".", MaxTokens = 300, Temperature = 0, TopP = 0 }; var skPrompt = """ Question: {{$input}} Tool call result: {{memory.ask $input}} If the answer is empty say "I don't know", otherwise reply with a preview of the answer, truncated to 15 words. """; var myFunction = kernel.CreateFunctionFromPrompt(skPrompt, promptOptions); kernel.ImportPluginFromObject(new MemoryPlugin(memory, waitForIngestionToComplete: true), "memory"); var question = "Combien ai-je de client ?"; Console.WriteLine("---------"); Console.WriteLine(question); var answer = await myFunction.InvokeAsync(kernel, question); Console.WriteLine("Answer: " + answer);
@mallo2, can you share with me the code you are using to save your records? are you sure to have a record explaining how much clients you have?
Hi @mallo2 do you have any update to share?
May I close this issue ?
Hey, I'm sorry but I have nothing to add to solve this issue
`using KernelMemory.MemoryStorage.SqlServer; using Microsoft.KernelMemory;
var memory = new KernelMemoryBuilder() .WithAzureOpenAITextGeneration(new AzureOpenAIConfig { Endpoint = "ENDPOINT", Deployment = "gpt-4-32k", APIKey = "API_KEY" }) .WithAzureOpenAITextEmbeddingGeneration(new AzureOpenAIConfig { Endpoint = "ENDPOINT", Deployment = "model-embedding", APIKey = "API_KEY" }) .WithSqlServerMemoryDb("CONNECTION_STRING") .Build();
var answer1 = await memory.AskAsync("Combien ai-je de clients ?");`
With the above code, I get this result below in the console that I don't understand:
info: Microsoft.KernelMemory.Handlers.TextExtractionHandler[0] Handler 'extract' ready info: Microsoft.KernelMemory.Handlers.TextPartitioningHandler[0] Handler 'partition' ready info: Microsoft.KernelMemory.Handlers.SummarizationHandler[0] Handler 'summarize' ready info: Microsoft.KernelMemory.Handlers.GenerateEmbeddingsHandler[0] Handler 'gen_embeddings' ready, 1 embedding generators info: Microsoft.KernelMemory.Handlers.SaveRecordsHandler[0] Handler save_records ready, 1 vector storages info: Microsoft.KernelMemory.Handlers.DeleteDocumentHandler[0] Handler 'private_delete_document' ready info: Microsoft.KernelMemory.Handlers.DeleteIndexHandler[0] Handler 'private_delete_index' ready info: Microsoft.KernelMemory.Handlers.DeleteGeneratedFilesHandler[0] Handler 'delete_generated_files' ready warn: Microsoft.KernelMemory.Search.SearchClient[0] No memories available
Can you help me to solve that ?