This commit is contained in:
Timothy Jaeryang Baek 2025-07-11 12:35:42 +04:00
parent 033d07ee23
commit 77c1905609

View file

@ -473,9 +473,20 @@ def get_sources_from_items(
if item.get("type") == "text": if item.get("type") == "text":
# Raw Text # Raw Text
# Used during temporary chat file uploads # Used during temporary chat file uploads
if item.get("file"):
# if item has file data, use it
query_result = {
"documents": [[item.get("file").get("data", {}).get("content")]],
"metadatas": [[item.get("file").get("data", {}).get("meta", {})]],
}
else:
# Fallback to item content
query_result = { query_result = {
"documents": [[item.get("content")]], "documents": [[item.get("content")]],
"metadatas": [[{"file_id": item.get("id"), "name": item.get("name")}]], "metadatas": [
[{"file_id": item.get("id"), "name": item.get("name")}]
],
} }
elif item.get("type") == "note": elif item.get("type") == "note":
@ -594,26 +605,11 @@ def get_sources_from_items(
log.debug(f"skipping {item} as it has already been extracted") log.debug(f"skipping {item} as it has already been extracted")
continue continue
try:
if full_context: if full_context:
try:
query_result = get_all_items_from_collections(collection_names) query_result = get_all_items_from_collections(collection_names)
except Exception as e:
log.exception(e)
else:
try:
query_result = None
if item.get("type") == "text":
# Not sure when this is used, but it seems to be a fallback
# TODO: remove?
query_result = {
"documents": [
[item.get("file").get("data", {}).get("content")]
],
"metadatas": [
[item.get("file").get("data", {}).get("meta", {})]
],
}
else: else:
query_result = None # Initialize to None
if hybrid_search: if hybrid_search:
try: try:
query_result = query_collection_with_hybrid_search( query_result = query_collection_with_hybrid_search(
@ -628,11 +624,11 @@ def get_sources_from_items(
) )
except Exception as e: except Exception as e:
log.debug( log.debug(
"Error when using hybrid search, using" "Error when using hybrid search, using non hybrid search as fallback."
" non hybrid search as fallback."
) )
if (not hybrid_search) or (query_result is None): # fallback to non-hybrid search
if not hybrid_search and query_result is None:
query_result = query_collection( query_result = query_collection(
collection_names=collection_names, collection_names=collection_names,
queries=queries, queries=queries,
@ -647,7 +643,6 @@ def get_sources_from_items(
if query_result: if query_result:
if "data" in item: if "data" in item:
del item["data"] del item["data"]
query_results.append({**query_result, "file": item}) query_results.append({**query_result, "file": item})
sources = [] sources = []