Expand description
§rig-llama-cpp
A Rig provider that runs GGUF models locally via llama.cpp, with optional Vulkan GPU acceleration.
A loaded model is a Rig Model — a completion wire bound to an
in-process runtime — so any GGUF model can stand in for a cloud provider wherever Rig
takes a model (DynModel, rig_agent::AgentBuilder, …). It supports:
- Completion and streaming — both one-shot and token-by-token responses.
- Tool calling — models with OpenAI-compatible chat templates can invoke tools.
- Reasoning / thinking — extended thinking output is forwarded when the model supports it.
- Configurable sampling — top-p, top-k, min-p, temperature, presence and repetition penalties.
- Embeddings — generate text embeddings using GGUF embedding models.
§Feature flags
There is no default GPU backend — pick exactly the one that matches your hardware. With no feature enabled the build is CPU-only.
GPU backends (forwarded to llama-cpp-2):
vulkan— cross-vendor GPU (recommended on Linux/Windows when CUDA/ROCm aren’t set up).cuda— NVIDIA GPUs with the CUDA toolkit installed.metal— Apple Silicon / macOS.rocm— AMD GPUs on Linux with the ROCm toolchain.
Other:
openmp— OpenMP CPU threading; orthogonal to the GPU backends and may be combined with any of them.mtmd— multimodal (vision) inference; required forClient::from_gguf_with_mmprojandClientBuilder::mmproj.
Examples:
cargo build --features vulkan
cargo build --features cuda
cargo build --features "vulkan,mtmd"Backend support depends on the corresponding llama-cpp-2 feature and any required
native toolchain or system libraries being available on the host machine.
§Quick start
Agents come from the rig-agent crate:
use rig_agent::AgentBuilder;
let client = rig_llama_cpp::Client::builder("path/to/model.gguf")
.n_ctx(8192)
.build()?;
let agent = AgentBuilder::new(client.completion_model("local"))
.preamble("You are a helpful assistant.")
.max_tokens(512)
.build();
let response = agent.prompt("Hello!").await?;
println!("{}", response.output());Structs§
- Checkpoint
Params - Tunable parameters for the in-memory state-checkpoint cache used to preserve KV/recurrent state across chat turns for hybrid models.
- Client
- The llama.cpp completion client.
- Client
Builder - Builder for
Client. - Completion
Wire - The completion wire of a local llama.cpp model.
- Embedding
Client - The llama.cpp embedding client.
- Embedding
Runtime - The transport behind
EmbeddingModelHandle: it hands each batch of texts to the embedding worker thread. - FitParams
- Configuration for automatic GPU/CPU layer fitting.
- Frame
- One step of a reply, as the inference worker delivers it to the
CompletionWiredecoder. - Frame
Decoder - The decoder of
CompletionWire: writes each workerFrameinto the reply. - KvCache
Params - KV cache quantization configuration.
- RawDocument
- Rebuilds a reply’s provider document — a serialized
RawResponse— from the worker’s end frame. - RawResponse
- The provider document of a reply: what
CompletionResponse::rawholds for every completion this crate produces, unary or streamed. - Runtime
- The transport of a
Model: carries each request to the inference worker thread and delivers its reply asFrames. - Sampling
Params - Sampling parameters that control token generation.
Enums§
- KvCache
Type - Data type used for an entry in the attention KV cache.
- Load
Error - Failure modes returned when constructing or reloading a
crate::Clientorcrate::EmbeddingClient.
Type Aliases§
- Embedding
Model Handle - A loaded embedding model: Rig’s local embedding wire over the embedding worker.
- Model
- A loaded model as Rig drives it:
CompletionWireoverRuntime.