Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: Fix for Empty Reference Array Causing Errors (#1652)

Mythd38f995ba603
diff --git a/api/apps/api_app.py b/api/apps/api_app.py
index dee7b857fc..6676941df8 100644
--- a/api/apps/api_app.py
+++ b/api/apps/api_app.py
@@ -199,8 +199,11 @@ def completion():
conv.message[-1] = {"role": "assistant", "content": ans["answer"]}
def rename_field(ans):
- for chunk in ans.get('reference', []):
- for chunk_i in chunk.get('chunks', []):
+ reference = ans['reference']
+ if not isinstance(reference, dict):
+ return
+ for chunk_i in reference.get('chunks', []):
+ if 'docnm_kwd' in chunk_i:
chunk_i['doc_name'] = chunk_i['docnm_kwd']
chunk_i.pop('docnm_kwd')