Skip to main content

Crate rig_llama_cpp

Crate rig_llama_cpp 

Source
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 for Client::from_gguf_with_mmproj and ClientBuilder::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§

CheckpointParams
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.
ClientBuilder
Builder for Client.
CompletionWire
The completion wire of a local llama.cpp model.
EmbeddingClient
The llama.cpp embedding client.
EmbeddingRuntime
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 CompletionWire decoder.
FrameDecoder
The decoder of CompletionWire: writes each worker Frame into the reply.
KvCacheParams
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::raw holds 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 as Frames.
SamplingParams
Sampling parameters that control token generation.

Enums§

KvCacheType
Data type used for an entry in the attention KV cache.
LoadError
Failure modes returned when constructing or reloading a crate::Client or crate::EmbeddingClient.

Type Aliases§

EmbeddingModelHandle
A loaded embedding model: Rig’s local embedding wire over the embedding worker.
Model
A loaded model as Rig drives it: CompletionWire over Runtime.