Tighten RAG file context scope handling

This commit is contained in:
Éole 2026-06-18 09:39:15 +00:00
parent 3a9b7dfcaa
commit decc794dac
3 changed files with 10 additions and 4 deletions

View file

@ -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

View file

@ -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:

View file

@ -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: [