New Tool Radar

Local AI

How to Set the Context Length for llama-server With a Flag

Set the context length for llama-server with a flag and confirm long input stays in view.

Schematic with three steps: Start the server with a context flag; Send a long input; Check the answer uses the start.

Context length is how much text the model keeps in view at once. llama-server takes it as a flag, so you can raise it for a long document instead of watching the start of the conversation drop out of view.

What you need

  • llama.cpp built or installed with llama-server
  • A GGUF model file
  • A long input to test with, for example a multi-page document

Step 1: Start the server with a context flag

Run llama-server -m model.gguf -c 32768 to start with a 32,768-token context. The flag sets the context for that server run.

Step 2: Send a long input

Send the long document to the server through its chat endpoint or web interface, and ask a question about the start of the document.

Step 3: Check the answer uses the start

Read the answer and confirm it refers to the start of the document. If it says the start is not in the input, the context is still too short or the flag was not applied.

Worked example: synthetic context check

The table below is a synthetic example. It shows the expected result of setting context length; no server was run.

Context flag Document length Start remembered?
Default Short note Yes
-c 32768 Long document Yes
-c 32768 Very long document Check the token count

Expected result (UNTESTED). with a 32,768-token context the server answers a question about the start of a long document, while the default context drops it. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • A longer context needs more memory for the KV cache, so raise it only as far as your memory allows.
  • The model itself has a maximum context; a flag above it does not help.
  • Count the tokens in the input first, because a document longer than the context still loses its start.

Sources

See all