diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py index fcda8883ec..4864845e8d 100644 --- a/backend/open_webui/routers/retrieval.py +++ b/backend/open_webui/routers/retrieval.py @@ -10,7 +10,7 @@ import shutil import uuid from datetime import datetime from pathlib import Path -from typing import Callable, Iterator, Optional, Sequence, Union +from typing import Callable, Iterator, Literal, Optional, Sequence, Union import tiktoken from fastapi import ( @@ -653,7 +653,7 @@ class ConfigForm(BaseModel): TOP_K: int | None = None BYPASS_EMBEDDING_AND_RETRIEVAL: bool | None = None RAG_FULL_CONTEXT: bool | None = None - RAG_FILE_CONTEXT_SCOPE: str | None = None + RAG_FILE_CONTEXT_SCOPE: Literal['conversation', 'message'] | None = None # Hybrid search settings ENABLE_RAG_HYBRID_SEARCH: bool | None = None diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index be6c08b25c..2e084ca1a2 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -955,11 +955,17 @@ def get_source_context(sources: list, source_ids: dict = None, include_content: return context_string +FILE_CONTEXT_ITEM_TYPES = {'doc', 'text', 'note', 'chat', 'folder', 'collection'} + + def is_file_context_item(item: dict) -> bool: if not isinstance(item, dict): return False - return item.get('type') != 'image' and not (item.get('content_type') or '').startswith('image/') + item_type = item.get('type') + return item_type in FILE_CONTEXT_ITEM_TYPES or ( + item_type == 'file' and not (item.get('content_type') or '').startswith('image/') + ) def get_file_context_key(item: dict) -> tuple: diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 28e428971d..5bf538f21a 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -2340,7 +2340,7 @@ return { role: message.role, ...(message.output ? { output: message.output } : {}), - ...(messageFiles.length > 0 ? { files: messageFiles } : {}), + ...(message.role === 'user' && messageFiles.length > 0 ? { files: messageFiles } : {}), ...(message.role === 'user' && imageFiles.length > 0 ? { content: [