Appearance
Iteration 组件
概述
Iteration组件是RAGFlow 迭代处理组件,循环容器组件,对数据集合进行批量迭代处理。
主要功能
- 🔄 批量数据迭代处理
- 📊 支持多种配置选项和参数调节
- 🔧 与其他组件无缝集成
- ⚡ 高性能处理和错误恢复
适用场景
- 批量文档处理
- 数据集分析
- 重复任务执行
- 集合数据处理
参数配置
基础参数
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
delimiter | string | 否 | \n | 分隔符 |
max_iterations | number | 否 | 100 | 最大迭代次数 |
stop_condition | string | 否 | 停止条件 |
详细说明
主要参数说明
delimiter
- 类型: string
- 描述: 分隔符
- 默认值: \n
- 是否必填: 否
max_iterations
- 类型: number
- 描述: 最大迭代次数
- 默认值: 100
- 是否必填: 否
stop_condition
- 类型: string
- 描述: 停止条件
- 默认值:
- 是否必填: 否
输入输出
输入格式
Iteration组件接受上游组件的标准输出:
json
{
"content": "输入内容",
"component_id": "upstream_component_id",
"reference": []
}输出格式
json
{
"content": "处理后的输出内容",
"component_id": "iteration_component_id",
"metadata": {
"processing_time": 0.123,
"success": true
},
"reference": []
}使用示例
示例1: 基础配置
json
{
"component_name": "Iteration",
"params": {
"delimiter": \n
}
}示例2: 高级配置
json
{
"component_name": "Iteration",
"params": {
"delimiter": "\n",
"max_iterations": 100,
"stop_condition": ""
}
}前端实现
节点组件
typescript
// web/src/pages/flow/canvas/node/iteration-node.tsx
export function IterationNode({ id, data, isConnectable, selected }: NodeProps) {
return (
<section className={`${styles.ragNode} ${selected ? styles.selectedNode : ''}`}>
<Handle type="target" position={Position.Left} isConnectable={isConnectable} />
<Handle type="source" position={Position.Right} isConnectable={isConnectable} />
<NodeHeader id={id} name={data.name} label={data.label} />
<div className={styles.nodeBody}>
<div className={styles.nodeInfo}>
<span className={styles.nodeDescription}>循环容器组件,对数据集合进行批量迭代处理</span>
</div>
</div>
</section>
);
}配置表单
typescript
// web/src/pages/flow/form/iteration-form/index.tsx
const IterationForm: React.FC<IOperatorForm> = ({ onValuesChange, form }) => {
return (
<Form form={form} layout="vertical" onValuesChange={onValuesChange}>
<Form.Item
name="delimiter"
label="分隔符"
rules={[{ required: false, message: '请输入分隔符' }]}
>
<Input placeholder="请输入分隔符" />
</Form.Item>
<Form.Item
name="max_iterations"
label="最大迭代次数"
>
<InputNumber style={{ width: '100%' }} placeholder="100" />
</Form.Item>
<Form.Item
name="stop_condition"
label="停止条件"
rules={[{ required: false, message: '请输入停止条件' }]}
>
<Input placeholder="请输入停止条件" />
</Form.Item>
</Form>
);
};后端实现
参数类
python
# agent/component/iteration.py
class IterationParam(ComponentParamBase):
"""
Iteration组件参数
"""
def __init__(self):
super().__init__()
self.delimiter = "\n" # 分隔符
self.max_iterations = 100 # 最大迭代次数
self.stop_condition = "" # 停止条件
def check(self):
"""参数验证"""
# 验证必填参数
class Iteration(ComponentBase):
"""
Iteration组件实现
"""
component_name = "Iteration"
def _run(self, history, **kwargs):
"""
执行Iteration组件逻辑
"""
# 获取输入
input_df = self.get_input()
if input_df.empty:
raise ValueError("Iteration组件需要输入数据")
input_content = input_df.iloc[0]["content"]
# 执行核心处理逻辑
result = self._process_content(input_content)
# 返回结果
return pd.DataFrame([{
"content": result,
"component_id": self._id,
"metadata": {
"processing_time": time.time() - start_time,
"success": True
},
"reference": input_df.iloc[0].get("reference", [])
}])
def _process_content(self, content):
"""
处理内容的核心逻辑
"""
# TODO: 实现具体的处理逻辑
return f"已处理: {content}"最佳实践
1. 参数配置建议
- 根据具体使用场景调整参数
- 注意参数之间的依赖关系
- 合理设置超时和重试机制
2. 错误处理
python
def robust_processing(self, content):
"""
带错误处理的处理方法
"""
try:
return self._process_content(content)
except Exception as e:
logger.error(f"Iteration组件处理失败: {str(e)}")
return f"处理失败: {str(e)}"3. 性能优化
- 合理使用缓存机制
- 优化处理算法
- 控制资源使用
常见问题
Q1: 组件配置后不生效怎么办?
A: 检查参数格式和必填项是否正确配置。
Q2: 处理大量数据时性能较慢?
A: 可以调整批处理大小或使用异步处理。
Q3: 如何调试组件执行过程?
A: 使用调试模式和日志功能查看详细执行信息。
相关组件
推荐搭配组件
典型工作流模式
Begin → Iteration → Answer
其他组件 → Iteration → 下游组件组件版本: v1.0.0
最后更新: 2025-07-12