mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #21733] [CLOSED] fix: deduplicate RAG content injection when builtin tools execute #65105
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/21733
Author: @Classic298
Created: 2/22/2026
Status: ❌ Closed
Base:
dev← Head:fix-rag📝 Commits (3)
ad9a98efix: deduplicate RAG content injection when builtin tools execute8b26b72Update middleware.py0460fa7Update middleware.py📊 Changes
1 file changed (+96 additions, -8 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+96 -8)📄 Description
Fixes: https://github.com/open-webui/open-webui/issues/21726
fix: deduplicate RAG content injection when builtin tools execute
When builtin tools (view_knowledge_file, query_knowledge_files, search_web, fetch_url) execute during a chat, the model receives the same content multiple times:
The fix addresses duplication via two mechanisms while preserving both citation functionality and agentic tool compatibility:
Reference-only RAG injection: After a tool call, the post-tool RAG source tags carry only the source ID and name for citation mapping, not the full content (which is already in the tool result message). This preserves the [1], [2] citation format while avoiding content duplication.
Source deduplication: After the initial RAG pass (when file context is enabled), all injected source/file IDs are tracked. When tools return citation sources already present from the initial pass, they are filtered out before post-tool RAG injection. Newly injected sources are tracked for subsequent tool call rounds.
Additionally, the repeated inline list of citation tool names is extracted into a module-level CITATION_TOOL_NAMES constant, and the repeated source ID collection logic is extracted into a collect_source_ids helper function.
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.