refac
This commit is contained in:
@@ -566,6 +566,13 @@ async def query_collection(
|
|||||||
log.exception(f'Error when querying the collection: {e}')
|
log.exception(f'Error when querying the collection: {e}')
|
||||||
return None, 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)
|
# Generate all query embeddings (in one call)
|
||||||
query_embeddings = await embedding_function(queries, prefix=RAG_EMBEDDING_QUERY_PREFIX)
|
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')
|
log.debug(f'query_collection: processing {len(queries)} queries across {len(collection_names)} collections')
|
||||||
|
|||||||
@@ -238,9 +238,13 @@ async def fetch_url(
|
|||||||
content, _ = await asyncio.to_thread(get_content_from_url, __request__, url)
|
content, _ = await asyncio.to_thread(get_content_from_url, __request__, url)
|
||||||
|
|
||||||
# Truncate if configured (WEB_FETCH_MAX_CONTENT_LENGTH)
|
# Truncate if configured (WEB_FETCH_MAX_CONTENT_LENGTH)
|
||||||
max_length = getattr(__request__.app.state.config, 'WEB_FETCH_MAX_CONTENT_LENGTH', None)
|
# Guard: content may be None if the web loader silently failed
|
||||||
if max_length and max_length > 0 and len(content) > max_length:
|
if content is not None:
|
||||||
content = content[:max_length] + '\n\n[Content truncated...]'
|
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
|
return content
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -1546,11 +1546,11 @@ async def chat_web_search_handler(request: Request, form_data: dict, extra_param
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
queries = [user_message]
|
queries = [user_message or '']
|
||||||
|
|
||||||
# Check if generated queries are empty
|
# Check if generated queries are empty
|
||||||
if len(queries) == 1 and queries[0].strip() == '':
|
if len(queries) == 1 and queries[0].strip() == '':
|
||||||
queries = [user_message]
|
queries = [user_message or '']
|
||||||
|
|
||||||
# Check if queries are not found
|
# Check if queries are not found
|
||||||
if len(queries) == 0:
|
if len(queries) == 0:
|
||||||
@@ -1991,7 +1991,7 @@ async def chat_completion_files_handler(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if len(queries) == 0:
|
if len(queries) == 0:
|
||||||
queries = [get_last_user_message(body['messages'])]
|
queries = [get_last_user_message(body['messages']) or '']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Directly await async get_sources_from_items (no thread needed - fully async now)
|
# Directly await async get_sources_from_items (no thread needed - fully async now)
|
||||||
|
|||||||
Reference in New Issue
Block a user