llama_memory_clear: Clear the KV cache

View source: R/llama.R

llama_memory_clearR Documentation

Clear the KV cache

Description

Removes all tokens from the KV cache. Call this before starting a new generation from scratch.

Usage

llama_memory_clear(ctx)

Arguments

ctx

Context handle returned by [llama_new_context]

Value

No return value, called for side effects.

Examples

## Not run: 
# Clear the KV cache to start a fresh conversation
llama_memory_clear(ctx)
result <- llama_generate(ctx, "New topic: ", max_new_tokens = 50L)

## End(Not run)

llamaR documentation built on May 28, 2026, 1:06 a.m.