This commit is contained in:
Timothy Jaeryang Baek
2026-04-24 17:59:45 +09:00
parent a7a92d2d9b
commit 1cea8ec7d4
3 changed files with 17 additions and 6 deletions

View File

@@ -566,6 +566,13 @@ async def query_collection(
log.exception(f'Error when querying the collection: {e}')
return None, e
# Sanitize: filter out None/empty queries to prevent embedding crashes
# (e.g. when get_last_user_message returns None)
queries = [q for q in queries if q]
if not queries:
log.warning('query_collection: all queries were None or empty, returning empty results')
return {'distances': [[]], 'documents': [[]], 'metadatas': [[]]}
# Generate all query embeddings (in one call)
query_embeddings = await embedding_function(queries, prefix=RAG_EMBEDDING_QUERY_PREFIX)
log.debug(f'query_collection: processing {len(queries)} queries across {len(collection_names)} collections')

View File

@@ -238,9 +238,13 @@ async def fetch_url(
content, _ = await asyncio.to_thread(get_content_from_url, __request__, url)
# Truncate if configured (WEB_FETCH_MAX_CONTENT_LENGTH)
max_length = getattr(__request__.app.state.config, 'WEB_FETCH_MAX_CONTENT_LENGTH', None)
if max_length and max_length > 0 and len(content) > max_length:
content = content[:max_length] + '\n\n[Content truncated...]'
# Guard: content may be None if the web loader silently failed
if content is not None:
max_length = getattr(__request__.app.state.config, 'WEB_FETCH_MAX_CONTENT_LENGTH', None)
if max_length and max_length > 0 and len(content) > max_length:
content = content[:max_length] + '\n\n[Content truncated...]'
else:
content = ''
return content
except Exception as e:

View File

@@ -1546,11 +1546,11 @@ async def chat_web_search_handler(request: Request, form_data: dict, extra_param
except Exception as e:
log.exception(e)
queries = [user_message]
queries = [user_message or '']
# Check if generated queries are empty
if len(queries) == 1 and queries[0].strip() == '':
queries = [user_message]
queries = [user_message or '']
# Check if queries are not found
if len(queries) == 0:
@@ -1991,7 +1991,7 @@ async def chat_completion_files_handler(
)
if len(queries) == 0:
queries = [get_last_user_message(body['messages'])]
queries = [get_last_user_message(body['messages']) or '']
try:
# Directly await async get_sources_from_items (no thread needed - fully async now)