mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #20317] [MERGED] fix: inject full context knowledge into system message for KV prefix caching #64421
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/20317
Author: @Classic298
Created: 1/1/2026
Status: ✅ Merged
Merged: 1/5/2026
Merged by: @tjbck
Base:
dev← Head:kv-cache📝 Commits (5)
3247d82Update middleware.py0fef6e6Update middleware.pyecd9c73env var1e197b4address54e490cupd📊 Changes
2 files changed (+27 additions, -9 deletions)
View changed files
📝
backend/open_webui/env.py(+4 -0)📝
backend/open_webui/utils/middleware.py(+23 -9)📄 Description
PR Description
Summary
Fixes #20301 - Knowledge provided as "entire document" / "bypass embedding" is now injected into the system message instead of the last user message, enabling KV prefix caching to work correctly.
Problem
Previously, full document knowledge was always appended to the last user message. Since the user message changes every turn, the knowledge block constantly shifted positions in the prompt, invalidating the KV cache and forcing the model to re-process the entire document on every interaction.
Solution
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.