Chroma Memory implementation in Asp.net Razor Pages #7064
-
I'm trying to develop a razor page which has Chroma embedded memory me based on this link Chroma is running and I can search for a question. Logs of my questions:
From my base class: protected string GetMemoryCollectionName()
{
return _MemoryCollectionName;
}
protected async Task<ISemanticTextMemory> GetMemoryAsync()
{
var memoryBuilder = new MemoryBuilder();
memoryBuilder.WithAzureOpenAITextEmbeddingGeneration(
deploymentName: "text-embedding-ada-002",
endpoint: _azureOpenAIConfig.EndPoint,
apiKey: _azureOpenAIConfig.ApiKey,
"azureml://registries/azure-openai/models/text-embedding-ada-002/versions/2");
var chromaMemoryStore = new ChromaMemoryStore("http://127.0.0.1:8000");
memoryBuilder.WithMemoryStore(chromaMemoryStore);
var memory = memoryBuilder.Build();
await memory.SaveInformationAsync(_MemoryCollectionName, id: "info1", text: "My name is Andrea");
await memory.SaveInformationAsync(_MemoryCollectionName, id: "info2", text: "I currently work as a tourist operator");
await memory.SaveInformationAsync(_MemoryCollectionName, id: "info3", text: "I currently live in Seattle and have been living there since 2005");
await memory.SaveInformationAsync(_MemoryCollectionName, id: "info4", text: "I visited France and Italy five times since 2015");
await memory.SaveInformationAsync(_MemoryCollectionName, id: "info5", text: "My family is from New York");
return memory;
} The issue beging after integration of memory with PromptFunction: var memory = await GetMemoryAsync();
var questions = new[]
{
"what is my name?",
"where do I live?",
"where is my family from?",
"where have I travelled?",
"what do I do for work?",
};
foreach (var q in questions)
{
var responseX = await memory.SearchAsync(GetMemoryCollectionName(), q, limit: 1, minRelevanceScore: 0.5).FirstOrDefaultAsync();
Console.WriteLine(q + " " + responseX?.Metadata.Text);
}
// TextMemoryPlugin provides the "recall" function
_kernel.ImportPluginFromObject(new TextMemoryPlugin(memory));
const string skPrompt = @"
ChatBot can have a conversation with you about any topic.
It can give explicit instructions or say 'I don't know' if it does not have an answer.
Information about me, from previous conversations:
- {{$fact1}} {{recall $fact1}}
- {{$fact2}} {{recall $fact2}}
- {{$fact3}} {{recall $fact3}}
- {{$fact4}} {{recall $fact4}}
- {{$fact5}} {{recall $fact5}}
Chat:
{{$history}}
User: {{$userInput}}
ChatBot: ";
var chatFunction = _kernel.CreateFunctionFromPrompt(skPrompt, executionSettings);
var arguments = new KernelArguments();
arguments["fact1"] = "what is my name?";
arguments["fact2"] = "where do I live?";
arguments["fact3"] = "where is my family from?";
arguments["fact4"] = "where have I travelled?";
arguments["fact5"] = "what do I do for work?";
arguments[TextMemoryPlugin.CollectionParam] = GetMemoryCollectionName();
arguments[TextMemoryPlugin.LimitParam] = "2";
arguments[TextMemoryPlugin.RelevanceParam] = "0.8";
var history = "";
foreach (var item in aiHistory)
{
switch (item.Role.Label.ToLower())
{
case "assistant":
history += "ChatBot: " + item.Items.Last() + "\n";
break;
case "user":
history += "User: " + item.Items.Last() + "\n";
break;
default:
break;
}
}
arguments["history"] = history;
arguments["userInput"] = aiHistory.Last().Items.Last();
var response = await _kernel.InvokeAsync(chatFunction, arguments); When I ask the following question:
I received the following answer:
That means the LLM has no memory in initial state! I have no error and exception! Source code: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @imranshams ! const string MemoryCollectionName = "aboutMe";
await memory.SaveInformationAsync(MemoryCollectionName, id: "info1", text: "My name is Andrea");
await memory.SaveInformationAsync(MemoryCollectionName, id: "info2", text: "I currently work as a tourist operator");
await memory.SaveInformationAsync(MemoryCollectionName, id: "info3", text: "I currently live in Seattle and have been living there since 2005");
await memory.SaveInformationAsync(MemoryCollectionName, id: "info4", text: "I visited France and Italy five times since 2015");
await memory.SaveInformationAsync(MemoryCollectionName, id: "info5", text: "My family is from New York"); |
Beta Was this translation helpful? Give feedback.
From issue description, it looks like you see the results from DB when you try to search directly, but it's not working when executing a function with Kernel. In this line, could you try to decrease relevance score to
0.5
?