[GH-ISSUE #21167] issue: user message is duplicated for RAG queries #19409

Closed
opened 2026-04-20 01:51:44 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Simon-Stone on GitHub (Feb 4, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/21167

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!).
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

v0.7.2

Ollama Version (if applicable)

No response

Operating System

MacOS

Browser (if applicable)

No response

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

Expected Behavior

The fully rendered RAG template contains the user query at the end. The rendered template should therefore replace the user message.

Actual Behavior

The rendered RAG template is preprended to the user message, so the user message contents are repeated once inside the <user_query> tags and once at the end.

Steps to Reproduce

  • Upload a file
  • Send a message ("What is this?")
  • Inspect the final payload to find the user message duplicated

Logs & Screenshots

See #19098.

Additional Information

The duplication of the user message after the RAG template is still an issue. I traced this through these two functions:

The RAG template is applied in apply_source_context_to_messages calling add_or_update_user_message():

6cd35b185d/backend/open_webui/utils/middleware.py (L808-L814)

I assume the programmer's attention was to overwrite the user message instead of appending to it when setting append=False. Howevere, that parameter only changes the order of original and new content:

6cd35b185d/backend/open_webui/utils/misc.py (L247-L260)

That's why the original user message still appears at the end, even though the rendered RAG template should replace it entirely.

Not sure what the original intention of append was, since it's undocumented. If it's current behavior is as intended, I would suggest adding a function replace_user_message similar to:

6cd35b185d/backend/open_webui/utils/misc.py (L263-L268)

Originally created by @Simon-Stone on GitHub (Feb 4, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/21167 ### Check Existing Issues - [x] I have searched for any existing and/or related issues. - [x] I have searched for any existing and/or related discussions. - [x] I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version v0.7.2 ### Ollama Version (if applicable) _No response_ ### Operating System MacOS ### Browser (if applicable) _No response_ ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have **provided every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### Expected Behavior The fully rendered RAG template contains the user query at the end. The rendered template should therefore replace the user message. ### Actual Behavior The rendered RAG template is preprended to the user message, so the user message contents are repeated once inside the <user_query> tags and once at the end. ### Steps to Reproduce - Upload a file - Send a message ("What is this?") - Inspect the final payload to find the user message duplicated ### Logs & Screenshots See #19098. ### Additional Information The duplication of the user message after the RAG template is still an issue. I traced this through these two functions: The RAG template is applied in `apply_source_context_to_messages` calling `add_or_update_user_message()`: https://github.com/open-webui/open-webui/blob/6cd35b185d5a18e9ff4d3fe0c6d1036e73b48073/backend/open_webui/utils/middleware.py#L808-L814 I assume the programmer's attention was to _overwrite_ the user message instead of _appending_ to it when setting `append=False`. Howevere, that parameter only changes the order of original and new content: https://github.com/open-webui/open-webui/blob/6cd35b185d5a18e9ff4d3fe0c6d1036e73b48073/backend/open_webui/utils/misc.py#L247-L260 That's why the original user message still appears at the end, even though the rendered RAG template should replace it entirely. Not sure what the original intention of `append` was, since it's undocumented. If it's current behavior is as intended, I would suggest adding a function `replace_user_message` similar to: https://github.com/open-webui/open-webui/blob/6cd35b185d5a18e9ff4d3fe0c6d1036e73b48073/backend/open_webui/utils/misc.py#L263-L268
GiteaMirror added the bug label 2026-04-20 01:51:44 -05:00
Author
Owner

@owui-terminator[bot] commented on GitHub (Feb 4, 2026):

🔍 Similar Issues Found

I found some existing issues that might be related to this one. Please check if any of these are duplicates or contain helpful solutions:

  1. #20661 issue: RAG threshold and chat file include bug
    by n4gY1 • Jan 14, 2026 • bug

  2. #20558 issue: RAG Knowledge file when modify/update, older data is available
    by n4gY1 • Jan 10, 2026 • bug

  3. #19098 issue: Prompt & context duplication when RAG template is used
    by matiboux • Nov 11, 2025 • bug

  4. #20033 issue: RAG not working when file uploaded through chat
    by abhishek-paradkar-sndk • Dec 18, 2025 • bug

  5. #19281 issue: RAG Template applied with "Bypass Embedding and Retrieval" enabled
    by lucyknada • Nov 19, 2025 • bug

Show 2 more related issues
  1. #19825 Image Generation and Web Search trigger on every message
    by bcnation • Dec 08, 2025 • bug

  2. #19752 issue: minor UI Bug: knowledge sharing
    by mahenning • Dec 04, 2025 • bug, confirmed issue


💡 Tips:

  • If this is a duplicate, please consider closing this issue and adding any additional details to the existing one
  • If you found a solution in any of these issues, please share it here to help others

This comment was generated automatically by a bot. Please react with a 👍 if this comment was helpful, or a 👎 if it was not.

<!-- gh-comment-id:3849669350 --> @owui-terminator[bot] commented on GitHub (Feb 4, 2026): 🔍 **Similar Issues Found** I found some existing issues that might be related to this one. Please check if any of these are duplicates or contain helpful solutions: 1. [#20661](https://github.com/open-webui/open-webui/issues/20661) **issue: RAG threshold and chat file include bug** *by n4gY1 • Jan 14, 2026 • `bug`* 2. [#20558](https://github.com/open-webui/open-webui/issues/20558) **issue: RAG Knowledge file when modify/update, older data is available** *by n4gY1 • Jan 10, 2026 • `bug`* 3. [#19098](https://github.com/open-webui/open-webui/issues/19098) **issue: Prompt & context duplication when RAG template is used** *by matiboux • Nov 11, 2025 • `bug`* 4. [#20033](https://github.com/open-webui/open-webui/issues/20033) **issue: RAG not working when file uploaded through chat** *by abhishek-paradkar-sndk • Dec 18, 2025 • `bug`* 5. [#19281](https://github.com/open-webui/open-webui/issues/19281) **issue: RAG Template applied with "Bypass Embedding and Retrieval" enabled** *by lucyknada • Nov 19, 2025 • `bug`* <details> <summary>Show 2 more related issues</summary> 6. [#19825](https://github.com/open-webui/open-webui/issues/19825) **Image Generation and Web Search trigger on every message** *by bcnation • Dec 08, 2025 • `bug`* 7. [#19752](https://github.com/open-webui/open-webui/issues/19752) **issue: minor UI Bug: knowledge sharing** *by mahenning • Dec 04, 2025 • `bug`, `confirmed issue`* </details> --- 💡 **Tips:** - If this is a duplicate, please consider closing this issue and adding any additional details to the existing one - If you found a solution in any of these issues, please share it here to help others *This comment was generated automatically by a bot.* Please react with a 👍 if this comment was helpful, or a 👎 if it was not.
Author
Owner

@tjbck commented on GitHub (Feb 5, 2026):

You can edit/modify the template.

<!-- gh-comment-id:3855990036 --> @tjbck commented on GitHub (Feb 5, 2026): You can edit/modify the template.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#19409