Welcome to the repository for the full local RAG scenario using Phi-3, SemanticKernel, and TextMemory. This project demonstrates the power of Phi-3, a groundbreaking Small Language Model (SLM) that is redefining AI capabilities for developers and businesses.
The demo scenario is designed to answer the question, "What is Bruno's favourite super hero?" using two different approaches:
- Directly asking the Phi-3 model.
- Adding a semantic memory object with fan facts loaded and then asking the question.
Phi-3 represents a significant leap in Small Language Models, offering a unique blend of performance and efficiency. It is capable of handling full scenarios independently, which simplifies the development process and reduces integration complexities.
The console application demonstrates the use of a local model hosted in Ollama and semantic memory for search. The program uses several external libraries for dependency injection, configuration, and semantic kernel and memory functionalities.
-
Open a terminal and navigate to the current project.
cd .\src\Sample03\
-
Run the project with the command
dotnet run
-
The project
Sample03
, answer the following question:var question = "What is Bruno's favourite super hero?"
-
First the question is asked directly to the Phi-3 Model. Then, the program load the following information in a Text Memory, and ask the question again.
// get the embeddings generator service var embeddingGenerator = kernel.Services.GetRequiredService<ITextEmbeddingGenerationService>(); var memory = new SemanticTextMemory(new VolatileMemoryStore(), embeddingGenerator); // add facts to the collection const string MemoryCollectionName = "fanFacts"; await memory.SaveInformationAsync(MemoryCollectionName, id: "info1", text: "Gisela's favourite super hero is Batman"); await memory.SaveInformationAsync(MemoryCollectionName, id: "info2", text: "The last super hero movie watched by Gisela was Guardians of the Galaxy Vol 3"); await memory.SaveInformationAsync(MemoryCollectionName, id: "info3", text: "Bruno's favourite super hero is Invincible"); await memory.SaveInformationAsync(MemoryCollectionName, id: "info4", text: "The last super hero movie watched by Bruno was Aquaman II"); await memory.SaveInformationAsync(MemoryCollectionName, id: "info5", text: "Bruno don't like the super hero movie: Eternals");
-
Once the text memory is ready, it's loaded into the kernel as a plugin.
TextMemoryPlugin memoryPlugin = new(memory); // Import the text memory plugin into the Kernel. kernel.ImportPluginFromObject(memoryPlugin);
-
Here is the demo console application running in a Codespace: