Local AI Assistant with MAUI, Semantic Kernel, Ollama & LiteDB
π€ Local AI Assistant with .NET MAUI, Semantic Kernel, Ollama & LiteDB
π Introduction
Artificial Intelligence applications today frequently rely on cloud APIs and external inference services. While this model provides scalability and powerful models, it also introduces several limitations: β οΈ API costs that grow over time
β οΈ Latency due to network requests
β οΈ Privacy concerns when sending data to external servers
β οΈ Internet dependency For many scenariosβespecially enterprise environments, field work, or privacy-sensitive applicationsβrunning AI locally on the device becomes a much better architectural choice. In this guide we will build a fully local AI assistant using the following stack:
- π₯ .NET MAUI β Cross-platform UI framework
- π§ Semantic Kernel β AI orchestration layer
- π¦ Ollama β Local LLM runtime
- πΎ LiteDB β Embedded vector database
- π¬ Shaunebu.MAUI.FloatingChatButton β Floating chat assistant UI
The result is a cross-platform AI assistant that runs completely offline, capable of answering questions, retrieving document context, and maintaining conversational interactions.
π§© Why This Stack?
Each component in this architecture serves a specific purpose.
π₯ .NET MAUI
.NET MAUI allows developers to build native cross-platform applications using a single C# codebase. Supported platforms include:
- Windows
- macOS
- Android
- iOS
This makes it perfect for building AI assistants that run directly on user devices.
π§ Semantic Kernel
Semantic Kernel acts as the AI orchestration layer. Instead of interacting directly with the LLM, Semantic Kernel allows developers to structure AI workflows such as: β¨ Prompt pipelines
β¨ Function orchestration
β¨ Context memory
β¨ Tool integration This makes AI applications modular and easier to maintain.
π¦ Ollama
Ollama is a lightweight runtime that enables running modern LLMs locally. Some popular models available include:
- Llama 3
- Phi-3
- Mistral
- Gemma
Running models locally provides several advantages: β
No API costs
β
Full data privacy
β
Low latency
β
Offline operation
πΎ LiteDB
LiteDB is a single-file embedded NoSQL database for .NET. In this architecture it acts as a local vector database. It stores:
- Document chunks
- Embeddings
- Metadata
This enables Retrieval-Augmented Generation (RAG) entirely on the device.
π Key Benefits of This Architecture
| Feature | Advantage |
|---|---|
| π° Zero Cloud Costs | Runs fully local |
| π Data Privacy | No external data transfer |
| πΆ Offline Support | Works without internet |
| π± Cross-Platform | Windows / macOS / Android / iOS |
| β‘ Fast Retrieval | Local vector search |
π Step-by-Step Implementation
1οΈβ£ Install Ollama (Local LLM)
First install Ollama on your system. Download from:
https://ollama.ai
Pull a lightweight model.
ollama pull phi3
Start the Ollama server:
ollama serve
The local API will be available at:
http://localhost:11434
2οΈβ£ Create the MAUI Project
Create a new project:
dotnet new maui -n MauiLocalAI
Install the required dependencies:
dotnet add package Microsoft.SemanticKernel
dotnet add package LiteDB
dotnet add package OllamaSharp
For the floating assistant UI:
dotnet add package Shaunebu.MAUI.FloatingChatButton
π Recommended Project Structure
MAUI-LocalAI/
β
βββ Services
β βββ OllamaService.cs
β βββ VectorDbService.cs
β
βββ ViewModels
β βββ ChatViewModel.cs
β
βββ Views
β βββ ChatPage.xaml
β
βββ Models
βββ Message.cs
This structure keeps AI logic separate from UI logic, making the project easier to maintain.
π§ Semantic Kernel + Ollama Integration
OllamaService.cs
using OllamaSharp;
using Microsoft.SemanticKernel;
public class OllamaService
{
private readonly Kernel _kernel;
public OllamaService()
{
var ollama = new OllamaApiClient("http://localhost:11434");
_kernel = Kernel.CreateBuilder()
.AddOllamaTextGeneration("phi3", ollama)
.Build();
}
public async Task<string> GetResponseAsync(string prompt)
{
return await _kernel.InvokePromptAsync(prompt);
}
}
This service acts as a bridge between the UI and the local AI model.
πΎ LiteDB Vector Storage
To support document search we store embeddings locally.
VectorDbService.cs
using LiteDB;
public class VectorDbService
{
private readonly LiteDatabase _db;
private readonly ILiteCollection<TextChunk> _chunks;
public VectorDbService()
{
_db = new LiteDatabase("LocalAI.db");
_chunks = _db.GetCollection<TextChunk>("chunks");
}
public void AddText(string text, float[] embedding)
{
_chunks.Insert(new TextChunk
{
Text = text,
Embedding = embedding
});
}
}
This enables semantic document retrieval.
π¬ Building the Chat UI
ChatPage.xaml
<ContentPage>
<StackLayout>
<CollectionView ItemsSource="{Binding Messages}">
<DataTemplate>
<Label Text="{Binding Text}" />
</DataTemplate>
</CollectionView>
<Entry Placeholder="Ask something..."
Text="{Binding UserInput}" />
<Button Text="Send"
Command="{Binding SendCommand}" />
</StackLayout>
</ContentPage>
π¬ Floating Assistant UI
Instead of showing the chat interface immediately, we can use Shaunebu.MAUI.FloatingChatButton to create a floating assistant button similar to modern messaging apps. This improves the UX because the assistant becomes available globally across the application. Example usage:
When pressed, it opens the chat window containing the AI assistant. This approach provides a clean and modern assistant interaction pattern.
π― Example Use Cases
This architecture is ideal for scenarios such as: π Offline document Q&A
Users can query PDFs or local documentation. π§ββοΈ Privacy-sensitive assistants
Medical, legal, or enterprise environments. π Field worker tools
Assistants running on devices without internet. π Knowledge base assistants
Local semantic search over internal documentation.
π― Conclusion
By combining:
- π₯ .NET MAUI
- π§ Semantic Kernel
- π¦ Ollama
- πΎ LiteDB
- π¬ Shaunebu.MAUI.FloatingChatButton
we can build a fully local AI assistant that runs entirely on-device. This architecture provides: β
Complete data privacy
β
Zero cloud costs
β
Offline AI capabilities
β
Cross-platform deployment
As local AI models continue to improve, architectures like this will become increasingly powerful for building privacy-first intelligent applications.
