[PR #22673] [CLOSED] fix: bypass RAG retrieval when all files are in full context mode #65663

Closed
opened 2026-05-06 11:34:01 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22673
Author: @a86582751
Created: 3/14/2026
Status: ❌ Closed

Base: main ← Head: fix-full-context-bypass-rag


📝 Commits (1)

  • 70fe715 fix: bypass RAG retrieval when all files are in full context mode

📊 Changes

1 file changed (+51 additions, -30 deletions)

View changed files

📝 backend/open_webui/utils/middleware.py (+51 -30)

📄 Description

Problem

When all uploaded files have context="full" (Full Context mode), the code was still:

  1. Generating queries (possibly empty)
  2. Calling get_sources_from_items with full_context=True
  3. Emitting queries_generated status

This caused unnecessary retrieval processing and UI delays even when users explicitly selected Full Context mode expecting direct file content injection without RAG.

Bug Manifestation / 具体表现形式

现象 1: "检索中"状态依然存在

用户操作: 在模型选项卡中勾选 "完整上下文" (Full Context),上传文档
预期行为: 直接传递文档内容,不经过 RAG
实际行为:

  • UI 仍然显示 "检索中..." (Retrieving...)
  • 显示 "搜索到 X 个引用来源"
  • 有明显的延迟感

现象 2: 角色扮演场景性能灾难

用户场景: 上传 50KB+ 的角色扮演剧情文档,让 AI 接着剧情继续
预期行为: AI 直接阅读完整文档,无缝衔接剧情
实际行为:

  • RAG 提取的片段破坏时间线连续性
  • AI "失忆"或混淆剧情顺序
  • 超过 3 轮对话后,因上下文过大导致卡死
  • 必须关闭 "将大文件粘贴为文本"选项,手动粘贴才能绕过

现象 3: 无法真正关闭 RAG

用户操作: 在设置 → 文档中勾选 "绕过嵌入和检索"
预期行为: 完全跳过 RAG,直接传递原始文件
实际行为:

  • 只要模型选项卡中勾选了 "文件上下文",就会触发 RAG
  • 取消勾选 "文件上下文" 后,模型完全收不到文件
  • 没有"直接传递文件内容"的选项

Root Cause

在 chat_completion_files_handler 中:

all_full_context = all(item.get("context") == "full" for item in files)

# 即使 all_full_context=True,仍会执行:
if not all_full_context:
    # 生成查询...
    
# 仍然调用检索流程
sources = await get_sources_from_items(
    ...,
    full_context=all_full_context,  # 只是传入参数,流程没变
)

Solution

When all_full_context is True:

  • Skip query generation entirely
  • Skip queries_generated status emission
  • Call get_sources_from_items with minimal parameters
  • Directly use file content without embedding/retrieval

Changes

  • Modified chat_completion_files_handler in backend/open_webui/utils/middleware.py
  • Split logic into two paths: all_full_context vs normal RAG
  • When all files are full context, bypass all retrieval-related processing

Testing

  • Upload files with Full Context mode enabled
  • Verify no "Retrieving..." status appears
  • Verify file content is directly injected into prompt
  • Verify normal RAG mode still works when not all files are full context

Related

Fixes the issue where 'Full Context' mode still triggered RAG processing, causing performance problems with large roleplay documents where time continuity is critical.


Signed-off-by: Pyrite Prof pyrite@example.com


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/22673 **Author:** [@a86582751](https://github.com/a86582751) **Created:** 3/14/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix-full-context-bypass-rag` --- ### 📝 Commits (1) - [`70fe715`](https://github.com/open-webui/open-webui/commit/70fe71572634b6e0263ab1823a05a0704e21d36c) fix: bypass RAG retrieval when all files are in full context mode ### 📊 Changes **1 file changed** (+51 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+51 -30) </details> ### 📄 Description ## Problem When all uploaded files have `context="full"` (Full Context mode), the code was still: 1. Generating queries (possibly empty) 2. Calling `get_sources_from_items` with `full_context=True` 3. Emitting `queries_generated` status This caused unnecessary retrieval processing and UI delays even when users explicitly selected **Full Context** mode expecting direct file content injection without RAG. ## Bug Manifestation / 具体表现形式 ### 现象 1: "检索中"状态依然存在 **用户操作**: 在模型选项卡中勾选 "完整上下文" (Full Context),上传文档 **预期行为**: 直接传递文档内容,不经过 RAG **实际行为**: - UI 仍然显示 "检索中..." (Retrieving...) - 显示 "搜索到 X 个引用来源" - 有明显的延迟感 ### 现象 2: 角色扮演场景性能灾难 **用户场景**: 上传 50KB+ 的角色扮演剧情文档,让 AI 接着剧情继续 **预期行为**: AI 直接阅读完整文档,无缝衔接剧情 **实际行为**: - RAG 提取的片段破坏时间线连续性 - AI "失忆"或混淆剧情顺序 - 超过 3 轮对话后,因上下文过大导致卡死 - 必须关闭 "将大文件粘贴为文本"选项,手动粘贴才能绕过 ### 现象 3: 无法真正关闭 RAG **用户操作**: 在设置 → 文档中勾选 "绕过嵌入和检索" **预期行为**: 完全跳过 RAG,直接传递原始文件 **实际行为**: - 只要模型选项卡中勾选了 "文件上下文",就会触发 RAG - 取消勾选 "文件上下文" 后,模型完全收不到文件 - 没有"直接传递文件内容"的选项 ## Root Cause 在 `chat_completion_files_handler` 中: ```python all_full_context = all(item.get("context") == "full" for item in files) # 即使 all_full_context=True,仍会执行: if not all_full_context: # 生成查询... # 仍然调用检索流程 sources = await get_sources_from_items( ..., full_context=all_full_context, # 只是传入参数,流程没变 ) ``` ## Solution When `all_full_context` is `True`: - **Skip query generation entirely** - **Skip `queries_generated` status emission** - **Call `get_sources_from_items` with minimal parameters** - **Directly use file content without embedding/retrieval** ## Changes - Modified `chat_completion_files_handler` in `backend/open_webui/utils/middleware.py` - Split logic into two paths: `all_full_context` vs normal RAG - When all files are full context, bypass all retrieval-related processing ## Testing - [ ] Upload files with Full Context mode enabled - [ ] Verify no "Retrieving..." status appears - [ ] Verify file content is directly injected into prompt - [ ] Verify normal RAG mode still works when not all files are full context ## Related Fixes the issue where 'Full Context' mode still triggered RAG processing, causing performance problems with large roleplay documents where time continuity is critical. --- Signed-off-by: Pyrite Prof <pyrite@example.com> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-06 11:34:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#65663