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.

An unhandled error has occurred. Reload πŸ—™