Skip to content

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

Fix api reference empty bug (#1655)

Kung Quang32d5885b68c5
diff --git a/api/apps/api_app.py b/api/apps/api_app.py
index 52f0ba1ff7..dee7b857fc 100644
--- a/api/apps/api_app.py
+++ b/api/apps/api_app.py
@@ -199,9 +199,10 @@ def completion():
conv.message[-1] = {"role": "assistant", "content": ans["answer"]}
def rename_field(ans):
- for chunk_i in ans['reference'].get('chunks', []):
- chunk_i['doc_name'] = chunk_i['docnm_kwd']
- chunk_i.pop('docnm_kwd')
+ for chunk in ans.get('reference', []):
+ for chunk_i in chunk.get('chunks', []):
+ chunk_i['doc_name'] = chunk_i['docnm_kwd']
+ chunk_i.pop('docnm_kwd')
def stream():
nonlocal dia, msg, req, conv
@@ -232,10 +233,7 @@ def completion():
API4ConversationService.append_message(conv.id, conv.to_dict())
break
- for chunk_i in answer['reference'].get('chunks',[]):
- chunk_i['doc_name'] = chunk_i['docnm_kwd']
- chunk_i.pop('docnm_kwd')
-
+ rename_field(answer)
return get_json_result(data=answer)
except Exception as e:
@@ -252,6 +250,8 @@ def get(conversation_id):
conv = conv.to_dict()
for referenct_i in conv['reference']:
+ if referenct_i is None or len(referenct_i) == 0:
+ continue
for chunk_i in referenct_i['chunks']:
if 'docnm_kwd' in chunk_i.keys():
chunk_i['doc_name'] = chunk_i['docnm_kwd']
diff --git a/rag/llm/rerank_model.py b/rag/llm/rerank_model.py
index fb20aea699..b6d5421ee7 100644
--- a/rag/llm/rerank_model.py
+++ b/rag/llm/rerank_model.py
@@ -147,6 +147,8 @@ class XInferenceRerank(Base):
}
def similarity(self, query: str, texts: list):
+ if len(texts) == 0:
+ return np.array([]), 0
data = {
"model": self.model_name,
"query": query,