mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[GH-ISSUE #24076] issue: RAG template: duplicate {{CONTEXT}} / [context] placeholders inject retrieved context multiple times without warning
#35705
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?
Originally created by @KingsleyOWO on GitHub (Apr 24, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/24076
Check Existing Issues
Installation Method
Docker
Open WebUI Version
v0.9.0
Ollama Version (if applicable)
No response
Operating System
Ubuntu 24.04
Browser (if applicable)
No response
Confirmation
README.md.Expected Behavior
When a RAG template contains more than one context placeholder, OpenWebUI should warn that retrieved context will be injected once per placeholder.
Acceptable fixes could include either:
rag_template()when the rendered template hascontext_count > 1, or[context]/{{CONTEXT}}placeholders.The warning should not block saving and should not change existing behavior, because some users may intentionally duplicate context placeholders.
Actual Behavior
A template with duplicate context placeholders injects the full retrieved context multiple times silently.
There is already a debug warning when no context placeholder exists:
However, there is no corresponding warning when more than one context placeholder exists. The missing-placeholder case and duplicate-placeholder case are both easy-to-miss RAG-template failure modes, but only the missing-placeholder case currently emits a signal.
Steps to Reproduce
{{CONTEXT}}twice:rag_template().Minimal substitution-only reproducer:
The OpenWebUI code path does the same kind of global replacement for both
[context]and{{CONTEXT}}.Logs & Screenshots
No browser-console error is expected for this issue. This is a rendered-prompt/template-expansion behavior, not a frontend crash.
Browser console:
Container / backend logs:
Minimal rendered-output evidence:
Template:
Context:
Rendered result:
This is consistent with the current
rag_template()substitution path, which uses:without a
countargument.Token-accounting reproduction from my environment:
{{CONTEXT}}{{CONTEXT}}o200k_baseThe rendered prompt therefore contains one extra full copy of the retrieved context. The current UI/logs do not make this visible.
Additional Information
Related but not the same as existing RAG duplication reports:
view_knowledge_fileis used.This issue is narrower: a custom RAG template that itself contains duplicate
{{CONTEXT}}/[context]placeholders causes the retrieved context to be injected once per placeholder.I am not asking to change substitution semantics. Intentional duplicate placeholders should continue to work. I am only requesting warning/linting so that accidental duplication is visible.
Anecdotal observation, not part of the bug claim:
In one internal Traditional Chinese HR/policy RAG deployment, the duplicate-context template appeared to produce better answers than the default single-context template in a small manual comparison. In particular, it handled multi-clause policy distinctions more reliably.
However, I am not claiming this proves duplicate injection is generally beneficial. The comparison was not controlled enough: the custom template also differed in language, structure, citation guidance, and XML/code-fence formatting; the sample size was only n=2; and only one model family was tested.
This observation is included only to explain why a user might unknowingly keep a duplicate-context template in production: it may appear to improve answer quality while silently increasing prompt tokens. A warning would let users make that tradeoff intentionally.
@tjbck commented on GitHub (Apr 24, 2026):
Intended behaviour, duplication notice message added to dev.