VOOZH about

URL: https://deepwiki.com/SciSharp/LLamaSharp/1.1-package-architecture

⇱ Package Architecture | SciSharp/LLamaSharp | DeepWiki


Loading...
Last indexed: 18 May 2026 (ecd184)
Menu

Package Architecture

Purpose and Scope

This document explains the modular package structure of LLamaSharp and how the different NuGet packages are organized and distributed. It covers the core library package, backend packages for different hardware platforms, integration packages for Microsoft AI frameworks, and experimental mobile/auto-download support.

For information about installing these packages and setting up your development environment, see 1.2 Installation and Setup For details about the runtime architecture and how these packages interact with native libraries at runtime, see 2.1 Native Library Integration

Package Structure Overview

LLamaSharp follows a modular distribution strategy that separates concerns into distinct NuGet packages. This design allows users to install only the components they need, reducing package size and avoiding unnecessary dependencies.

The package ecosystem consists of four primary categories:

Package CategoryPurposeTarget Users
Core LibraryProvides the fundamental API and abstractions for LLM inferenceAll users
Backend PackagesContains platform-specific native binaries compiled from llama.cppUsers select one based on hardware
Integration PackagesExtends LLamaSharp to work with Microsoft AI frameworksUsers of Semantic Kernel or Kernel Memory
Experimental/MobileAdvanced features (auto-download) and MAUI mobile supportAdvanced users and mobile developers

Sources: README.md87-108 LLama.Experimental/LLama.Experimental.csproj19-22 Llama.Mobile/Llama.Mobile.csproj15-31

NuGet Package Distribution

The following diagram shows the complete NuGet package ecosystem and how packages relate to each other:

LLamaSharp Ecosystem Relationship


Sources: README.md5-11 LLama/LLamaSharp.csproj30 LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj31 LLama.KernelMemory/LLamaSharp.KernelMemory.csproj25 LLama.Experimental/LLama.Experimental.csproj29 Llama.Mobile/Llama.Mobile.csproj79

Core Library Package

The LLamaSharp package is the primary library that provides all high-level APIs for working with LLMs. It contains the managed .NET code but does not include native binaries.

Package Metadata

PropertyValue
PackageIdLLamaSharp
Version0.27.0
Target Frameworksnetstandard2.0, net8.0
PlatformsAnyCPU, x64, Arm64

Sources: LLama/LLamaSharp.csproj3-30

Core Dependencies

The core library has minimal external dependencies to maximize compatibility, including the Microsoft.Extensions.AI.Abstractions for standardized AI interfaces.

Core Package Dependencies


Sources: LLama/LLamaSharp.csproj44-59

Binary Distribution Mechanism

The core package includes MSBuild targets that automatically download and extract native binaries during build for development environments. This mechanism uses a BinaryReleaseId to track versions of llama.cpp dependencies.

MSBuild Binary Retrieval Flow


Sources: LLama/LLamaSharp.csproj61-100

Backend Packages

Backend packages contain platform-specific native binaries compiled from llama.cpp. These packages use .props files to ensure native libraries are copied to the output directory and correctly linked for various platforms, including Android.

Available Backend Packages

Package NamePlatformsHardware Support
LLamaSharp.Backend.CpuWindows, Linux, macOSCPU inference; Metal GPU on macOS
LLamaSharp.Backend.Cuda11Windows, LinuxNVIDIA GPU with CUDA 11.x
LLamaSharp.Backend.Cuda12Windows, LinuxNVIDIA GPU with CUDA 12.x
LLamaSharp.Backend.VulkanWindows, LinuxVulkan-compatible GPUs

Sources: README.md99-105 LLama/runtimes/build/LLamaSharp.Backend.Cuda12.Windows.nuspec4-12 LLama/runtimes/build/LLamaSharp.Backend.Vulkan.Windows.nuspec4-12

Native Library Mapping (Android Example)

The backend packages for mobile use AndroidNativeLibrary items to map native .so files (like libllama.so, libggml.so, and libmtmd.so) to specific ABIs.

Native LibraryABISource Path
libllama.soarm64-v8aruntimes/deps/android-arm64-v8a/libllama.so
libggml.sox86_64runtimes/deps/android-x86_64/libggml.so

Sources: LLama/runtimes/build/LLamaSharpBackend.props57-84 LLama/runtimes/build/LLamaSharp.Backend.Cpu.Android.nuspec21-31

Integration Packages

Integration packages extend LLamaSharp to work seamlessly with Microsoft's AI ecosystem.

Semantic Kernel Integration

The LLamaSharp.semantic-kernel package provides integration with Microsoft Semantic Kernel, enabling LLamaSharp to act as a local LLM backend for SK-based applications.

Metadata:

Kernel Memory Integration

The LLamaSharp.kernel-memory package provides integration with Microsoft Kernel Memory for Retrieval-Augmented Generation (RAG) scenarios.

Metadata:

Experimental and Mobile Support

Experimental Auto-Download

The LLama.Experimental package includes features for automatic native library downloading from Hugging Face via the NativeLibraryDownloader class. This allows applications to fetch the required native binaries at runtime based on environment detection.

Mobile Support (MAUI)

The Llama.Mobile project demonstrates LLamaSharp running on mobile platforms using .NET MAUI.

Sources: LLama.Experimental/LLama.Experimental.csproj1-42 Llama.Mobile/Llama.Mobile.csproj1-82 LLama.Experimental/Native/NativeLibraryDownloader.cs1-115

Examples and Web Projects

The repository includes several demonstration projects:

Sources: LLamaSharp.sln8-14

Version Synchronization

All LLamaSharp packages maintain synchronized version numbers to ensure compatibility across the ecosystem.

PackageCurrent Version
LLamaSharp0.27.0
LLamaSharp.semantic-kernel0.27.0
LLamaSharp.kernel-memory0.27.0

Sources: LLama/LLamaSharp.csproj10 LLama.SemanticKernel/LLamaSharp.SemanticKernel.csproj13 LLama.KernelMemory/LLamaSharp.KernelMemory.csproj7