This sample shows how to apply vanilla / simple RAG pattern using .NET fundamentals in the AI ecosystem such as:
- Microsoft.ML.Tokenizers
- System.Numerics.Tensors
- Microsoft.Extensions.AI
- Microsoft.Extensions.VectorData.Abstractions
- ML.NET
- ONNX Runtime
Given a list of movies, this sample implements semantic search, a building block for RAG patterns.
The project structure is as follows:
- Domain.cs - Contains the data models used by ML.NET and the vector store
- MLNETONNXEmbeddingGenerator - Implementation of
IEmbeddingGenerator
Microsoft.Extensions.AI interface. The implementation creates an ML.NET pipeline which uses the BertTokenizer from Microsoft.ML.Tokenizers and an the e5-small-v2 ONNX embedding model to generate embeddings. - Program.cs - Uses an
InMemoryVectorStore
Semantic Kernel to store and query movie data containg embeddings generated by theMLNETONNXEmbeddingGenerator
.
- .NET 9 SDK
- Visual Studio or Visual Studio Code
-
Open in GitHub Codespaces
-
Download the e5-small-v2 model and save it to the assets directory. If you rename the file, make sure to update the model path used by the
generator
in Program.cs.
- Download the e5-small-v2 model and save it to the assets directory. If you rename the file, make sure to update the model path used by the
generator
in Program.cs.
- Open the terminal and run the following command.
dotnet run