New Tool Radar

Local AI

How to Increase the Context Length for a Chat in GPT4All

In GPT4All's model settings, raise Context Length above its 2048-token default so longer conversations and LocalDocs snippets fit before the model forgets the start.

Schematic diagram with three steps: open the model settings in GPT4All, raise Context Length above the 2048 default, then chat on and check the model still remembers the start.

A chat model can only see so much at once: the context length is the maximum length of the input sequence in tokens, and once a conversation grows past it, the earliest messages fall out of view and the model starts forgetting what you said at the start. GPT4All’s default is 2048 tokens, and it is a per-model setting — you raise it for the model you chat with, not for the whole app. This is the GPT4All setting; the Ollama and LM Studio context settings are different guides for different apps.

Find the setting

Open the model’s settings in the GPT4All desktop app. The official settings page lists it under Model Sampling Settings:

Setting Description Default value
Context Length Maximum length of input sequence in tokens 2048
Max Length Maximum length of response in tokens 4096
Prompt Batch Size Token batch size for parallel processing 128
Temperature Lower temperature gives more likely generations 0.7

Do not confuse Context Length with Max Length: the first is how much the model can take in, the second is how long its reply may be. Raising Max Length does not help a model remember a long conversation.

Raise it and keep the original

Change Context Length from 2048 to a larger value — 4096 for a long conversation, 8192 for a very long one with documents attached. If you want to compare the two settings side by side, clone the model first: the settings page says you can clone an existing model, which lets you save a configuration of a model file with different prompt templates and sampling settings. That way the original keeps its 2048 default and the clone carries the larger context.

The same limit exists in the Python package, where the GPT4All constructor takes n_ctx — “Maximum size of context window” — with a default of 2048:

from gpt4all import GPT4All
model = GPT4All("Meta-Llama-3-8B-Instruct.Q4_0.gguf", n_ctx=4096)

Check that the start is still remembered

Start a chat, give the model a fact to remember in the first message — for a practice check, “The lighthouse keeper is named Mara” — then keep chatting for a while, and ask near the end: “What is the lighthouse keeper’s name?”

Check What you should see If you do not see it
Setting Context Length reads 4096 (or your chosen value) for this model You changed Max Length instead — that limits the reply, not the input
Other models Your other models still show 2048 The setting is per model by design — change each one separately, or clone
Memory The model answers “Mara” after a long conversation The conversation outgrew even the raised limit — raise it further or start a new chat

Expected result. We checked GPT4All’s own settings docs for the Context Length default and the clone option, and the Python bindings source for the n_ctx default. We did not run GPT4All.

Limits

A larger context window is not free: it is more input for the model to process on every reply, so generation can get slower, and the LocalDocs settings note that increasing related settings may slow generation. The setting is per model, so raising it for one model does not change any other. The practice check above is fictional — use your own conversation and your own first message. We did not run GPT4All, so no reply here is a recorded result.

Sources

See all