Spaces:
Paused
Paused
lanny xu
commited on
Commit
·
11e6cae
1
Parent(s):
543b684
delete vectara
Browse files- main.py +3 -2
- workflow_nodes.py +17 -3
main.py
CHANGED
|
@@ -47,10 +47,11 @@ class AdaptiveRAGSystem:
|
|
| 47 |
|
| 48 |
def _build_workflow(self):
|
| 49 |
"""构建工作流图"""
|
| 50 |
-
# 创建工作流节点实例,传递DocumentProcessor
|
| 51 |
self.workflow_nodes = WorkflowNodes(
|
| 52 |
doc_processor=self.doc_processor,
|
| 53 |
-
graders=self.graders
|
|
|
|
| 54 |
)
|
| 55 |
|
| 56 |
workflow = StateGraph(GraphState)
|
|
|
|
| 47 |
|
| 48 |
def _build_workflow(self):
|
| 49 |
"""构建工作流图"""
|
| 50 |
+
# 创建工作流节点实例,传递DocumentProcessor实例和retriever
|
| 51 |
self.workflow_nodes = WorkflowNodes(
|
| 52 |
doc_processor=self.doc_processor,
|
| 53 |
+
graders=self.graders,
|
| 54 |
+
retriever=self.retriever
|
| 55 |
)
|
| 56 |
|
| 57 |
workflow = StateGraph(GraphState)
|
workflow_nodes.py
CHANGED
|
@@ -39,9 +39,9 @@ class GraphState(TypedDict):
|
|
| 39 |
class WorkflowNodes:
|
| 40 |
"""工作流节点类,包含所有节点函数"""
|
| 41 |
|
| 42 |
-
def __init__(self, doc_processor, graders):
|
| 43 |
self.doc_processor = doc_processor # 接收DocumentProcessor实例
|
| 44 |
-
self.retriever = doc_processor
|
| 45 |
self.graders = graders
|
| 46 |
|
| 47 |
# 设置RAG链 - 使用本地提示模板
|
|
@@ -100,7 +100,21 @@ class WorkflowNodes:
|
|
| 100 |
except Exception as e:
|
| 101 |
print(f"⚠️ 增强检索失败: {e},回退到基本检索")
|
| 102 |
# 回退到基本检索
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
return {"documents": documents, "question": question}
|
| 106 |
|
|
|
|
| 39 |
class WorkflowNodes:
|
| 40 |
"""工作流节点类,包含所有节点函数"""
|
| 41 |
|
| 42 |
+
def __init__(self, doc_processor, graders, retriever=None):
|
| 43 |
self.doc_processor = doc_processor # 接收DocumentProcessor实例
|
| 44 |
+
self.retriever = retriever if retriever is not None else getattr(doc_processor, 'retriever', None)
|
| 45 |
self.graders = graders
|
| 46 |
|
| 47 |
# 设置RAG链 - 使用本地提示模板
|
|
|
|
| 100 |
except Exception as e:
|
| 101 |
print(f"⚠️ 增强检索失败: {e},回退到基本检索")
|
| 102 |
# 回退到基本检索
|
| 103 |
+
try:
|
| 104 |
+
if self.retriever is not None:
|
| 105 |
+
documents = self.retriever.invoke(question)
|
| 106 |
+
elif hasattr(self.doc_processor, 'vector_retriever') and self.doc_processor.vector_retriever is not None:
|
| 107 |
+
documents = self.doc_processor.vector_retriever.invoke(question)
|
| 108 |
+
print(" 使用 vector_retriever 作为备选")
|
| 109 |
+
elif hasattr(self.doc_processor, 'retriever') and self.doc_processor.retriever is not None:
|
| 110 |
+
documents = self.doc_processor.retriever.invoke(question)
|
| 111 |
+
print(" 使用 doc_processor.retriever 作为备选")
|
| 112 |
+
else:
|
| 113 |
+
print("❌ 检索器未正确初始化,返回空文档列表")
|
| 114 |
+
documents = []
|
| 115 |
+
except Exception as fallback_e:
|
| 116 |
+
print(f"❌ 回退检索也失败: {fallback_e}")
|
| 117 |
+
documents = []
|
| 118 |
|
| 119 |
return {"documents": documents, "question": question}
|
| 120 |
|