一个标准知识库问答的编排

1 流程

image.png

2 详细流程

2.1 流程开始

没有特别的设置

2.2 文本拼接

image.png

生成用于优化问题的提示词。
新建一个变量 input,来自于 用户问题
拼接文本:

你是经验丰富的科学课程老师。<text></text>中的内容是我的问题,你的任务是优化这个问题,让输出更加丰富和聚焦于细节。要求如下:

- 直接输出结果
- 不要分析、解释、回答问题。
- 不要求我给你更多的细节。

<text>
{{input}}
</text>

另一种拼接方法:

你是经验丰富的化学课程老师。你的任务是优化我的问题,让输出更加丰富和聚焦于细节。直接输出优化的结果,不要分析、解释、回答问题,不要求我给你更多的细节。
我的问题是:{{input}}
直接在____处输出优化后的问题。

______________

2.3 问题优化

image.png

模型选择:gpt-4o ,不要使用 gpt-4o-mini 输出不太可控。点击模型名称可以进行模型的配置。
image.png
不要选择 返回 AI 内容,不然会输出优化后的问题。

提示词:空
聊天记录:0 。!!! 一定是 0。不然再次进行提问时会把之前的回答和提问带入上下文。
用户问题:选择上一步 拼接结果

2.4 知识库搜索

image.png
选择创建好的知识库,这一步可以参考 打造知识库
搜索设置如下:

用户问题:选择上一步 问题优化 > AI 回复内容

3 AI 对话

image.png
模型:为了省点钱的话,可以选择 deepseek-chat
提示词:要与知识库相关,最好是设置一个角色。
聊天记录:6 就可以。
知识库引用:选择上一步的知识库。点击 ⚙️ 进行设置。
image.png
选择 标准模板
如果知识库来自于多个文档的导入,在 引用模板内容 中加入一行 来源:{{source}}
文档引用:不选
用户问题:选择 问题优化 > AI 回复内容

4 配置

{
  "nodes": [
    {
      "nodeId": "userGuide",
      "name": "系统配置",
      "intro": "可以配置应用的系统参数",
      "avatar": "core/workflow/template/systemConfig",
      "flowNodeType": "userGuide",
      "position": {
        "x": -682.5169279544558,
        "y": -734.936146867379
      },
      "version": "481",
      "inputs": [
        {
          "key": "welcomeText",
          "renderTypeList": [
            "hidden"
          ],
          "valueType": "string",
          "label": "core.app.Welcome Text",
          "value": "你好,我是知识库助手,请不要忘记选择知识库噢~\n[你是谁]\n[如何使用]"
        },
        {
          "key": "variables",
          "renderTypeList": [
            "hidden"
          ],
          "valueType": "any",
          "label": "core.app.Chat Variable",
          "value": []
        },
        {
          "key": "questionGuide",
          "valueType": "boolean",
          "renderTypeList": [
            "hidden"
          ],
          "label": "core.app.Question Guide",
          "value": false
        },
        {
          "key": "tts",
          "renderTypeList": [
            "hidden"
          ],
          "valueType": "any",
          "label": "",
          "value": {
            "type": "web"
          }
        },
        {
          "key": "whisper",
          "renderTypeList": [
            "hidden"
          ],
          "valueType": "any",
          "label": "",
          "value": {
            "open": false,
            "autoSend": false,
            "autoTTSResponse": false
          }
        },
        {
          "key": "scheduleTrigger",
          "renderTypeList": [
            "hidden"
          ],
          "valueType": "any",
          "label": "",
          "value": null
        }
      ],
      "outputs": []
    },
    {
      "nodeId": "workflowStartNodeId",
      "name": "流程开始",
      "intro": "",
      "avatar": "core/workflow/template/workflowStart",
      "flowNodeType": "workflowStart",
      "position": {
        "x": -1082.78790392898,
        "y": 254.6037121567142
      },
      "version": "481",
      "inputs": [
        {
          "key": "userChatInput",
          "renderTypeList": [
            "reference",
            "textarea"
          ],
          "valueType": "string",
          "label": "用户问题",
          "required": true,
          "toolDescription": "用户问题"
        }
      ],
      "outputs": [
        {
          "id": "userChatInput",
          "key": "userChatInput",
          "label": "common:core.module.input.label.user question",
          "type": "static",
          "valueType": "string"
        }
      ]
    },
    {
      "nodeId": "7BdojPlukIQw",
      "name": "AI 对话",
      "intro": "AI 大模型对话",
      "avatar": "core/workflow/template/aiChat",
      "flowNodeType": "chatNode",
      "showStatus": true,
      "position": {
        "x": 1559.8775056365023,
        "y": -16.400771168434346
      },
      "version": "481",
      "inputs": [
        {
          "key": "model",
          "renderTypeList": [
            "settingLLMModel",
            "reference"
          ],
          "label": "core.module.input.label.aiModel",
          "valueType": "string",
          "value": "deepseek-chat"
        },
        {
          "key": "temperature",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "value": 2,
          "valueType": "number",
          "min": 0,
          "max": 10,
          "step": 1
        },
        {
          "key": "maxToken",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "value": 4000,
          "valueType": "number",
          "min": 100,
          "max": 4000,
          "step": 50
        },
        {
          "key": "isResponseAnswerText",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "value": true,
          "valueType": "boolean"
        },
        {
          "key": "quoteTemplate",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "string",
          "value": "{{q}}\n{{a}}"
        },
        {
          "key": "quotePrompt",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "string",
          "value": "忘记你已有的知识,仅使用 <Data></Data> 标记中的内容作为你的知识:\n\n<Data>\n{{quote}}\n</Data>\n\n思考流程:\n1. 判断问题是否与 <Data></Data> 标记中的内容有关。\n2. 如果有关,你按下面的要求回答。\n3. 如果无关,你直接拒绝回答本次问题。\n\n回答要求:\n- 避免提及你是从 <Data></Data> 获取的知识。\n- 保持答案与 <Data></Data> 中描述的一致。\n- 使用 Markdown 语法优化回答格式。\n- 使用与问题相同的语言回答。\n\n问题:\"\"\"{{question}}\"\"\""
        },
        {
          "key": "aiChatVision",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "boolean",
          "value": true
        },
        {
          "key": "systemPrompt",
          "renderTypeList": [
            "textarea",
            "reference"
          ],
          "max": 3000,
          "valueType": "string",
          "label": "core.ai.Prompt",
          "description": "core.app.tip.chatNodeSystemPromptTip",
          "placeholder": "core.app.tip.chatNodeSystemPromptTip",
          "value": "扮演信息化项目专家"
        },
        {
          "key": "history",
          "renderTypeList": [
            "numberInput",
            "reference"
          ],
          "valueType": "chatHistory",
          "label": "core.module.input.label.chat history",
          "description": "最多携带多少轮对话记录",
          "required": true,
          "min": 0,
          "max": 50,
          "value": 6
        },
        {
          "key": "quoteQA",
          "renderTypeList": [
            "settingDatasetQuotePrompt"
          ],
          "label": "",
          "debugLabel": "知识库引用",
          "description": "",
          "valueType": "datasetQuote",
          "value": [
            "iKBoX2vIzETU",
            "quoteQA"
          ]
        },
        {
          "key": "stringQuoteText",
          "renderTypeList": [
            "reference",
            "textarea"
          ],
          "label": "app:document_quote",
          "debugLabel": "app:document_quote",
          "description": "app:document_quote_tip",
          "valueType": "string"
        },
        {
          "key": "userChatInput",
          "renderTypeList": [
            "reference",
            "textarea"
          ],
          "valueType": "string",
          "label": "用户问题",
          "required": true,
          "toolDescription": "用户问题",
          "value": [
            "zkzT3LPzuy8k",
            "answerText"
          ]
        }
      ],
      "outputs": [
        {
          "id": "history",
          "key": "history",
          "required": true,
          "label": "core.module.output.label.New context",
          "description": "core.module.output.description.New context",
          "valueType": "chatHistory",
          "type": "static"
        },
        {
          "id": "answerText",
          "key": "answerText",
          "required": true,
          "label": "core.module.output.label.Ai response content",
          "description": "core.module.output.description.Ai response content",
          "valueType": "string",
          "type": "static"
        }
      ]
    },
    {
      "nodeId": "iKBoX2vIzETU",
      "name": "知识库搜索",
      "intro": "调用“语义检索”和“全文检索”能力,从“知识库”中查找可能与问题相关的参考内容",
      "avatar": "core/workflow/template/datasetSearch",
      "flowNodeType": "datasetSearchNode",
      "showStatus": true,
      "position": {
        "x": 655.1119308661343,
        "y": 174.0124869104919
      },
      "version": "481",
      "inputs": [
        {
          "key": "datasets",
          "renderTypeList": [
            "selectDataset",
            "reference"
          ],
          "label": "core.module.input.label.Select dataset",
          "value": [],
          "valueType": "selectDataset",
          "required": true,
          "list": []
        },
        {
          "key": "similarity",
          "renderTypeList": [
            "selectDatasetParamsModal"
          ],
          "label": "",
          "value": 0.6,
          "valueType": "number"
        },
        {
          "key": "limit",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "value": 8000,
          "valueType": "number"
        },
        {
          "key": "searchMode",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "string",
          "value": "mixedRecall"
        },
        {
          "key": "usingReRank",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "boolean",
          "value": true
        },
        {
          "key": "datasetSearchUsingExtensionQuery",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "boolean",
          "value": true
        },
        {
          "key": "datasetSearchExtensionModel",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "string",
          "value": "gpt-4o-mini"
        },
        {
          "key": "datasetSearchExtensionBg",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "string",
          "value": "关于信息化项目方案"
        },
        {
          "key": "userChatInput",
          "renderTypeList": [
            "reference",
            "textarea"
          ],
          "valueType": "string",
          "label": "用户问题",
          "required": true,
          "toolDescription": "需要检索的内容",
          "value": [
            "zkzT3LPzuy8k",
            "answerText"
          ]
        },
        {
          "key": "collectionFilterMatch",
          "renderTypeList": [
            "JSONEditor",
            "reference"
          ],
          "label": "集合元数据过滤",
          "valueType": "object",
          "isPro": true,
          "description": "目前支持标签和创建时间过滤,需按照以下格式填写:\n{\n  \"tags\": {\n    \"$and\": [\"标签 1\",\"标签 2\"],\n    \"$or\": [\"有 $and 标签时,and 生效,or 不生效\"]\n  },\n  \"createTime\": {\n      \"$gte\": \"YYYY-MM-DD HH:mm 格式即可,集合的创建时间大于该时间\",\n      \"$lte\": \"YYYY-MM-DD HH:mm 格式即可,集合的创建时间小于该时间,可和 $gte 共同使用\"\n  }\n}\n      "
        }
      ],
      "outputs": [
        {
          "id": "quoteQA",
          "key": "quoteQA",
          "label": "core.module.Dataset quote.label",
          "description": "特殊数组格式,搜索结果为空时,返回空数组。",
          "type": "static",
          "valueType": "datasetQuote"
        }
      ]
    },
    {
      "nodeId": "qRK8L5qlkWze",
      "name": "文本拼接",
      "intro": "可对固定或传入的文本进行加工后输出,非字符串类型数据最终会转成字符串类型。",
      "avatar": "core/workflow/template/textConcat",
      "flowNodeType": "textEditor",
      "position": {
        "x": -654.5357758324703,
        "y": 149.02292291608356
      },
      "version": "486",
      "inputs": [
        {
          "key": "system_addInputParam",
          "renderTypeList": [
            "addInputParam"
          ],
          "valueType": "dynamic",
          "label": "",
          "required": false,
          "description": "可以引用其他节点的输出,作为文本拼接的变量,通过 {{字段名}} 来引用变量",
          "customInputConfig": {
            "selectValueTypeList": [
              "string",
              "number",
              "boolean",
              "object",
              "arrayString",
              "arrayNumber",
              "arrayBoolean",
              "arrayObject",
              "any",
              "chatHistory",
              "datasetQuote",
              "dynamic",
              "selectApp",
              "selectDataset"
            ],
            "showDescription": false,
            "showDefaultValue": false
          }
        },
        {
          "key": "system_textareaInput",
          "renderTypeList": [
            "textarea"
          ],
          "valueType": "string",
          "required": true,
          "label": "拼接文本",
          "placeholder": "可通过 {{字段名}} 来引用变量",
          "value": "你是经验丰富的信息化项目专家。\n你的任务是优化我的问题,让输出更加丰富和聚焦于细节。直接输出优化的结果,不要分析、解释、回答问题,不要求我给你更多的细节。\n我的问题是:{{input}}\n\n直接在____处输出优化后的问题。\n______________"
        },
        {
          "renderTypeList": [
            "reference"
          ],
          "valueType": "string",
          "canEdit": true,
          "key": "input",
          "label": "input",
          "customInputConfig": {
            "selectValueTypeList": [
              "string",
              "number",
              "boolean",
              "object",
              "arrayString",
              "arrayNumber",
              "arrayBoolean",
              "arrayObject",
              "any",
              "chatHistory",
              "datasetQuote",
              "dynamic",
              "selectApp",
              "selectDataset"
            ],
            "showDescription": false,
            "showDefaultValue": false
          },
          "required": true,
          "value": [
            "workflowStartNodeId",
            "userChatInput"
          ]
        }
      ],
      "outputs": [
        {
          "id": "system_text",
          "key": "system_text",
          "label": "拼接结果",
          "type": "static",
          "valueType": "string"
        }
      ]
    },
    {
      "nodeId": "zkzT3LPzuy8k",
      "name": "问题优化",
      "intro": "AI 大模型对话",
      "avatar": "core/workflow/template/aiChat",
      "flowNodeType": "chatNode",
      "showStatus": true,
      "position": {
        "x": 96.8084494110476,
        "y": -2.0708428444559104
      },
      "version": "481",
      "inputs": [
        {
          "key": "model",
          "renderTypeList": [
            "settingLLMModel",
            "reference"
          ],
          "label": "core.module.input.label.aiModel",
          "valueType": "string",
          "value": "gpt-4o"
        },
        {
          "key": "temperature",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "value": 2,
          "valueType": "number"
        },
        {
          "key": "maxToken",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "value": 2000,
          "valueType": "number"
        },
        {
          "key": "isResponseAnswerText",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "value": false,
          "valueType": "boolean"
        },
        {
          "key": "quoteTemplate",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "string",
          "value": "{{q}}\n{{a}}"
        },
        {
          "key": "quotePrompt",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "string",
          "value": "使用 <Data></Data> 标记中的内容作为你的知识:\n\n<Data>\n{{quote}}\n</Data>\n\n回答要求:\n- 如果你不清楚答案,你需要澄清。\n- 避免提及你是从 <Data></Data> 获取的知识。\n- 保持答案与 <Data></Data> 中描述的一致。\n- 使用 Markdown 语法优化回答格式。\n- 使用与问题相同的语言回答。\n\n问题:\"\"\"{{question}}\"\"\""
        },
        {
          "key": "aiChatVision",
          "renderTypeList": [
            "hidden"
          ],
          "label": "",
          "valueType": "boolean",
          "value": true
        },
        {
          "key": "systemPrompt",
          "renderTypeList": [
            "textarea",
            "reference"
          ],
          "max": 3000,
          "valueType": "string",
          "label": "core.ai.Prompt",
          "description": "core.app.tip.chatNodeSystemPromptTip",
          "placeholder": "core.app.tip.chatNodeSystemPromptTip",
          "value": ""
        },
        {
          "key": "history",
          "renderTypeList": [
            "numberInput",
            "reference"
          ],
          "valueType": "chatHistory",
          "label": "core.module.input.label.chat history",
          "description": "最多携带多少轮对话记录",
          "required": true,
          "min": 0,
          "max": 50,
          "value": 0
        },
        {
          "key": "quoteQA",
          "renderTypeList": [
            "settingDatasetQuotePrompt"
          ],
          "label": "",
          "debugLabel": "知识库引用",
          "description": "",
          "valueType": "datasetQuote"
        },
        {
          "key": "stringQuoteText",
          "renderTypeList": [
            "reference",
            "textarea"
          ],
          "label": "app:document_quote",
          "debugLabel": "app:document_quote",
          "description": "app:document_quote_tip",
          "valueType": "string"
        },
        {
          "key": "userChatInput",
          "renderTypeList": [
            "reference",
            "textarea"
          ],
          "valueType": "string",
          "label": "用户问题",
          "required": true,
          "toolDescription": "用户问题",
          "value": [
            "qRK8L5qlkWze",
            "system_text"
          ]
        }
      ],
      "outputs": [
        {
          "id": "history",
          "key": "history",
          "required": true,
          "label": "core.module.output.label.New context",
          "description": "core.module.output.description.New context",
          "valueType": "chatHistory",
          "type": "static"
        },
        {
          "id": "answerText",
          "key": "answerText",
          "required": true,
          "label": "core.module.output.label.Ai response content",
          "description": "core.module.output.description.Ai response content",
          "valueType": "string",
          "type": "static"
        }
      ]
    }
  ],
  "edges": [
    {
      "source": "iKBoX2vIzETU",
      "target": "7BdojPlukIQw",
      "sourceHandle": "iKBoX2vIzETU-source-right",
      "targetHandle": "7BdojPlukIQw-target-left"
    },
    {
      "source": "workflowStartNodeId",
      "target": "qRK8L5qlkWze",
      "sourceHandle": "workflowStartNodeId-source-right",
      "targetHandle": "qRK8L5qlkWze-target-left"
    },
    {
      "source": "qRK8L5qlkWze",
      "target": "zkzT3LPzuy8k",
      "sourceHandle": "qRK8L5qlkWze-source-right",
      "targetHandle": "zkzT3LPzuy8k-target-left"
    },
    {
      "source": "zkzT3LPzuy8k",
      "target": "iKBoX2vIzETU",
      "sourceHandle": "zkzT3LPzuy8k-source-right",
      "targetHandle": "iKBoX2vIzETU-target-left"
    }
  ],
  "chatConfig": {
    "variables": [],
    "scheduledTriggerConfig": {
      "cronString": "",
      "timezone": "Asia/Shanghai",
      "defaultPrompt": ""
    },
    "_id": "668143b86da25297e7d817ae"
  }
}