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":
# Raw Text
# 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 = {
"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":
@ -594,26 +605,11 @@ def get_sources_from_items(
log.debug(f"skipping {item} as it has already been extracted")
continue
try:
if full_context:
try:
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:
query_result = None # Initialize to None
if hybrid_search:
try:
query_result = query_collection_with_hybrid_search(
@ -628,11 +624,11 @@ def get_sources_from_items(
)
except Exception as e:
log.debug(
"Error when using hybrid search, using"
" non hybrid search as fallback."
"Error when using hybrid search, using 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(
collection_names=collection_names,
queries=queries,
@ -647,7 +643,6 @@ def get_sources_from_items(
if query_result:
if "data" in item:
del item["data"]
query_results.append({**query_result, "file": item})
sources = []