[GH-ISSUE #8531] Ollama Truncates Beginning of User Messages and System Prompt When Exceeding Context Window #31262

Closed
opened 2026-04-22 11:33:36 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @vYLQs6 on GitHub (Jan 22, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/8531

What is the issue?

Description:

I am encountering an issue with Ollama where, upon sending a message that exceeds the context window, the model truncates the beginning of the message, including the system prompt. This is particularly frustrating as it leads to the loss of crucial context that is essential for the model's behavior.

Steps to Reproduce:

  1. Compose a message exceeding the context window limit.
  2. Send the message to Ollama.
  3. Observe that the beginning of the message, including the system prompt, is truncated.

Expected Behavior:

When a message exceeds the context window, Ollama should prioritize retaining the beginning of the message, especially the system prompt, to maintain context and ensure the model behaves as intended.

Request for Assistance:

Could you please advise if there are parameters that can be adjusted to modify this behavior? Allowing the retention of the message's beginning would significantly enhance the user experience. Thank you for your consideration and assistance.

OS

Windows

GPU

Nvidia

CPU

AMD

Ollama version

v0.5.7

Originally created by @vYLQs6 on GitHub (Jan 22, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/8531 ### What is the issue? **Description:** I am encountering an issue with Ollama where, upon sending a message that exceeds the context window, the model truncates the beginning of the message, including the system prompt. This is particularly frustrating as it leads to the loss of crucial context that is essential for the model's behavior. **Steps to Reproduce:** 1. Compose a message exceeding the context window limit. 2. Send the message to Ollama. 3. Observe that the beginning of the message, including the system prompt, is truncated. **Expected Behavior:** When a message exceeds the context window, Ollama should prioritize retaining the beginning of the message, especially the system prompt, to maintain context and ensure the model behaves as intended. **Request for Assistance:** Could you please advise if there are parameters that can be adjusted to modify this behavior? Allowing the retention of the message's beginning would significantly enhance the user experience. Thank you for your consideration and assistance. ### OS Windows ### GPU Nvidia ### CPU AMD ### Ollama version v0.5.7
GiteaMirror added the bug label 2026-04-22 11:33:36 -05:00
Author
Owner

@rick-github commented on GitHub (Jan 22, 2025):

When a message exceeds the context window, Ollama should prioritize retaining the beginning of the message, especially the system prompt, to maintain context and ensure the model behaves as intended.

This is how ollama works now. For example, if I send a prompt with a system message and some user/assistant messages, I can examine the logs and see how the input is processed. With the default context window (2048 tokes), we see that the input is wrapped in special tokens and otherwise intact:

$ curl -s localhost:11434/api/chat -d '{"model":"qwen2.5:0.5b","messages":[{"role":"system","content":"speak like a pirate"},{"role":"user","content":"hello"},{"role":"assistant","content":"how can i assist you"},{"role":"user","content":"polly wanna cracker"}]}'
$ printf "$(docker compose logs ollama | sed -ne 's/.*"chat request"[^"]*"\(.*\).$/\1/p' | tail -1)"'\n'
<|im_start|>system
speak like a pirate<|im_end|>
<|im_start|>user
hello<|im_end|>
<|im_start|>assistant
how can i assist you<|im_end|>
<|im_start|>user
polly wanna cracker<|im_end|>
<|im_start|>assistant

If the context window is reduced in size, we see that the first few user/assistant messages are dropped, but the system message is preserved:

$ curl -s localhost:11434/api/chat -d '{"model":"qwen2.5:0.5b","messages":[{"role":"system","content":"speak like a pirate"},{"role":"user","content":"hello"},{"role":"assistant","content":"how can i assist you"},{"role":"user","content":"polly wanna cracker"}],"options":{"num_ctx":32}}'
$ printf "$(docker compose logs ollama | sed -ne 's/.*"chat request"[^"]*"\(.*\).$/\1/p' | tail -1)"'\n'
<|im_start|>system
speak like a pirate<|im_end|>
<|im_start|>user
polly wanna cracker<|im_end|>
<|im_start|>assistant

Could you please advise if there are parameters that can be adjusted to modify this behavior?

Increase the context window in the API call (num_ctx) or modify the model to have a larger default context, see here.

<!-- gh-comment-id:2606510905 --> @rick-github commented on GitHub (Jan 22, 2025): > When a message exceeds the context window, Ollama should prioritize retaining the beginning of the message, especially the system prompt, to maintain context and ensure the model behaves as intended. This is how ollama works now. For example, if I send a prompt with a system message and some user/assistant messages, I can examine the logs and see how the input is processed. With the default context window (2048 tokes), we see that the input is wrapped in special tokens and otherwise intact: ```console $ curl -s localhost:11434/api/chat -d '{"model":"qwen2.5:0.5b","messages":[{"role":"system","content":"speak like a pirate"},{"role":"user","content":"hello"},{"role":"assistant","content":"how can i assist you"},{"role":"user","content":"polly wanna cracker"}]}' $ printf "$(docker compose logs ollama | sed -ne 's/.*"chat request"[^"]*"\(.*\).$/\1/p' | tail -1)"'\n' <|im_start|>system speak like a pirate<|im_end|> <|im_start|>user hello<|im_end|> <|im_start|>assistant how can i assist you<|im_end|> <|im_start|>user polly wanna cracker<|im_end|> <|im_start|>assistant ``` If the context window is reduced in size, we see that the first few user/assistant messages are dropped, but the system message is preserved: ```console $ curl -s localhost:11434/api/chat -d '{"model":"qwen2.5:0.5b","messages":[{"role":"system","content":"speak like a pirate"},{"role":"user","content":"hello"},{"role":"assistant","content":"how can i assist you"},{"role":"user","content":"polly wanna cracker"}],"options":{"num_ctx":32}}' $ printf "$(docker compose logs ollama | sed -ne 's/.*"chat request"[^"]*"\(.*\).$/\1/p' | tail -1)"'\n' <|im_start|>system speak like a pirate<|im_end|> <|im_start|>user polly wanna cracker<|im_end|> <|im_start|>assistant ``` > Could you please advise if there are parameters that can be adjusted to modify this behavior? Increase the context window in the API call (`num_ctx`) or modify the model to have a larger default context, see [here](https://github.com/ollama/ollama/issues/5965#issuecomment-2252354726).
Author
Owner

@vYLQs6 commented on GitHub (Jan 22, 2025):

but the system message is preserved

Weird, are you sure about that? That's not what I experience when using Ollama + Open WebUI.

Here’s what I did:

  1. I used Qwen2.5 32B with 32K context, and included a system prompt to analyze the news in a particular way.
  2. I sent it a large amount of news in the first message, with no instructions other than the news itself.
  3. When the context window was exceeded, it always forgot what it should be doing and just decided to summarize the news instead.

Maybe this is caused by Open WebUI? However, I did see the context window exceeded warning from Ollama.

<!-- gh-comment-id:2607286605 --> @vYLQs6 commented on GitHub (Jan 22, 2025): > but the system message is preserved Weird, are you sure about that? That's not what I experience when using Ollama + Open WebUI. Here’s what I did: 1. I used Qwen2.5 32B with 32K context, and included a system prompt to analyze the news in a particular way. 2. I sent it a large amount of news in the first message, with no instructions other than the news itself. 3. When the context window was exceeded, it always forgot what it should be doing and just decided to summarize the news instead. Maybe this is caused by Open WebUI? However, I did see the context window exceeded warning from Ollama.
Author
Owner

@vYLQs6 commented on GitHub (Jan 22, 2025):

I just tested this again with another model, 16k context, with another system prompt, which simply tells it to translate everything to english.

I give it a bunch of foreign news (not in english)

context window was exceeded, level=WARN source=runner.go:129 msg="truncating input prompt" limit=16000 prompt=30838 keep=4 new=16000

and it just give me a summarization of the news in that foreign language, not following the system prompt

<!-- gh-comment-id:2607302452 --> @vYLQs6 commented on GitHub (Jan 22, 2025): I just tested this again with another model, 16k context, with another system prompt, which simply tells it to translate everything to english. I give it a bunch of foreign news (not in english) context window was exceeded, `level=WARN source=runner.go:129 msg="truncating input prompt" limit=16000 prompt=30838 keep=4 new=16000` and it just give me a summarization of the news in that foreign language, not following the system prompt
Author
Owner

@rick-github commented on GitHub (Jan 22, 2025):

Enable verbose logging (OLLAMA_DEBUG=1), re-run your test and add the logs here. The message you are seeing is from the runner, the message pruning I described above is done by the server. It sounds like the input the server is getting is just one big chunk of text, which it can't prune because there are no individual messages, and the lot gets passed to the runner which then just cuts enough off to fit in the KV cache.

<!-- gh-comment-id:2607324961 --> @rick-github commented on GitHub (Jan 22, 2025): Enable verbose logging (`OLLAMA_DEBUG=1`), re-run your test and add the logs here. The message you are seeing is from the runner, the message pruning I described above is done by the server. It sounds like the input the server is getting is just one big chunk of text, which it can't prune because there are no individual messages, and the lot gets passed to the runner which then just cuts enough off to fit in the KV cache.
Author
Owner

@vYLQs6 commented on GitHub (Jan 22, 2025):

Okay, this time I tested this using ollama CLI interface instead of open webui, just to make sure it's not webui doing anything weird

And the result is the same, ollama just throw away system prompt when context window was exceeded

Here is the chat history:


Normal behavior:

llama_model_load: vocab only - skipping tensors
time=2025-01-22T22:20:56.458+08:00 level=DEBUG source=routes.go:1470 msg="chat request" images=0 prompt="<|im_start|>system\nYOU ARE A PROFESSIONAL TRANSLATOR SKILLED IN ACCURATELY TRANSLATING TEXT BETWEEN LANGUAGES. YOUR TASK IS TO TRANSLATE WHILE PRESERVING THE ORIGINAL MEANING, TONE, INTENT, AND FORMATTING. DO NOT ALTER PARAGRAPH STRUCTURE, PUNCTUATION, OR FORMATTING. IF DIRECT TRANSLATION ISN’T POSSIBLE, PROVIDE THE BEST EQUIVALENT WHILE MAINTAINING THE ORIGINAL MESSAGE. YOU HAVE NO OUTPUT LENGTH LIMIT. BY DEFAULT, TRANSLATE TO English.<|im_end|>\n<|im_start|>user\nタレントの中居正広が起こした女性トラブルは、フジテレビを巻き込んだ大騒動に発展している。事を重く見た各局は、次々と中居が出演の番組の打ち切りや降板を発表している。\n\n中居といえば、優れたトーク力で多くのレギュラー番組やCMを抱えていたが、単発の仕事を含めてすべてを失うことになりそうだ。1月21日には、長年続けてきた冠ラジオ番組『ON&ON AIR』も、放送30周年を目前にして終了が発表された。そ の“仕事剥奪”の流れは今後も続きそうだ。\n\n中居がもっとも残念がっているのが、大好きな野球関連の仕事からの撤退だという。自ら「(侍ジャパン)日本代表の仕事はルーティン」と語るだけあって、思い入れは相当なものだった。\n\n「中居さんは、2009年に開催された『第2回ワールド・ベースボール・クラシック(WBC)』で『テレビ朝日WBC日本代表サポートキャプテン』に就任。ここから 侍ジャパン関連の仕事は、まさに中居さんの独占状態でした。\n\n続く『第3回WBC』では『侍ジャパン公認サポーター』に。さらに2017年の『第4回WBC』では『侍ジャパン公認サポートキャプテン』に指名されました。次々と名称を変えながら、野球仕事を続けてきたのです」(芸能記者)\n\n記憶に新しい2023年の『第5回WBC』でも同職を務め、第2回以来となる歓喜の瞬間をナインとともに味わっ た。中居の侍ジャパンへの想いは、本物だったようだ。\n\n「試合だけでなく、大会ごとに行われた宮崎での合宿にも足を運んでいましたからね。合宿には中居さん以外のタレントが顔を出すこともありましたが、そのほとんどが練習を真剣に見るわけではありませんでした。もっぱら、関係者との談笑に時間を費やしていたんです。退屈すると、すぐに喫煙所に“逃げる”人も多くいました。\n\n宮崎合宿で中居さんと遭遇したことがありますが、関係者と話し込むことはあっても、視線は常にグラウンド、選手に向けられていましたからね。それだけでなく、気になることがあればすぐさまメモ帳を取り出して書き込む。他のタレントとは、まさに一線を画していました」(スポーツ記者)\n\n中居といえば、選手との交友関係が広いことでも有名だ。それというのも、中居の野球に向き合う“本気 姿勢”ゆえのことだったようだ。\n\n「練習を真剣に見てメモを取るなど、中居の本気度は選手にも知られていて認められる存在でし た。事前にも勉強しているからでしょうか、選手への取材も、他のタレントとは違って的を射たものが多かったんです。\n\nしかし、一連の騒動で状況一変。なかには『野球のイメージが悪くなるから合宿や試合に来ないでほしい』ということを言う選手すらいるほどです。\n\n今年の3月5~6日には京セラドームで『ラグザス 侍ジャパンシリーズ2025』が行われます。来年連覇がかかる『第6回WBC』に向けた強化試合です。本来なら、中居さんは“公認キャプテン”として現場に行く予定でしたが、出演は絶望的です。\n\n両試合はTBS系とテレビ朝日系が担当しますが、いずれもゴールデンタイムの時間帯なのでスポンサーも多い。もし中居さんが出演となれば、ス ポンサーが降りる可能性が高いですからね……」(スポーツ紙デスク)\n\n中居が長年積み上げてきた努力も水泡に帰してしまうのか……。<|im_end|>\n<|im_start|>assistant\n"
time=2025-01-22T22:20:56.464+08:00 level=DEBUG source=cache.go:104 msg="loading cache slot" id=0 cache=0 prompt=1039 used=0 remaining=1039
[GIN] 2025/01/22 - 22:21:10 | 200 |   14.1750906s |       127.0.0.1 | POST     "/api/chat"
time=2025-01-22T22:21:10.419+08:00 level=DEBUG source=sched.go:407 msg="context for request finished"
time=2025-01-22T22:21:10.419+08:00 level=DEBUG source=sched.go:339 msg="runner with non-zero duration has gone idle, adding timer" modelPath=D:\LLM\.ollama\models\blobs\sha256-b2c12d46c1eec7e6536b759f1b6d5f98e254ade8a25c293f0fc01cce9489af69 duration=5m0s
time=2025-01-22T22:21:10.419+08:00 level=DEBUG source=sched.go:357 msg="after processing request finished event" modelPath=D:\LLM\.ollama\models\blobs\sha256-b2c12d46c1eec7e6536b759f1b6d5f98e254ade8a25c293f0fc01cce9489af69 refCount=0
[GIN] 2025/01/22 - 22:21:53 | 200 |            0s |       127.0.0.1 | HEAD     "/"
[GIN] 2025/01/22 - 22:21:53 | 200 |     22.3404ms |       127.0.0.1 | POST     "/api/show"
time=2025-01-22T22:21:53.958+08:00 level=DEBUG source=sched.go:575 msg="evaluating already loaded" model=D:\LLM\.ollama\models\blobs\sha256-b2c12d46c1eec7e6536b759f1b6d5f98e254ade8a25c293f0fc01cce9489af69
[GIN] 2025/01/22 - 22:21:53 | 200 |     22.8907ms |       127.0.0.1 | POST     "/api/generate"
time=2025-01-22T22:21:53.960+08:00 level=DEBUG source=sched.go:407 msg="context for request finished"

As you can see there are the YOU ARE A PROFESSIONAL TRANSLATOR ... BY DEFAULT, TRANSLATE TO English system prompt at the beginning of the chat history, and it successfully translated the japanese news into english


When ctx window exceeded:

time=2025-01-22T22:21:59.395+08:00 level=DEBUG source=prompt.go:77 msg="truncating input messages which exceed context length" truncated=2
time=2025-01-22T22:21:59.395+08:00 level=DEBUG source=routes.go:1470 msg="chat request" images=0 prompt="<|im_start|>user\nタレントの中居正広が起こした女性トラブルは、フジテレビを巻き込んだ大騒動に発展している。事を重く見た各局は、次々と中 居が出演の番組の打ち切りや降板を発表している。\n\n中居といえば、優れたトーク力で多くのレギュラー番組やCMを抱えていたが、単発の仕事を含めてすべてを失うことになりそうだ。1月21日には、長年続けてきた冠ラジオ番組『ON&ON AIR』も、放送30周年を目 前にして終了が発表された。その“仕事剥奪”の流れは今後も続きそうだ。\n\n中居がもっとも残念���っているのが、大好きな野球関連の仕事からの撤退だという。自ら「(侍ジャパン)日本代表の仕事はルーティン」と語るだけあって、思い入れは相当なものだった。\n\n「中居さんは、2009年に開催された『第2回ワールド・ベースボール・クラシック(WBC)』で『テレビ朝日WBC日本代表サポート キャプテン』に就任。ここから侍ジャパン関連の仕事は、まさに中居さんの独占状態でした。\n\n続く『第3回WBC』では『侍ジャパン公認サポーター』に。さらに2017年の『第4回WBC』では『侍ジャパン公認サポートキャプテン』に指名されました。次々と名称を変えながら、野球仕事を続けてきたのです」(芸能記者)\n\n記憶に新しい2023年の『第5回WBC』でも同職を務め、第2回以来となる歓喜 の瞬間をナインとともに味わった。中居の侍ジャパンへの想いは、本物だったようだ。\n\n「試合だけでなく、大会ごとに行われた宮崎での合宿にも足を運んでいましたからね。合宿には中居さん以外のタレントが顔を出すこともありましたが、そのほとんどが練習を真剣に見るわけではありませんでした。もっぱら、関係者との談笑に時間を費やしていたんです。退屈すると、すぐに喫煙所に“逃げ る”人も多くいました。\n\n宮崎合宿で中居さんと遭遇したことがありますが、関係者と話し込むことはあっても、視線は常にグラウ ンド、選手に向けられていましたからね。それだけでなく、気になることがあればすぐさまメモ帳を取り出して書き込む。他のタレントとは、まさに一線を画していました」(スポーツ記者)\n\n中居といえば、選手との交友関係が広いことでも有名だ。それというのも、中居の野球に向き合う“本気姿勢”ゆえのことだったようだ。\n\n「練習を真剣に見てメモを取るなど、中居の本気度は選手にも知られていて認められる存在でした。事前にも勉強しているからでしょうか、選手への取材も、他のタレントとは違って的を射たものが多かったんです。\n\nしかし、一連の騒動で状況一変。なかには『野球のイメージが悪くなるから合宿や試合に来ないでほしい』ということを言う選手すらいるほどです。\n\n今年の3月5~6日には京セラドームで『ラグザス 侍ジャパンシリーズ2025』が行われます。来年連覇がかかる『第6回WBC』に向けた強化試合です。本来なら、中居さんは“公認キャプテン”として現場に行く予定でしたが、出演は絶望的です。\n\n両試合はTBS系とテレビ朝日系が担当しますが、いずれもゴールデンタイムの時間帯なのでスポンサーも多い。も し中居さんが出演となれば、スポンサーが降りる可能性が高いですからね……」(スポーツ紙デスク)\n\n中居が長年積み上げてきた努力も水泡に帰してしまうのか……。\n\nアーセナルはサカの負傷離脱を受け、現地メディアから三笘薫の名前も\nイングランド1部アー セナルは英代表FWブカヨ・サカの負傷離脱を受けて、冬の移籍市場で前線の補強が噂されている。ウォルバーハンプトンのブラジル代表FWマティアス・クーニャの獲得に動くとも伝えられていたなか、現地メディアでは「クーニャの代わりにミトマをターゲットにすべき」と日本代表MF三笘薫(ブライトン)の名前が取り上げられていた。\n\nウルブスでプレーする25歳のクーニャは今季プレミアリーグで21試合10ゴール4アシストを記録。アーセナルはハムストリングの負傷で離���しているサカに代わるアタッカーとしてこのクーニ ャに関心を寄せていると報じられていた。\n\nそうしたなかで、アーセナル専門メディアの「Arsenal Insider」は「(ウルブスが) このブラジル人選手に高額の移籍金を要求する可能性が高いため、アーセナルは他のFWを探す必要がある」とクーニャの獲得の可能性について否定的に伝えた。そのうえで「アーセナルはクーニャの代わりに三笘をターゲットにすべきだ」と持論を展開した。なお、英メディア「Caughtoffside」では、ウルブスは7000万ポンド(約134億円)以上のオファーでなければ受け入れないが、アーセナルは4500万ポンド(約86億円)以上を支払う用意はないと伝えられていた。\n\n「Arsenal insider」は三笘について「27歳でキャリアの全 盛期で、プレミアリーグで実力を証明してきた」と紹介。過去にもアーセナルからの関心が伝えられてきたとしたうえで、「三笘のドリブル能力、ボックス内でDFを切り離す力、そしてチャンスを作る力は、サカの不在を埋めることができる」とその能力の高さを絶賛していた。\n\nブライトンは三笘の移籍に対して高額の移籍金を要求することになるはずだが、クーニャの移籍金に比べれば比較的安く抑えられると見られる。シーズン途中の移籍のハードルは高いが、アーセナルにとって三笘が魅力なターゲットであることは間違いなさそうだ。(FOOTBALL ZONE編集部)\n\n\u3000リバプールとバルセロナがソシエダのMF久保建英に強い関心を寄せているようだ。 同じく両クラブが獲得ターゲットとしてきたチームメイトのMFマルティン・スビメンディよりも優先順位が高いと、バルセロナ専門メディア『カルペタスFCB』が報じている。\n\n\u3000久保を巡っては、以前からFWモハメド・サラーの後釜を探すリバプールが狙って いるとされてきた。クラブはソシエダとの取り引きを成立させるため、FWフェデリコ・キエーザやMF遠藤航といった選手を交渉に含めることも検討しているいう。\n\n\u3000同メディアは「このソシエダ選手はスピード、試合を動かす能力、ゴールセンスにより、リバプールが求めるプロファイルに完璧に合致している」と久保を評価し、プレミアリーグでのプレーに太鼓判を押している。\n\n\u3000久保がアカデミー時代に在籍したバルセロナについては「新たな攻撃オプションを必要としているクラブは、この選手に目をつけている。ジョアン・ラポルタ会長とハンジ・フリック監督は、この選手がチームに多様性とクオリティーをもたらす絶好の機会だと見ている」と紹介。ただし、ここ数年は財政的な問題を抱えており、「リバプールのオファーと競争するには、分割払いの活用や選手を含めるなど、創造的な手段を模索する必要がある」と指摘した。\n\n\u3000一方で、ソシエダが久保に6000万ユーロ(約97億円)の契約解除条項を設定していることを挙げ、「この選手はプロジェクトの重要な一部であり、彼の退団はソシエダにとって多大な損失となる」と、簡単に手放す気がないとも伝えている。\n\n\u3000ソシエダで充実の時を過ごし、今季も大きなインパクトを与えている久保。同メディアは「リバプールは経済的安定とスタメンでの重要な役割を提供し、バルセロナは彼の才能を引き出せるプレースタイルとの親和性を訴求している」とした上で、「バルセロナとリバプールは、それぞれの戦略を洗練させて久保を説得する必要がある。この物語の結末は、移籍市場で最も注目される瞬間の一つとなるに違いない」と述べた。\n\n韓国の至宝への酷評に、母国メディアが怒りを露わにした。\n\nフランス王者パリ・サンジェルマンは現地1月18日のリーグ・アン第19節で、RCランスと敵地で対戦。2-1で勝利を収めた。\n\nこの試合に先発し、60分までプレーしたパリSGの韓国代表MFイ・ガンインについて、一部のフランスメディアが厳しい評価をしたようだ。\n\n韓国メディア『スポーツ朝鮮』は「『イ・ガンインが嫌い』フランスメディアの悪質な評価、イ・ガンイン蔑視は深刻だ」と題した記事を掲載。「客観的な基準であるべき評価が感情をぶちまける道具になっている。ここまでくると『私はイ・ガンインが嫌い』との評価を書いているようなものだ」と不満を露わにした。\n\n「一部のフランスメディアの、『イ・ガンインの信用を落とす』行為は度を超えている。今回はフットメルカートだ。他のメディアやデータ会社がイ・ガンインに中程度の評価を与えた。ところが、『フットメルカート』はイ・ガンインにわずか4点という衝撃の評価だった。10点満点中4点は落第点だ。実際、PSG選手の 中で最低点だった」\n\n【画像】“世界一美しいフットボーラー”に認定されたクロアチア女子代表FWの厳選ショット\n\n同メディアは、昨年12月のチャンピオンズリーグでも、『フットメルカート』が「イ・ガンインが技術的な資質を持っていることは間違いないが、ボールに対して慎重すぎた。リスクを冒さずに後方からプレーすることが多く、時には試合のペースを落とすこともあったのは残念だ」と、今回と同様の評価をしたと指摘。こう糾弾している。\n\n「一貫している。イ・ガンインのプレーに非常に不満を抱いていることが分かる。採点と解説をした担当編集者は嫌悪感を持つほどイ・ガンインを嫌っているようだ。あるいは、フットメルカート全体がイ・ガンインのプレースタイルを嫌っているか、存在そのものを否定したいのかもしれない」\n\n自国のスターへの扱いに納得ができないようだ。\n\n構成●サッカーダイジェストWeb編集部<|im_end|>\n<|im_start|>assistant\n"
time=2025-01-22T22:21:59.405+08:00 level=WARN source=runner.go:129 msg="truncating input prompt" limit=2048 prompt=2696 keep=4 new=2048
time=2025-01-22T22:21:59.405+08:00 level=DEBUG source=cache.go:104 msg="loading cache slot" id=0 cache=1695 prompt=2048 used=1 remaining=2047
time=2025-01-22T22:21:59.975+08:00 level=DEBUG source=cache.go:231 msg="context limit hit - shifting" id=0 limit=2048 input=2048 keep=4 discard=1022
[GIN] 2025/01/22 - 22:22:07 | 200 |     7.692824s |       127.0.0.1 | POST     "/api/chat"
time=2025-01-22T22:22:07.056+08:00 level=DEBUG source=sched.go:407 msg="context for request finished"

I strated a new round of conversion for this test, and as you can see, the chat history started with prompt="<|im_start|>user\nタレントの中居, there is no system prompt, and it just reply me bunch of japanese which I can't read


ollama serve command: (I'm using windows)

set OLLAMA_FLASH_ATTENTION=1 && set OLLAMA_KV_CACHE_TYPE=q8_0&& set OLLAMA_DEBUG=1 && ollama serve

ollama show translte-test (the model I used in this test)

  Model
    architecture        qwen2
    parameters          14.8B
    context length      32768
    embedding length    5120
    quantization        Q8_0

  System
    YOU ARE A PROFESSIONAL TRANSLATOR SKILLED IN ACCURATELY TRANSLATING TEXT BETWEEN LANGUAGES. YOUR
      TASK IS TO TRANSLATE WHILE PRESERVING THE ORIGINAL MEANING, TONE, INTENT, AND FORMATTING. DO NOT
      ALTER PARAGRAPH STRUCTURE, PUNCTUATION, OR FORMATTING. IF DIRECT TRANSLATION ISN’T POSSIBLE,
      PROVIDE THE BEST EQUIVALENT WHILE MAINTAINING THE ORIGINAL MESSAGE. YOU HAVE NO OUTPUT LENGTH LIMIT.
      BY DEFAULT, TRANSLATE TO English.

  License
    Apache License
    Version 2.0, January 2004

@rick-github

<!-- gh-comment-id:2607408095 --> @vYLQs6 commented on GitHub (Jan 22, 2025): Okay, **this time I tested this using ollama CLI interface** instead of open webui, just to make sure it's not webui doing anything weird And the result is the same, ollama just throw away system prompt when context window was exceeded Here is the chat history: --- ### Normal behavior: ``` llama_model_load: vocab only - skipping tensors time=2025-01-22T22:20:56.458+08:00 level=DEBUG source=routes.go:1470 msg="chat request" images=0 prompt="<|im_start|>system\nYOU ARE A PROFESSIONAL TRANSLATOR SKILLED IN ACCURATELY TRANSLATING TEXT BETWEEN LANGUAGES. YOUR TASK IS TO TRANSLATE WHILE PRESERVING THE ORIGINAL MEANING, TONE, INTENT, AND FORMATTING. DO NOT ALTER PARAGRAPH STRUCTURE, PUNCTUATION, OR FORMATTING. IF DIRECT TRANSLATION ISN’T POSSIBLE, PROVIDE THE BEST EQUIVALENT WHILE MAINTAINING THE ORIGINAL MESSAGE. YOU HAVE NO OUTPUT LENGTH LIMIT. BY DEFAULT, TRANSLATE TO English.<|im_end|>\n<|im_start|>user\nタレントの中居正広が起こした女性トラブルは、フジテレビを巻き込んだ大騒動に発展している。事を重く見た各局は、次々と中居が出演の番組の打ち切りや降板を発表している。\n\n中居といえば、優れたトーク力で多くのレギュラー番組やCMを抱えていたが、単発の仕事を含めてすべてを失うことになりそうだ。1月21日には、長年続けてきた冠ラジオ番組『ON&ON AIR』も、放送30周年を目前にして終了が発表された。そ の“仕事剥奪”の流れは今後も続きそうだ。\n\n中居がもっとも残念がっているのが、大好きな野球関連の仕事からの撤退だという。自ら「(侍ジャパン)日本代表の仕事はルーティン」と語るだけあって、思い入れは相当なものだった。\n\n「中居さんは、2009年に開催された『第2回ワールド・ベースボール・クラシック(WBC)』で『テレビ朝日WBC日本代表サポートキャプテン』に就任。ここから 侍ジャパン関連の仕事は、まさに中居さんの独占状態でした。\n\n続く『第3回WBC』では『侍ジャパン公認サポーター』に。さらに2017年の『第4回WBC』では『侍ジャパン公認サポートキャプテン』に指名されました。次々と名称を変えながら、野球仕事を続けてきたのです」(芸能記者)\n\n記憶に新しい2023年の『第5回WBC』でも同職を務め、第2回以来となる歓喜の瞬間をナインとともに味わっ た。中居の侍ジャパンへの想いは、本物だったようだ。\n\n「試合だけでなく、大会ごとに行われた宮崎での合宿にも足を運んでいましたからね。合宿には中居さん以外のタレントが顔を出すこともありましたが、そのほとんどが練習を真剣に見るわけではありませんでした。もっぱら、関係者との談笑に時間を費やしていたんです。退屈すると、すぐに喫煙所に“逃げる”人も多くいました。\n\n宮崎合宿で中居さんと遭遇したことがありますが、関係者と話し込むことはあっても、視線は常にグラウンド、選手に向けられていましたからね。それだけでなく、気になることがあればすぐさまメモ帳を取り出して書き込む。他のタレントとは、まさに一線を画していました」(スポーツ記者)\n\n中居といえば、選手との交友関係が広いことでも有名だ。それというのも、中居の野球に向き合う“本気 姿勢”ゆえのことだったようだ。\n\n「練習を真剣に見てメモを取るなど、中居の本気度は選手にも知られていて認められる存在でし た。事前にも勉強しているからでしょうか、選手への取材も、他のタレントとは違って的を射たものが多かったんです。\n\nしかし、一連の騒動で状況一変。なかには『野球のイメージが悪くなるから合宿や試合に来ないでほしい』ということを言う選手すらいるほどです。\n\n今年の3月5~6日には京セラドームで『ラグザス 侍ジャパンシリーズ2025』が行われます。来年連覇がかかる『第6回WBC』に向けた強化試合です。本来なら、中居さんは“公認キャプテン”として現場に行く予定でしたが、出演は絶望的です。\n\n両試合はTBS系とテレビ朝日系が担当しますが、いずれもゴールデンタイムの時間帯なのでスポンサーも多い。もし中居さんが出演となれば、ス ポンサーが降りる可能性が高いですからね……」(スポーツ紙デスク)\n\n中居が長年積み上げてきた努力も水泡に帰してしまうのか……。<|im_end|>\n<|im_start|>assistant\n" time=2025-01-22T22:20:56.464+08:00 level=DEBUG source=cache.go:104 msg="loading cache slot" id=0 cache=0 prompt=1039 used=0 remaining=1039 [GIN] 2025/01/22 - 22:21:10 | 200 | 14.1750906s | 127.0.0.1 | POST "/api/chat" time=2025-01-22T22:21:10.419+08:00 level=DEBUG source=sched.go:407 msg="context for request finished" time=2025-01-22T22:21:10.419+08:00 level=DEBUG source=sched.go:339 msg="runner with non-zero duration has gone idle, adding timer" modelPath=D:\LLM\.ollama\models\blobs\sha256-b2c12d46c1eec7e6536b759f1b6d5f98e254ade8a25c293f0fc01cce9489af69 duration=5m0s time=2025-01-22T22:21:10.419+08:00 level=DEBUG source=sched.go:357 msg="after processing request finished event" modelPath=D:\LLM\.ollama\models\blobs\sha256-b2c12d46c1eec7e6536b759f1b6d5f98e254ade8a25c293f0fc01cce9489af69 refCount=0 [GIN] 2025/01/22 - 22:21:53 | 200 | 0s | 127.0.0.1 | HEAD "/" [GIN] 2025/01/22 - 22:21:53 | 200 | 22.3404ms | 127.0.0.1 | POST "/api/show" time=2025-01-22T22:21:53.958+08:00 level=DEBUG source=sched.go:575 msg="evaluating already loaded" model=D:\LLM\.ollama\models\blobs\sha256-b2c12d46c1eec7e6536b759f1b6d5f98e254ade8a25c293f0fc01cce9489af69 [GIN] 2025/01/22 - 22:21:53 | 200 | 22.8907ms | 127.0.0.1 | POST "/api/generate" time=2025-01-22T22:21:53.960+08:00 level=DEBUG source=sched.go:407 msg="context for request finished" ``` As you can see there are the `YOU ARE A PROFESSIONAL TRANSLATOR ... BY DEFAULT, TRANSLATE TO English` system prompt at the beginning of the chat history, and it successfully translated the japanese news into english --- ### When ctx window exceeded: ``` time=2025-01-22T22:21:59.395+08:00 level=DEBUG source=prompt.go:77 msg="truncating input messages which exceed context length" truncated=2 time=2025-01-22T22:21:59.395+08:00 level=DEBUG source=routes.go:1470 msg="chat request" images=0 prompt="<|im_start|>user\nタレントの中居正広が起こした女性トラブルは、フジテレビを巻き込んだ大騒動に発展している。事を重く見た各局は、次々と中 居が出演の番組の打ち切りや降板を発表している。\n\n中居といえば、優れたトーク力で多くのレギュラー番組やCMを抱えていたが、単発の仕事を含めてすべてを失うことになりそうだ。1月21日には、長年続けてきた冠ラジオ番組『ON&ON AIR』も、放送30周年を目 前にして終了が発表された。その“仕事剥奪”の流れは今後も続きそうだ。\n\n中居がもっとも残念���っているのが、大好きな野球関連の仕事からの撤退だという。自ら「(侍ジャパン)日本代表の仕事はルーティン」と語るだけあって、思い入れは相当なものだった。\n\n「中居さんは、2009年に開催された『第2回ワールド・ベースボール・クラシック(WBC)』で『テレビ朝日WBC日本代表サポート キャプテン』に就任。ここから侍ジャパン関連の仕事は、まさに中居さんの独占状態でした。\n\n続く『第3回WBC』では『侍ジャパン公認サポーター』に。さらに2017年の『第4回WBC』では『侍ジャパン公認サポートキャプテン』に指名されました。次々と名称を変えながら、野球仕事を続けてきたのです」(芸能記者)\n\n記憶に新しい2023年の『第5回WBC』でも同職を務め、第2回以来となる歓喜 の瞬間をナインとともに味わった。中居の侍ジャパンへの想いは、本物だったようだ。\n\n「試合だけでなく、大会ごとに行われた宮崎での合宿にも足を運んでいましたからね。合宿には中居さん以外のタレントが顔を出すこともありましたが、そのほとんどが練習を真剣に見るわけではありませんでした。もっぱら、関係者との談笑に時間を費やしていたんです。退屈すると、すぐに喫煙所に“逃げ る”人も多くいました。\n\n宮崎合宿で中居さんと遭遇したことがありますが、関係者と話し込むことはあっても、視線は常にグラウ ンド、選手に向けられていましたからね。それだけでなく、気になることがあればすぐさまメモ帳を取り出して書き込む。他のタレントとは、まさに一線を画していました」(スポーツ記者)\n\n中居といえば、選手との交友関係が広いことでも有名だ。それというのも、中居の野球に向き合う“本気姿勢”ゆえのことだったようだ。\n\n「練習を真剣に見てメモを取るなど、中居の本気度は選手にも知られていて認められる存在でした。事前にも勉強しているからでしょうか、選手への取材も、他のタレントとは違って的を射たものが多かったんです。\n\nしかし、一連の騒動で状況一変。なかには『野球のイメージが悪くなるから合宿や試合に来ないでほしい』ということを言う選手すらいるほどです。\n\n今年の3月5~6日には京セラドームで『ラグザス 侍ジャパンシリーズ2025』が行われます。来年連覇がかかる『第6回WBC』に向けた強化試合です。本来なら、中居さんは“公認キャプテン”として現場に行く予定でしたが、出演は絶望的です。\n\n両試合はTBS系とテレビ朝日系が担当しますが、いずれもゴールデンタイムの時間帯なのでスポンサーも多い。も し中居さんが出演となれば、スポンサーが降りる可能性が高いですからね……」(スポーツ紙デスク)\n\n中居が長年積み上げてきた努力も水泡に帰してしまうのか……。\n\nアーセナルはサカの負傷離脱を受け、現地メディアから三笘薫の名前も\nイングランド1部アー セナルは英代表FWブカヨ・サカの負傷離脱を受けて、冬の移籍市場で前線の補強が噂されている。ウォルバーハンプトンのブラジル代表FWマティアス・クーニャの獲得に動くとも伝えられていたなか、現地メディアでは「クーニャの代わりにミトマをターゲットにすべき」と日本代表MF三笘薫(ブライトン)の名前が取り上げられていた。\n\nウルブスでプレーする25歳のクーニャは今季プレミアリーグで21試合10ゴール4アシストを記録。アーセナルはハムストリングの負傷で離���しているサカに代わるアタッカーとしてこのクーニ ャに関心を寄せていると報じられていた。\n\nそうしたなかで、アーセナル専門メディアの「Arsenal Insider」は「(ウルブスが) このブラジル人選手に高額の移籍金を要求する可能性が高いため、アーセナルは他のFWを探す必要がある」とクーニャの獲得の可能性について否定的に伝えた。そのうえで「アーセナルはクーニャの代わりに三笘をターゲットにすべきだ」と持論を展開した。なお、英メディア「Caughtoffside」では、ウルブスは7000万ポンド(約134億円)以上のオファーでなければ受け入れないが、アーセナルは4500万ポンド(約86億円)以上を支払う用意はないと伝えられていた。\n\n「Arsenal insider」は三笘について「27歳でキャリアの全 盛期で、プレミアリーグで実力を証明してきた」と紹介。過去にもアーセナルからの関心が伝えられてきたとしたうえで、「三笘のドリブル能力、ボックス内でDFを切り離す力、そしてチャンスを作る力は、サカの不在を埋めることができる」とその能力の高さを絶賛していた。\n\nブライトンは三笘の移籍に対して高額の移籍金を要求することになるはずだが、クーニャの移籍金に比べれば比較的安く抑えられると見られる。シーズン途中の移籍のハードルは高いが、アーセナルにとって三笘が魅力なターゲットであることは間違いなさそうだ。(FOOTBALL ZONE編集部)\n\n\u3000リバプールとバルセロナがソシエダのMF久保建英に強い関心を寄せているようだ。 同じく両クラブが獲得ターゲットとしてきたチームメイトのMFマルティン・スビメンディよりも優先順位が高いと、バルセロナ専門メディア『カルペタスFCB』が報じている。\n\n\u3000久保を巡っては、以前からFWモハメド・サラーの後釜を探すリバプールが狙って いるとされてきた。クラブはソシエダとの取り引きを成立させるため、FWフェデリコ・キエーザやMF遠藤航といった選手を交渉に含めることも検討しているいう。\n\n\u3000同メディアは「このソシエダ選手はスピード、試合を動かす能力、ゴールセンスにより、リバプールが求めるプロファイルに完璧に合致している」と久保を評価し、プレミアリーグでのプレーに太鼓判を押している。\n\n\u3000久保がアカデミー時代に在籍したバルセロナについては「新たな攻撃オプションを必要としているクラブは、この選手に目をつけている。ジョアン・ラポルタ会長とハンジ・フリック監督は、この選手がチームに多様性とクオリティーをもたらす絶好の機会だと見ている」と紹介。ただし、ここ数年は財政的な問題を抱えており、「リバプールのオファーと競争するには、分割払いの活用や選手を含めるなど、創造的な手段を模索する必要がある」と指摘した。\n\n\u3000一方で、ソシエダが久保に6000万ユーロ(約97億円)の契約解除条項を設定していることを挙げ、「この選手はプロジェクトの重要な一部であり、彼の退団はソシエダにとって多大な損失となる」と、簡単に手放す気がないとも伝えている。\n\n\u3000ソシエダで充実の時を過ごし、今季も大きなインパクトを与えている久保。同メディアは「リバプールは経済的安定とスタメンでの重要な役割を提供し、バルセロナは彼の才能を引き出せるプレースタイルとの親和性を訴求している」とした上で、「バルセロナとリバプールは、それぞれの戦略を洗練させて久保を説得する必要がある。この物語の結末は、移籍市場で最も注目される瞬間の一つとなるに違いない」と述べた。\n\n韓国の至宝への酷評に、母国メディアが怒りを露わにした。\n\nフランス王者パリ・サンジェルマンは現地1月18日のリーグ・アン第19節で、RCランスと敵地で対戦。2-1で勝利を収めた。\n\nこの試合に先発し、60分までプレーしたパリSGの韓国代表MFイ・ガンインについて、一部のフランスメディアが厳しい評価をしたようだ。\n\n韓国メディア『スポーツ朝鮮』は「『イ・ガンインが嫌い』フランスメディアの悪質な評価、イ・ガンイン蔑視は深刻だ」と題した記事を掲載。「客観的な基準であるべき評価が感情をぶちまける道具になっている。ここまでくると『私はイ・ガンインが嫌い』との評価を書いているようなものだ」と不満を露わにした。\n\n「一部のフランスメディアの、『イ・ガンインの信用を落とす』行為は度を超えている。今回はフットメルカートだ。他のメディアやデータ会社がイ・ガンインに中程度の評価を与えた。ところが、『フットメルカート』はイ・ガンインにわずか4点という衝撃の評価だった。10点満点中4点は落第点だ。実際、PSG選手の 中で最低点だった」\n\n【画像】“世界一美しいフットボーラー”に認定されたクロアチア女子代表FWの厳選ショット\n\n同メディアは、昨年12月のチャンピオンズリーグでも、『フットメルカート』が「イ・ガンインが技術的な資質を持っていることは間違いないが、ボールに対して慎重すぎた。リスクを冒さずに後方からプレーすることが多く、時には試合のペースを落とすこともあったのは残念だ」と、今回と同様の評価をしたと指摘。こう糾弾している。\n\n「一貫している。イ・ガンインのプレーに非常に不満を抱いていることが分かる。採点と解説をした担当編集者は嫌悪感を持つほどイ・ガンインを嫌っているようだ。あるいは、フットメルカート全体がイ・ガンインのプレースタイルを嫌っているか、存在そのものを否定したいのかもしれない」\n\n自国のスターへの扱いに納得ができないようだ。\n\n構成●サッカーダイジェストWeb編集部<|im_end|>\n<|im_start|>assistant\n" time=2025-01-22T22:21:59.405+08:00 level=WARN source=runner.go:129 msg="truncating input prompt" limit=2048 prompt=2696 keep=4 new=2048 time=2025-01-22T22:21:59.405+08:00 level=DEBUG source=cache.go:104 msg="loading cache slot" id=0 cache=1695 prompt=2048 used=1 remaining=2047 time=2025-01-22T22:21:59.975+08:00 level=DEBUG source=cache.go:231 msg="context limit hit - shifting" id=0 limit=2048 input=2048 keep=4 discard=1022 [GIN] 2025/01/22 - 22:22:07 | 200 | 7.692824s | 127.0.0.1 | POST "/api/chat" time=2025-01-22T22:22:07.056+08:00 level=DEBUG source=sched.go:407 msg="context for request finished" ``` I strated a new round of conversion for this test, and as you can see, the chat history started with `prompt="<|im_start|>user\nタレントの中居`, there is no system prompt, and it just reply me bunch of japanese which I can't read --- ollama serve command: (I'm using windows) ``` set OLLAMA_FLASH_ATTENTION=1 && set OLLAMA_KV_CACHE_TYPE=q8_0&& set OLLAMA_DEBUG=1 && ollama serve ``` ollama show translte-test (the model I used in this test) ``` Model architecture qwen2 parameters 14.8B context length 32768 embedding length 5120 quantization Q8_0 System YOU ARE A PROFESSIONAL TRANSLATOR SKILLED IN ACCURATELY TRANSLATING TEXT BETWEEN LANGUAGES. YOUR TASK IS TO TRANSLATE WHILE PRESERVING THE ORIGINAL MEANING, TONE, INTENT, AND FORMATTING. DO NOT ALTER PARAGRAPH STRUCTURE, PUNCTUATION, OR FORMATTING. IF DIRECT TRANSLATION ISN’T POSSIBLE, PROVIDE THE BEST EQUIVALENT WHILE MAINTAINING THE ORIGINAL MESSAGE. YOU HAVE NO OUTPUT LENGTH LIMIT. BY DEFAULT, TRANSLATE TO English. License Apache License Version 2.0, January 2004 ``` @rick-github
Author
Owner

@vYLQs6 commented on GitHub (Jan 22, 2025):

I also tried this with Q8 KV Cache & Flash attention disabled

set OLLAMA_DEBUG=1 && ollama serve

It's the same behavior, ollama just throw away system prompt

llama_model_load: vocab only - skipping tensors
time=2025-01-22T22:37:41.398+08:00 level=DEBUG source=prompt.go:77 msg="truncating input messages which exceed context length" truncated=2
time=2025-01-22T22:37:41.398+08:00 level=DEBUG source=routes.go:1470 msg="chat request" images=0 prompt="<|im_start|>user\nタレントの中居正広.....
<!-- gh-comment-id:2607425925 --> @vYLQs6 commented on GitHub (Jan 22, 2025): I also tried this with Q8 KV Cache & Flash attention disabled `set OLLAMA_DEBUG=1 && ollama serve` It's the same behavior, ollama just throw away system prompt ``` llama_model_load: vocab only - skipping tensors time=2025-01-22T22:37:41.398+08:00 level=DEBUG source=prompt.go:77 msg="truncating input messages which exceed context length" truncated=2 time=2025-01-22T22:37:41.398+08:00 level=DEBUG source=routes.go:1470 msg="chat request" images=0 prompt="<|im_start|>user\nタレントの中居正広..... ```
Author
Owner

@rick-github commented on GitHub (Jan 22, 2025):

You are sending one big chunk of text which is bigger than the context window. ollama does it best to minimize size while maintaining message integrity. It tries to maintain the system message and user/assistant messages, but at the end of the day, something has to give - the system prompt is discarded because there's no point in sending a system if there's no user message.

You either have to increase context size or pass in the user message as a sequence of messages that ollama can prune if necessary. To expand from my earlier example, if we ask the model to translate something in a block of text which exceeds context:

$ curl -s localhost:11434/api/chat -d '{
  "model":"qwen2.5:0.5b",
  "messages":[
    {"role":"system","content":"translate the following content to german"},
    {"role":"user","content":"goodbye and to all the ships at sea, goodnight\nnow is the time for all good men to come to the aid of the party\nthe quick brown fox jumps over the lazy dog"}
  ],"options":{"num_ctx":50}'
$ printf "$(docker compose logs ollama | sed -ne 's/.*"chat request"[^"]*"\(.*\).$/\1/p' | tail -1)"'\n'
<|im_start|>user
goodbye and to all the ships at sea, goodnight
now is the time for all good men to come to the aid of the party
the quick brown fox jumps over the lazy dog<|im_end|>
<|im_start|>assistant

We see that it kept the user message but discarded the system message.

If we split the user message up:

$ curl -s localhost:11434/api/chat -d '{
  "model":"qwen2.5:0.5b",
  "messages":[
    {"role":"system","content":"translate the following content to german"},
    {"role":"user","content":"goodbye and to all the ships at sea, goodnight"},
    {"role":"user","content":"now is the time for all good men to come to the aid of the party"},
    {"role":"user","content":"the quick brown fox jumps over the lazy dog"}
  ],"options":{"num_ctx":50}}'
$ printf "$(docker compose logs ollama | sed -ne 's/.*"chat request"[^"]*"\(.*\).$/\1/p' | tail -1)"'\n'
<|im_start|>system
translate the following content to german<|im_end|>
<|im_start|>user
now is the time for all good men to come to the aid of the party

the quick brown fox jumps over the lazy dog<|im_end|>
<|im_start|>assistant

Here we see that ollama has dropped the first message and concatenated the rest (since they are all user) and this allows it to preserve the system message.

Note that you are likely to have other problems here because of your context limits. Your prompt says YOU HAVE NO OUTPUT LENGTH LIMIT and this is going to negatively impact performance if you are already dropping part of the input text due to context size constraints. The tokens generated by the LLM will also go into the context buffer, so if ollama had to drop a message to fit the initial prompt in the context buffer, the process of translating the text is going to exceed the context buffer, the runner will shift the contents to make room, and the head of the buffer will be lost. Realistically, you need to provision 2*input_length if you want the generated output to be coherent.

<!-- gh-comment-id:2607548743 --> @rick-github commented on GitHub (Jan 22, 2025): You are sending one big chunk of text which is bigger than the context window. ollama does it best to minimize size while maintaining message integrity. It tries to maintain the system message and user/assistant messages, but at the end of the day, something has to give - the system prompt is discarded because there's no point in sending a system if there's no user message. You either have to increase context size or pass in the user message as a sequence of messages that ollama can prune if necessary. To expand from my earlier example, if we ask the model to translate something in a block of text which exceeds context: ```console $ curl -s localhost:11434/api/chat -d '{ "model":"qwen2.5:0.5b", "messages":[ {"role":"system","content":"translate the following content to german"}, {"role":"user","content":"goodbye and to all the ships at sea, goodnight\nnow is the time for all good men to come to the aid of the party\nthe quick brown fox jumps over the lazy dog"} ],"options":{"num_ctx":50}' $ printf "$(docker compose logs ollama | sed -ne 's/.*"chat request"[^"]*"\(.*\).$/\1/p' | tail -1)"'\n' <|im_start|>user goodbye and to all the ships at sea, goodnight now is the time for all good men to come to the aid of the party the quick brown fox jumps over the lazy dog<|im_end|> <|im_start|>assistant ``` We see that it kept the user message but discarded the system message. If we split the user message up: ```console $ curl -s localhost:11434/api/chat -d '{ "model":"qwen2.5:0.5b", "messages":[ {"role":"system","content":"translate the following content to german"}, {"role":"user","content":"goodbye and to all the ships at sea, goodnight"}, {"role":"user","content":"now is the time for all good men to come to the aid of the party"}, {"role":"user","content":"the quick brown fox jumps over the lazy dog"} ],"options":{"num_ctx":50}}' $ printf "$(docker compose logs ollama | sed -ne 's/.*"chat request"[^"]*"\(.*\).$/\1/p' | tail -1)"'\n' <|im_start|>system translate the following content to german<|im_end|> <|im_start|>user now is the time for all good men to come to the aid of the party the quick brown fox jumps over the lazy dog<|im_end|> <|im_start|>assistant ``` Here we see that ollama has dropped the first message and concatenated the rest (since they are all `user`) and this allows it to preserve the system message. Note that you are likely to have other problems here because of your context limits. Your prompt says `YOU HAVE NO OUTPUT LENGTH LIMIT` and this is going to negatively impact performance if you are already dropping part of the input text due to context size constraints. The tokens generated by the LLM will also go into the context buffer, so if ollama had to drop a message to fit the initial prompt in the context buffer, the process of translating the text is going to exceed the context buffer, the runner will shift the contents to make room, and the head of the buffer will be lost. Realistically, you need to provision 2*input_length if you want the generated output to be coherent.
Author
Owner

@andyphua114 commented on GitHub (Jun 25, 2025):

Hi @rick-github , I was trying to examine how Ollama truncate the system prompt when it exceeds the context length. I have enabled verbose logging but I can't see the log on the input that is wrapped in special tokens - which should be something like msg="chat request". Do you have any idea why?

time=2025-06-25T15:47:25.990+08:00 level=DEBUG source=prompt.go:62 msg="truncating input messages which exceed context length" truncated=2
time=2025-06-25T15:47:25.990+08:00 level=DEBUG source=server.go:729 msg="completion request" images=0 prompt=205 format=""
time=2025-06-25T15:47:25.991+08:00 level=DEBUG source=cache.go:104 msg="loading cache slot" id=0 cache=0 prompt=47 used=0 remaining=47
time=2025-06-25T15:47:26.313+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:27.403+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:28.518+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:29.631+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:30.738+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:31.890+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:33.046+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:34.189+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:35.338+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:36.492+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:37.643+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:38.792+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:39.927+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:41.084+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:42.239+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:43.390+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:44.528+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:45.653+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:46.787+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:47.937+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:49.079+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
time=2025-06-25T15:47:50.235+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23
update: applying K-shift
[GIN] 2025/06/25 - 15:47:50 | 200 |   27.6824138s |       127.0.0.1 | POST     "/api/chat"
time=2025-06-25T15:47:50.887+08:00 level=DEBUG source=sched.go:503 msg="context for request finished"
<!-- gh-comment-id:3004235785 --> @andyphua114 commented on GitHub (Jun 25, 2025): Hi @rick-github , I was trying to examine how Ollama truncate the system prompt when it exceeds the context length. I have enabled verbose logging but I can't see the log on the input that is wrapped in special tokens - which should be something like `msg="chat request"`. Do you have any idea why? ``` time=2025-06-25T15:47:25.990+08:00 level=DEBUG source=prompt.go:62 msg="truncating input messages which exceed context length" truncated=2 time=2025-06-25T15:47:25.990+08:00 level=DEBUG source=server.go:729 msg="completion request" images=0 prompt=205 format="" time=2025-06-25T15:47:25.991+08:00 level=DEBUG source=cache.go:104 msg="loading cache slot" id=0 cache=0 prompt=47 used=0 remaining=47 time=2025-06-25T15:47:26.313+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:27.403+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:28.518+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:29.631+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:30.738+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:31.890+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:33.046+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:34.189+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:35.338+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:36.492+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:37.643+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:38.792+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:39.927+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:41.084+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:42.239+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:43.390+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:44.528+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:45.653+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:46.787+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:47.937+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:49.079+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift time=2025-06-25T15:47:50.235+08:00 level=DEBUG source=cache.go:240 msg="context limit hit - shifting" id=0 limit=50 input=50 keep=4 discard=23 update: applying K-shift [GIN] 2025/06/25 - 15:47:50 | 200 | 27.6824138s | 127.0.0.1 | POST "/api/chat" time=2025-06-25T15:47:50.887+08:00 level=DEBUG source=sched.go:503 msg="context for request finished" ```
Author
Owner

@rick-github commented on GitHub (Jun 25, 2025):

ollama 0.7.0+ has moved prompt logging to a higher level. Set OLLAMA_DEBUG=2 and search for "completion request" to see the prompt.

<!-- gh-comment-id:3004260760 --> @rick-github commented on GitHub (Jun 25, 2025): ollama 0.7.0+ has moved prompt logging to a higher level. Set `OLLAMA_DEBUG=2` and search for "completion request" to see the prompt.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#31262