diff --git a/.env.example b/.env.example index 2756df3b90..5a32e435b9 100644 --- a/.env.example +++ b/.env.example @@ -38,7 +38,7 @@ RAG_TOP_K=10 RAG_TOP_K_RERANKER=10 # Zero disables relevance score filtering. RAG_RELEVANCE_THRESHOLD=0.0 -# Always include full extracted text up to this character count per file or knowledge-base attachment. +# Always include full extracted text up to this character count per uploaded file. # Only larger attachments switch to retrieval; this never truncates text. Set to 0 to always use retrieval. RAG_FULL_TEXT_CHAR_THRESHOLD=50000 diff --git a/backend/open_webui/retrieval/utils.py b/backend/open_webui/retrieval/utils.py index b1840f8a78..340321cb0a 100644 --- a/backend/open_webui/retrieval/utils.py +++ b/backend/open_webui/retrieval/utils.py @@ -1623,20 +1623,9 @@ async def get_sources_from_items( extracted_collections.append(knowledge_base.id) else: - force_full_context = item.get('context') == 'full' or bypass_embedding_and_retrieval - files = None - documents = [] - if force_full_context or char_threshold > 0: + if item.get('context') == 'full' or bypass_embedding_and_retrieval: files = await Knowledges.get_files_by_id(knowledge_base.id) documents = [(file.data or {}).get('content') or '' for file in files] - # Missing extracted text must fall back to the index, not silently omit files. - auto_full_context = ( - char_threshold > 0 - and bool(documents) - and all(documents) - and sum(len(content) for content in documents) <= char_threshold - ) - if force_full_context or auto_full_context: query_result = { 'documents': [documents], 'metadatas': [ @@ -1651,8 +1640,7 @@ async def get_sources_from_items( # Legacy KB: item.collection_names is client-supplied. # Validate against the KB's actual files to prevent # cross-tenant collection name substitution. - if files is None: - files = await Knowledges.get_files_by_id(knowledge_base.id) + files = await Knowledges.get_files_by_id(knowledge_base.id) owned_names = {f'file-{f.id}' for f in files} owned_names.add(knowledge_base.id) valid_names = [n for n in (item.get('collection_names') or []) if n in owned_names] diff --git a/src/lib/i18n/locales/en-US/translation.json b/src/lib/i18n/locales/en-US/translation.json index 09702a054d..4cbc98249f 100644 --- a/src/lib/i18n/locales/en-US/translation.json +++ b/src/lib/i18n/locales/en-US/translation.json @@ -3002,7 +3002,7 @@ "settings.admin.documents.fullContextMode.description": "Include complete documents regardless of the full text threshold.", "settings.admin.documents.fullContextMode.label": "Always Use Full Text", "settings.admin.documents.fullTextCharThreshold.label": "Full Text Threshold (Characters)", - "settings.admin.documents.fullTextCharThreshold.description": "Include the complete extracted text of each uploaded file up to this character count. Only larger attachments switch to retrieval; text is never truncated at this threshold. Knowledge-base attachments count their files together. Set to 0 to always use retrieval. Explicit full-context selections still take priority.", + "settings.admin.documents.fullTextCharThreshold.description": "Include the complete extracted text of each uploaded file up to this character count. Only larger files switch to retrieval; text is never truncated at this threshold. Set to 0 to always use retrieval. Explicit full-context selections still take priority.", "settings.admin.documents.googleDrive.description": "Allow Google Drive as a document source.", "settings.admin.documents.googleDrive.label": "Google Drive", "settings.admin.documents.headers.description": "Additional JSON headers sent to the external document loader.",