pub struct OllamaGenerationParams {
pub num_predict: Option<u32>,
pub temperature: Option<f32>,
pub top_p: Option<f32>,
pub top_k: Option<u32>,
pub stop: Option<Vec<String>>,
pub repeat_penalty: Option<f32>,
pub num_ctx: Option<u32>,
pub keep_alive: Option<String>,
pub context: Option<Vec<i64>>,
}Expand description
Generation parameters for Ollama requests
Fields§
§num_predict: Option<u32>Maximum tokens to generate
temperature: Option<f32>Temperature for sampling (0.0 - 1.0)
top_p: Option<f32>Top-p nucleus sampling threshold
top_k: Option<u32>Top-k sampling
stop: Option<Vec<String>>Stop sequences
repeat_penalty: Option<f32>Repeat penalty
num_ctx: Option<u32>Context window size in tokens.
Critical for long documents: Ollama silently truncates prompts that exceed the default context size (often 2k-8k tokens). Set this to accommodate the full document + chunk + instructions when using Contextual Enrichment.
For KV Cache efficiency, calculate as:
tokens(instructions) + tokens(document) + tokens(max_chunk) + output_tokens + 5% margin
keep_alive: Option<String>How long to keep the model loaded in memory after the request (e.g. “1h”, “30m”, “0”).
Critical for KV Cache: Without this, Ollama may unload the model between consecutive requests, destroying the KV cache and forcing a full re-evaluation of the static document prefix for every chunk. Set to “1h” when processing multiple chunks from the same document.
This is a top-level Ollama API field, not an option — serialized separately.
context: Option<Vec<i64>>KV cache context from a previous /api/generate response.
When set, the model continues from this token state instead of re-evaluating the entire prompt. Use this for the two-step KV cache pattern:
- Prime: send the full document, get
contextback (loads doc into KV cache) - Per chunk: send only the chunk text with the priming
context→ Ollama skips document re-evaluation, only evaluates ~128 chunk tokens
This is a top-level Ollama API field — serialized separately.
Trait Implementations§
Source§impl Clone for OllamaGenerationParams
impl Clone for OllamaGenerationParams
Source§fn clone(&self) -> OllamaGenerationParams
fn clone(&self) -> OllamaGenerationParams
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OllamaGenerationParams
impl Debug for OllamaGenerationParams
Source§impl Default for OllamaGenerationParams
impl Default for OllamaGenerationParams
Source§impl<'de> Deserialize<'de> for OllamaGenerationParams
impl<'de> Deserialize<'de> for OllamaGenerationParams
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for OllamaGenerationParams
impl RefUnwindSafe for OllamaGenerationParams
impl Send for OllamaGenerationParams
impl Sync for OllamaGenerationParams
impl Unpin for OllamaGenerationParams
impl UnsafeUnpin for OllamaGenerationParams
impl UnwindSafe for OllamaGenerationParams
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more