How to Build an AI‑Powered Knowledge Retrieval Workflow with Dify and Embedding Models
This guide explains how to organize a knowledge base, select embedding and rerank models, clean user queries, and construct a Dify DSL workflow that iteratively retrieves and merges information before handing it to a large language model for answer generation.
Key Steps
Knowledge base organization: use Excel as the source format and convert it to CSV for upload.
Knowledge base retrieval mode: enable high‑quality mode and combine the embedding model bge‑m3 with the rerank model bge‑reranker‑large .
AI application orchestration: first let a large model decompose the question, removing interrogative words, verbs, particles, prepositions, conjunctions, and modifiers unless they are essential to the core noun phrase.
Question Cleaning Prompt
Prompt for extracting core nouns and noun phrases from user input.
# Role
You are a natural‑language‑processing text analysis expert.
# Task
Accurately extract the core nouns and noun phrases from each independent question in the user’s input.
# Input
User input text:
# Processing Steps
1. **Split questions**: Identify and separate each independent question.
2. **Identify core**: For each question, find nouns and noun phrases that represent the subject, object, time, location, and constraints.
3. **Filter non‑core**: Generally ignore interrogative words (e.g., "how many", "where", "who"), verbs, particles, prepositions, conjunctions, and adjectives/adverbs unless they are indispensable to the noun phrase.
4. **Format output**: Follow the specified output format.
# Principles
- **Information completeness**: Preserve all key information.
- **Purity of components**: Output only nouns and noun phrases.
- **Question distinction**: Keep extracted terms for each question separate.
- **Faithfulness**: Do not add or guess information.
# Examples
## Example 1
Input: "东邵渠村村域面积多少平方千米?,东邵渠村有农户多少人?,1933年东邵渠村属于哪里?"
Output: "东邵渠村村域面积多少平方千米?,东邵渠村有农户多少人?,1933年东邵渠村属于哪里?", "东邵渠村村域面积,东邵渠村农户人数", "1933年东邵渠村所属地"
## Example 2
Input: "北京今天的天气怎么样?"
Output: "北京今天的天气怎么样?", "北京今天天气"
## Example 3
Input: "请介绍一下长城。长城是谁修建的?修建长城花了多少年?"
Output: "请介绍一下长城。长城是谁修建的?修建长城花了多少年?", "长城,长城修建者", "长城修建耗时"
## Example 4
Input: "2023年全球智能手机出货量排名前三的品牌有哪些?它们各自的市场份额是多少?"
Output: "2023年全球智能手机出货量排名前三的品牌有哪些?它们各自的市场份额是多少?", "2023年全球智能手机出货量排名前三品牌", "2023年全球智能手机出货量排名前三品牌市场份额"
# Output format
Separate identified questions with English commas, e.g., "Question1", "Question2", "Question3".Decompose user questions into multiple search keywords, use an iterative component to perform multiple knowledge retrievals, and merge the results for large‑model reasoning.
Problem Reasoning Prompt
# Role
You serve Zhuhai Paino Technology Co., Ltd. as a senior hardware selection and keyword extraction expert in the power industry. Your task is to accurately extract hardware product model numbers belonging to the company from knowledge‑base retrieval results.
# Task
Think step‑by‑step, strictly follow retrieval results, and extract only the company’s hardware model numbers without fabricating or mentioning other companies’ models.
# Special Requirements
1. **Knowledge boundary**: Use only information retrieved from the knowledge base.
- Allowed inference: logical relations between entries or compliance‑related extrapolation.
- Prohibited: speculation beyond the knowledge base or conflicting assumptions.
- If uncertain, explicitly state: "According to current knowledge base information..." or "Based on system records...".
2. If retrieval yields no results, reply: "No corresponding instrument model recommendation."
# Output format
Recommend model: [Product Model]
Include installation method, suggested price, applicable scenarios, and recommendation reason.
# Example (bold tags shown as HTML)
<strong>Recommend Model: [PMAC503M5]</strong>
<strong>Product Type</strong>: Combined electrical fire monitoring detector
<strong>Installation Method</strong>: Panel type
<strong>Guide Price</strong>: 600 CNY
<strong>Core Parameter Match</strong>: List
<strong>Recommendation Reason</strong>: List
<strong>Summary Advice</strong>: Table
<strong>Priority Recommendation</strong>: List
<strong>Note</strong>: If the budget is around 600 CNY and you accept marginal pricing, consider PMAC503M5 (600 CNY), but confirm whether the budget includes this price.Below is the completed Dify application DSL file (useful if you wish to support the assistant with a tip).
app:
description: I am a senior hardware selection expert in the power industry, able to answer user questions about our company's hardware selection.
icon: 🤖
icon_background: '#FFEAD5'
mode: advanced-chat
name: Hardware Selection Assistant
use_icon_as_answer_icon: false
dependencies:
- current_identifier: null
type: marketplace
value:
marketplace_plugin_unique_identifier: langgenius/xinference:0.0.2@04dee9c8396689421df7537f73ebb4b26efbcb7e0b9c32b7f09236e84bb97b3c
kind: app
version: 0.1.5
workflow:
conversation_variables:
- description: Summary table retrieval result
id: 5bf27886-0933-4694-bf60-05403e9ff374
name: summaryTableSearchResult
selector:
- conversation
- summaryTableSearchResult
value: ''
value_type: string
environment_variables: []
features:
file_upload:
allowed_file_extensions:
- .JPG
- .JPEG
- .PNG
- .GIF
- .WEBP
- .SVG
allowed_file_types:
- image
allowed_file_upload_methods:
- local_file
- remote_url
enabled: false
fileUploadConfig:
audio_file_size_limit: 50
batch_count_limit: 20
file_size_limit: 30
image_file_size_limit: 10
video_file_size_limit: 100
workflow_file_upload_limit: 10
image:
enabled: false
number_limits: 3
opening_statement: I am the hardware selection assistant, feel free to ask any hardware‑selection‑related questions~
retriever_resource:
enabled: true
suggested_questions_after_answer:
enabled: true
graph:
edges:
- data:
isInIteration: false
isInLoop: false
sourceType: llm
targetType: answer
id: 1746586688328-source-1751033873680-target
source: '1746586688328'
sourceHandle: source
target: '1751033873680'
targetHandle: target
type: custom
zIndex: 0
- data:
isInIteration: false
isInLoop: false
sourceType: start
targetType: llm
id: 1745306271727-source-1751759378018-target
source: '1745306271727'
sourceHandle: source
target: '1751759378018'
targetHandle: target
type: custom
zIndex: 0
- data:
isInIteration: false
isInLoop: false
sourceType: llm
targetType: code
id: 1751759378018-source-1751759437171-target
source: '1751759378018'
sourceHandle: source
target: '1751759437171'
targetHandle: target
type: custom
zIndex: 0
- data:
isInIteration: false
isInLoop: false
sourceType: code
targetType: iteration
id: 1751759437171-source-1751759510195-target
source: '1751759437171'
sourceHandle: source
target: '1751759510195'
targetHandle: target
type: custom
zIndex: 0
- data:
isInIteration: true
isInLoop: false
iteration_id: '1751759510195'
sourceType: iteration-start
targetType: knowledge-retrieval
id: 1751759510195start-source-1751759529746-target
source: 1751759510195start
sourceHandle: source
target: '1751759529746'
targetHandle: target
type: custom
zIndex: 1002
- data:
isInIteration: false
isInLoop: false
sourceType: iteration
targetType: if-else
id: 1751759510195-source-1751859350506-target
source: '1751759510195'
sourceHandle: source
target: '1751859350506'
targetHandle: target
type: custom
zIndex: 0
- data:
isInLoop: false
sourceType: if-else
targetType: llm
id: 1751859350506-true-1746586688328-target
source: '1751859350506'
sourceHandle: 'true'
target: '1746586688328'
targetHandle: target
type: custom
zIndex: 0
- data:
isInLoop: false
sourceType: if-else
targetType: answer
id: 1751859350506-false-1751859486474-target
source: '1751859350506'
sourceHandle: 'false'
target: '1751859486474'
targetHandle: target
type: custom
zIndex: 0
nodes:
- data:
desc: ''
selected: false
title: 开始
type: start
variables: []
height: 53
id: '1745306271727'
position:
x: 30
y: 290
positionAbsolute:
x: 30
y: 290
sourcePosition: right
targetPosition: left
width: 244
type: custom
- data:
context:
enabled: true
variable_selector:
- '1751759510195'
- output
desc: ''
memory:
query_prompt_template: 用户的原始问题为:{{#sys.query#}}
role_prefix:
assistant: ''
user: ''
window:
enabled: true
size: 70
model:
completion_params:
max_tokens: 21501
presence_penalty: 0
temperature: 0.3
mode: chat
name: QwQ-32B
provider: langgenius/xinference
prompt_template:
- id: f28da9ee-09a2-40ee-b786-c3b2df75eb69
role: system
text: "###角色
你服务于珠海派诺科技股份有限公司,是一名资深电力行业硬件产品选型专家与关键词提取专家,你需要准确的提取知识库检索结果中属于公司的硬件产品型号。
###任务
你要一步一步思考,严格根据检索结果进行回答,准确提取{{#context#}}中所有属于公司的硬件产品型号,不允许自己编造、假设进行推理,也不要提及其他公司的产品型号和不属于公司自身的产品型号,认真检查你的回答。
优先从关键参数中查找选型的指标参数,找出该知识分段中的产品型号名称相关的信息。
### 特殊要求
请严格遵循以下规则生成回答:
1. **知识边界限定**
- 仅使用从知识库中检索到的信息生成回答
- 允许以下两类推测:
① 基于知识库条目间的逻辑关系进行必要推断
② 对未明示的流程环节进行合规性推演
- 禁止事项:
✖ 超出知识库领域的外延猜测
✖ 与现有条款冲突的假设
如遇以下情况需明确声明:
• "根据当前知识库信息..."
• "依据系统记录显示..."
2. 如果从知识库中检索结果为空,请回复:无相应参数的仪表型号推荐。"
retry_config:
max_retries: 3
retry_enabled: false
retry_interval: 1000
selected: false
title: 提取总表检索出的型号
type: llm
variables: []
vision:
enabled: false
height: 89
id: '1746586688328'
position:
x: 1694
y: 290
positionAbsolute:
x: 1694
y: 290
sourcePosition: right
targetPosition: left
width: 244
type: custom
- data:
answer: '{{#1746586688328.text#}}'
desc: ''
selected: false
title: 直接回复
type: answer
variables: []
height: 104
id: '1751033873680'
position:
x: 1998
y: 290
positionAbsolute:
x: 1998
y: 290
sourcePosition: right
targetPosition: left
width: 244
type: custom
- data:
context:
enabled: true
variable_selector:
- sys
- query
desc: ''
model:
completion_params:
max_tokens: 19801
temperature: 0.8
mode: chat
name: QwQ-32B
provider: langgenius/xinference
prompt_template:
- id: 129cd57b-7cce-4a21-ae29-88afbb75fa0e
role: system
text: "# 角色
你是一位精通自然语言处理的文本分析专家。
# 任务
你的任务是准确地从用户输入的文本中提取每一个独立问题的核心名词和名词性短语。这些名词和短语应当能够抓住每个问题的关键信息(如主体、对象、时间、地点、属性等),并且组合起来能够反映原问题的核心查询意图。
# 输入
用户输入的文本:{{#sys.query#}}
# 处理步骤
1. **分割问题**: 首先,识别并分割输入文本中的每一个独立问题。
2. **识别核心**: 对于每一个问题,识别出构成问题核心意义的名词和名词性短语。
* 重点关注代表问题主体、对象、时间、地点、限定条件等的词语。
* 确保提取的词语组合起来能够反映原问题的核心查询意图。
* 针对电力相关的词语,如果用户输入表达不正确,希望可以利用大模型使用专业的词汇替换,但要能反映问题核心查询意图。比如:\"基波\" 和 \"谐波\",使用 \"谐波\" 更准确一点。
3. **过滤非核心**: 原则上,忽略疑问词(如\"多少\"、\"哪里\"、\"谁\"、\"什么\"、\"怎么样\"、\"吗\"等)、动词、助词、介词、连词以及形容词副词等修饰性成分,除非它们是构成核心名词短语不可或缺的一部分(例如,\"市场份额\"中的\"市场\")。
4. **格式化输出**: 按照指定的\"输出规范\"格式化提取结果。"
selected: false
title: 问题转换
type: llm
variables: []
vision:
enabled: false
height: 89
id: '1751759378018'
position:
x: 334
y: 290
positionAbsolute:
x: 334
y: 290
sourcePosition: right
targetPosition: left
width: 244
type: custom
- data:
code: "def main(input_str: str) -> dict:
if not input_str:
return {'result': []}
think_tag = '</think>'
if think_tag in input_str:
input_str = input_str.split(think_tag)[1].strip()
input_str = input_str.strip().strip('"')
items = [item.strip() for item in input_str.split(',')]
return {'result': items[:5]}"
code_language: python3
desc: ''
outputs:
result:
children: null
type: array[string]
selected: false
title: 转化成问题列表
type: code
variables:
- value_selector:
- '1751759378018'
- text
variable: input_str
height: 53
id: '1751759437171'
position:
x: 638
y: 290
positionAbsolute:
x: 638
y: 290
sourcePosition: right
targetPosition: left
width: 244
type: custom
- data:
answer: "⛄ **非常抱歉**:**当前知识库中无符合全部条件的型号**。<br/>❤️ **建议**:修改调整选型条件,把选型指标参数具体化后可以帮助你精准定位相应的型号哦!!<br/>⚠ **注意**:以上信息严格基于知识库现有记录,未包含任何假设或捏造内容。"
desc: ''
selected: false
title: 不存在回复
type: answer
variables: []
height: 197
id: '1751859486474'
position:
x: 1694
y: 420
positionAbsolute:
x: 1694
y: 420
sourcePosition: right
targetPosition: left
width: 244
type: custom
viewport:
x: 66.8979694212785
y: -38.4980634235485
zoom: 0.9649066181975102Architect's Alchemy Furnace
A comprehensive platform that combines Java development and architecture design, guaranteeing 100% original content. We explore the essence and philosophy of architecture and provide professional technical articles for aspiring architects.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
