From 401147009aee7bdf6f221b3b3ae544846d53870f Mon Sep 17 00:00:00 2001 From: Catherine Renelle <32781029+catrenelle@users.noreply.github.com> Date: Thu, 12 Feb 2026 19:25:24 -0500 Subject: [PATCH] Increase Ollama context window to 16k tokens Ollama defaults to 2048 tokens which is far too small for page context data + 15 tool definitions + conversation history. Added num_ctx=16384 via the options field on all Ollama requests. With Qwen at ~4GB and 7GB VRAM free this fits comfortably. Co-Authored-By: Claude Opus 4.6 --- src/Purrse.Api/Services/ChatService.cs | 6 ++++-- src/Purrse.Core/DTOs/ChatDtos.cs | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Purrse.Api/Services/ChatService.cs b/src/Purrse.Api/Services/ChatService.cs index ed8bcdf..57e87ae 100644 --- a/src/Purrse.Api/Services/ChatService.cs +++ b/src/Purrse.Api/Services/ChatService.cs @@ -198,7 +198,8 @@ public class ChatService : IChatService Model = modelName, Messages = ollamaMessages, Stream = false, - Tools = tools + Tools = tools, + Options = new OllamaRequestOptions { NumCtx = 16384 } }; var response = await CallOllamaAsync(ollamaUrl, ollamaRequest); @@ -270,7 +271,8 @@ public class ChatService : IChatService Model = modelName, Messages = ollamaMessages, Stream = false, - Tools = null // drop tools so the model focuses on the page data + Tools = null, // drop tools so the model focuses on the page data + Options = new OllamaRequestOptions { NumCtx = 16384 } }; var retryResponse = await CallOllamaAsync(ollamaUrl, retryRequest); rawContent = retryResponse?.Message?.Content; diff --git a/src/Purrse.Core/DTOs/ChatDtos.cs b/src/Purrse.Core/DTOs/ChatDtos.cs index 962adb7..6d67542 100644 --- a/src/Purrse.Core/DTOs/ChatDtos.cs +++ b/src/Purrse.Core/DTOs/ChatDtos.cs @@ -45,6 +45,16 @@ public class OllamaToolChatRequest [JsonPropertyName("tools")] public List? Tools { get; set; } + + [JsonPropertyName("options")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public OllamaRequestOptions? Options { get; set; } +} + +public class OllamaRequestOptions +{ + [JsonPropertyName("num_ctx")] + public int NumCtx { get; set; } } public class OllamaToolMessage