mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-26 23:29:24 -05:00
feat: let operators expose chosen file metadata to the model in retrieved sources (#29696)
Custom metadata attached to a file upload now reaches the vector DB, but the model still never sees it. Both prompt-assembly paths build their output from a fixed field set: the classic RAG <source> tag carries only id, name and resource type, and the retrieval tools return only content, source and file id per chunk. A scraper that records where each document came from therefore cannot get that origin in front of the model, so answers cannot state it. RAG_SOURCE_METADATA_KEYS names the chunk metadata keys allowed through to the model. Configured keys are emitted as extra attributes on the <source> tag and as extra fields on tool result chunks, covering both retrieval paths. It is empty by default, so nothing changes for existing deployments. An allowlist instead of passing everything through, because chunk metadata also carries file hashes, collection names, embedding config and relevance scores, which would then be added to every retrieved chunk of every request. Values are attacker-controllable through an uploaded file, so they are escaped before they go into the tag, and a configured key can never displace a field the tag or the chunk already defines. Reported in open-webui/open-webui#29486.
This commit is contained in:
1 parent
3a6d0fd203
commit
7fa705f3b8
5 files changed
+24
-2
No files matched your search
@@ -2,6 +2,7 @@ import ast
|
||||
import asyncio
|
||||
import base64
|
||||
import copy
|
||||
import html
|
||||
import inspect
|
||||
import json
|
||||
import logging
|
||||
@@ -52,7 +53,7 @@ from open_webui.models.models import Models
|
||||
from open_webui.models.notes import Notes
|
||||
from open_webui.models.oauth_sessions import OAuthSessions
|
||||
from open_webui.models.users import UserModel, Users
|
||||
from open_webui.retrieval.utils import get_sources_from_items
|
||||
from open_webui.retrieval.utils import filter_source_metadata, get_sources_from_items
|
||||
from open_webui.routers.images import (
|
||||
CreateImageForm,
|
||||
EditImageForm,
|
||||
@@ -952,11 +953,17 @@ def get_source_context(sources: list, source_ids: dict = None, include_content:
|
||||
src_type = source.get('source', {}).get('type')
|
||||
src_rid = source.get('source', {}).get('id')
|
||||
body = doc if include_content else ''
|
||||
extra_attrs = ''
|
||||
for key, value in filter_source_metadata(meta).items():
|
||||
if key in ('id', 'name', 'resource-type', 'resource-id'):
|
||||
continue
|
||||
extra_attrs += f' {key}="{html.escape(str(value))}"'
|
||||
context_string += (
|
||||
f'<source id="{source_ids[source_id]}"'
|
||||
+ (f' name="{src_name}"' if src_name else '')
|
||||
+ (f' resource-type="{src_type}"' if src_type else '')
|
||||
+ (f' resource-id="{src_rid}"' if src_rid else '')
|
||||
+ extra_attrs
|
||||
+ f'>{body}</source>\n'
|
||||
)
|
||||
return context_string
|
||||
|
||||
Reference in new issue
Block a user