From bb57b14cb825f89b83262d3eb3b831b775b9bab9 Mon Sep 17 00:00:00 2001 From: QingGang Date: Tue, 23 Dec 2025 01:43:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=90=9C=E7=B4=A2=E8=8A=82?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodes/parse_search.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/nodes/parse_search.py b/nodes/parse_search.py index d1d9dad..f349a9c 100644 --- a/nodes/parse_search.py +++ b/nodes/parse_search.py @@ -6,7 +6,35 @@ def check_status(status_code: float, body: str): raise Exception(f"注册任务失败,状态码:{status_code}") if "code" not in body or body["code"] != 1: raise Exception(f"注册任务失败,返回值:{body}") + +def format_rag_context(data: list) -> str: + ''' + 将检索到的 data 列表格式化为 Markdown 文本 + ''' + if not data: + return "未找到相关的参考资料。" + + formatted_parts = [] + for i, item in enumerate(data): + # 提取字段(对应你数据库和 API 返回的字段) + title = item.get("title") or "无标题" + url = item.get("source_url") or "未知来源" + content = item.get("content", "").strip() + c_idx = item.get("chunk_index", 0) + + # 构造 Markdown 块 + block = ( + f"### [资料 {i+1}] {title}\n" + f"**来源**: {url}\n" + f"**切片索引**: {c_idx}\n" + f"**内容**: {content}" + ) + formatted_parts.append(block) + + # 使用分隔符连接多个资料块 + return "\n\n---\n\n".join(formatted_parts) + def main(status_code: float, body: str): try: check_status(status_code, body) @@ -14,7 +42,8 @@ def main(status_code: float, body: str): raise e data = body["data"] - + rag_context = format_rag_context(data) + return { - "RAG_results": data + "RAG_results": rag_context }