Inference context - manages KV cache and generation state
Instance methods
clear_memory
Clear KV cache + recurrent state (decoder/hybrid models only, NOT BERT)
SourceEncode tokens for BERT/encoder models (uses llama_encode instead of llama_decode)
SourceProcess prompt tokens (prefill)
Sourceget_embeddings
Get embeddings (requires embeddings=true in context)
Sourceget_logits
Get logits for last token
SourceGet sequence embeddings (for BERT/encoder models with pooling)
Sourceposition
Current position in context
Sourcereset
Reset position + sampler (safe for all context types including BERT)
Sourcereset_perf
Reset performance counters
Sourcesetup_greedy_sampler
Greedy sampler (deterministic)
Sourcesetup_sampler(temperature :
Float32 = 0.8_f32, top_k :
Int32 = 40, top_p :
Float32 = 0.95_f32, min_p :
Float32 = 0.05_f32, seed :
UInt32 =
LlamaFFI::LLAMA_DEFAULT_SEED)
Setup sampler chain with default parameters
Source