mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-16 06:03:26 -05:00
[PR #20648] [CLOSED] feat: hybrid RAG context placement for KV cache optimization #129375
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/20648
Author: @Classic298
Created: 1/13/2026
Status: ❌ Closed
Base:
dev← Head:patch-2📝 Commits (3)
240c613Update middleware.py14d0556Update middleware.pyc6b3f2fUpdate middleware.py📊 Changes
1 file changed (+67 additions, -25 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+67 -25)📄 Description
feat: hybrid RAG context placement for KV cache optimization
PR Description
Summary
Implements hybrid placement of RAG context to optimize KV prefix caching when RAG_SYSTEM_CONTEXT is enabled.
Problem
When RAG_SYSTEM_CONTEXT=True, ALL RAG content is placed in the system message. This breaks KV caching for chunked retrieval because per-query chunks change each turn, invalidating the cached prefix.
Solution
Separate sources by stability:
Changes
Backward Compatibility
When RAG_SYSTEM_CONTEXT=False: unchanged behavior (all sources → user message)
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.