匠人学院 JR Academy
  • Position

    Where am I now, and where should I go?

    How your job is changing, where your experience can take you and what you still need for a target role, worked out from what you have actually done. Free, and the full result needs no sign-up.

    Analyse my career and skills

    Look up a career

    Will AI replace my job?AI impact and transition paths for common careersNew jobs in the AI eraWhat they do, what they need, how to move in

    Focused tools

    AI Engineer interview readiness30 timed questions on what you still need before interviewsCareer personality testDirections that suit how you workReturning to China checkJob prospects in China by school, major and graduation date

    AI coach

    Talk to your AI coachStill unsure after your result? Talk through what is holding you back
  • Core courses

    AI Engineer BootcampEngineering bootcamp from LLM apps to agentsAI Engineer Full-Stack Project Class16 weeks · RAG and full-stack AI projectsVibe Coding Masterclass8 weeks · direct agents to build and ship a productAI Essentials10 hours · use AI for email, reports, data and copyAI Office Automation Course8 weeks · help a whole company adopt AIOne-Person Company (OPC) Bootcamp15 weeks in person · build a one-person company with AIAll courses →

    AI engineering

    Machine Learning & Data Engineering Full-Stack ClassAI Agent & MCP Project BootcampAI Engineer Core TechniquesAI Engineer FoundationsAI Engineer Advanced: RAG to Agents and TuningClaude Code TasterAll AI engineering courses →

    AI at work

    AI Coding for everyoneClaude Code One-Day Masterclass (Non-Technical)Enterprise AI Automation BootcampAI Marketing BootcampAI Risk, Governance and Audit CourseOpenClaw 4-Week Personal AI Assistant BootcampAll AI-at-work courses →

    Career development

    AI Product Manager (BA) Bootcamp + InternshipAustralia IT Interview BootcampAustralia IT Technical Interview BootcampAustralia IT Resume BootcampAustralia Big Tech Job Search BootcampAustralia IT Career Planning BootcampAll career courses →

    Learn free first

    Vibe CodingAI for office workPrompt MasterAI EngineerAI data analysisResource centerInstructorsAll learning paths →
  • Evidence

    What will convince an employer?

    Certifications, projects, team work and competition entries, collected into one portfolio.

    See the portfolio

    Certifications

    Cert Master · all certificationsPrep and mock exams for AWS, Azure, GCP, Claude and moreAWS CLF-C02Entry-level AWS cloud certificationAWS SAA-C03Entry certification for cloud architectsClaude certificationsAnthropic Claude certification seriesAll certifications →

    Projects and team work

    P3 team projectsBuild a project with real teammates in a simulated team workflowP3 project experienceThe parts of a P3 project that go on your resumeDemo DayProject showcaseP3 certificatesProof once a project is completeAll of P3 →

    Competitions and work

    HackathonsBuild something against the clockSubmit your workAdd your project to the showcaseCareerOS portfolioDo tasks in the desktop app; your results become portfolio pieces
    Cert MasterBrowser extension, app and mini programScreenshot a question for analysis and practise anywhereAbout Cert Master
  • Connect

    How do I get myself in front of employers?

    Resume, interviews, referrals and mentors. See how far you are from the target role first, then decide what to fix.

    Start with Jobpin

    Resume and openings

    Graduate careersGraduate preparation across Australia, China, Malaysia, Singapore, the US and UKJobpinAI job search workspace: resume, roles, applicationsAI resumeRewrite your resume against a job descriptionReferralsRoles shared by students and mentorsOpportunitiesInternships, projects and collaborationsOffer boardOffers students have received

    Interviews

    AI Engineer interview guideSeven areas, with worked examplesFDE interview guideFive rounds, from scoping to the customer roundAI mock interviewPractise by text or voice and see the gapsInterview storiesReal interview experiencesSystem Design handbookPrepare for system design interviewsAll interview prep →

    Mentors

    1:1 mentorsBook AI, career and technical mentors by the hourGroup tutoringShare a tutor with a few others and pay less eachCareer coachingResume, interview and direction packages
    Jobpin desktopOne workspace for the whole job searchOrganise real experience and refine resume versions for target roles on macOS or Windows.About Jobpin
BusinessMembershipDownload CareerOS
0
匠人学院 JR Academy

Follow Us

linkedinfacebooktwitterinstagramyoutube

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png
Airbotix · AI learning & creation for kids Another Life · AI story game
Products46

CareerOS and tools

  • CareerOS
  • Cert Master
  • Jobpin
  • Jobpin web
  • Jobpin report
  • Jobpin desktop download
  • My job search reports
  • Buy report credits
  • Jobpin billing
  • AI Toolbox
  • AI Skill Marketplace

Membership

  • Membership
  • AI membership

Courses

  • Bootcamps
  • Training Camp
  • Kanban learning
  • AI Builder course
  • MCP course
  • NotebookLM workshop
  • Business Analyst course
  • Web Full-Stack Bootcamp
  • DevOps Bootcamp
  • Data Engineering Bootcamp
  • Data Analysis Bootcamp
  • Coding for Beginners
  • Algorithm Bootcamp

Career services

  • Graduate careers
  • Graduate careers in Australia
  • Graduate careers in China
  • Graduate careers in Malaysia
  • Graduate careers in Singapore
  • Graduate careers in the US
  • Graduate careers in the UK
  • 1:1 coaching
  • Career coaching
  • AI Engineer VIP
  • BA & PM Internship
  • Data Science Internship
  • Data Analysis Internship
  • Marketing Internship
  • Resume Review
  • Interview Coaching
  • Job Application Service
  • Job Monitoring
  • LinkedIn Management
  • LinkedIn Networking
Library57

Learning paths

  • All Learning Paths
  • AI Engineer
  • Context Engineering
  • Vibe Coding
  • Prompt Master
  • AI Builder
  • AI Product Manager
  • Python Basics
  • AI Productivity
  • AI Data Analysis
  • AI Finance
  • AI Content Creation
  • AI Image Creation
  • Frontend Development
  • Hermes Agent
  • OpenClaw Local Agent

Interactive labs

  • Prompt Lab
  • Frontend Lab
  • JavaScript Lab
  • Python Lab
  • AWS Lab
  • Azure Lab
  • LLM Lab
  • Git Lab

Reference and guides

  • Resources
  • Wiki
  • Cheat sheets
  • Roadmaps
  • AI roadmaps
  • Videos
  • Ebooks
  • Blog
  • Interview handbook
  • Mock exams
  • Free resources

Cities

  • Sydney
  • Melbourne
  • Brisbane
  • Adelaide
  • Singapore
  • Kuala Lumpur
  • London
  • New York
  • San Francisco
  • Los Angeles
  • Seattle
  • Toronto
  • Vancouver

Immigration

  • Australia Immigration
  • Skilled Visa 189/190/491
  • Employer Sponsored 482/186/494
  • Business Visa 188/888
  • UK Immigration
  • US Immigration
  • Canada Immigration
  • Singapore immigration
  • Malaysia immigration
Business20

For business

  • AI for Business
  • Business portal sign-in
  • Corporate Training
  • Internship Partnership
  • Recruitment Partnership
  • Enterprise (EN)

Metatree AI Lab

  • Metatree AI Lab (Chinese)
  • AI solutions (Chinese)
  • Digital employees (Chinese)
  • Case studies (Chinese)
  • Metatree AI Lab
  • AI services
  • Digital employees
  • Case studies

AI education for kids

  • Airbotix — AI Learning & Creation for Kids
  • AU Family Resource Hub
  • NAPLAN Report Guide
  • My School Data Guide
  • Sydney Private School Fees 2026
  • Kids Coding Programs
About15

Company

  • About Us
  • Our Mentors
  • Become a Mentor
  • Metaverse Classroom
  • JR Careers
  • Another Life — AI Story Game
  • Contact Us

Help and policies

  • FAQs
  • Terms & Conditions
  • Privacy Policy
  • Cancellation & Refund Policy
  • Site map

Friend links

  • CS Browser

Contact

  • hello@jiangren.com.au
  • 0421-672-555

Offices

Level 10b, 144 Edward Street, Brisbane CBD (Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
45A13, Block B, Oriental Hope Tianxiang Plaza, 500 Tianfu Avenue Middle Section, Wuhou District, Chengdu, Sichuan, China
Business Hub, 155 Waymouth St, Adelaide SA 5000
Disclaimer
footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

All content on the JR Academy website, including course materials, logos, and information provided, is protected under Australian intellectual property laws. Unauthorized use, sale, distribution, reproduction, or modification is strictly prohibited. Violations may result in legal action. By accessing our website, you agree to respect our intellectual property. JR Academy Pty Ltd reserves all rights, including patents, trademarks, and copyrights. Any infringement will be subject to legal prosecution. View Terms of Service

© 2017-2026 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572

HomeLearnCoursesCerts
  1. Home
  2. Learn
  3. Blog
  4. Dify 实战手册:用可视化拖拽搭建 AI 应用 — Dify RAG 知识库实战:分块策略、检索调优与 reranking
JR Academy · BlogCareer insights

Dify 实战手册:用可视化拖拽搭建 AI 应用 — Dify RAG 知识库实战:分块策略、检索调优与 reranking

三种分块模式(通用/父子/Q&A)的选择逻辑、向量与混合检索参数调优、reranker 接入与 TopK 配置——系统性把召回率从 60% 拉到 90%+

Published2026-12-01
Reading time2 min
Author

Contents

  • RAG 管道的五个阶段
  • 分块模式:三选一,选错就从头来
  • 通用模式(General)
  • 父子模式(Parent-Child)— Dify v0.15.0+
  • Q&A 模式
  • 索引质量:High Quality vs Economy
  • 检索模式配置
  • 三种检索模式
  • TopK 和 Score Threshold
  • Reranking:召回率的最后一关
  • 可选的 Reranker 模型
  • Reranker 调用流程
  • 实战调优流程
  • 第一步:确认内容在知识库里
  • 第二步:看召回块是否包含答案
  • 第三步:针对文档类型选分块策略
  • 第四步:调整参数组合
  • 几个容易踩的坑

很多人上传完文档,测试几条问题,发现回答驴唇不对马嘴,就把锅甩给大模型。其实多半是知识库配错了。Dify RAG 管道有七八个配置点,任何一个没调好都会影响最终质量。这章把每个参数讲清楚,顺带给一个调优流程。

Dify hybrid search and rerank architecture

RAG 管道的五个阶段

先建一个心智模型,知道问题出在哪一层才能对症下药:

文档上传 → 分块 (Chunking) → 向量化 (Indexing) → 检索 (Retrieval) → 重排 (Reranking) → 生成 (Generation)

分块决定你存进去的信息粒度,检索决定能召回什么,reranking 决定送给模型的是不是真正相关的内容。三个环节相互影响,不能只盯着一个。


分块模式:三选一,选错就从头来

分块结构一旦保存无法修改。上传文档前想清楚用哪种模式,改错了只能删掉重传。

通用模式(General)

默认选项,适合大多数场景:产品文档、新闻、博客、说明书。按分隔符(换行、段落)切块,可以指定最大块长度(通常 512-1000 token)和重叠长度(overlap,通常 50-100 token)。

段落 A(1000 token)
  ↓ 切割
块 1: 第 1-512 token
块 2: 第 462-974 token  ← 50 token 重叠确保上下文连续
块 3: 第 924-1000 token

overlap 不要设 0。没有重叠时,切块边界处的信息很容易被两个块各分走一半,单独看都不完整。通常设总块长的 10%。

父子模式(Parent-Child)— Dify v0.15.0+

父子模式解决的是"精准匹配"和"上下文丰富"的矛盾。

  • 子块(Child chunk):小,几十到一两百 token,用于向量相似度匹配——短文本的 embedding 更精准
  • 父块(Parent chunk):大,几百 token 或整篇文档,检索命中后送给 LLM——保留足够上下文

工作流程:用户问题 → 和子块做相似度匹配 → 找到子块 → 返回对应的父块给模型。

两种父块策略:

  • 段落模式:按段落分父块,父块相对独立,适合有清晰段落结构的技术文档
  • 全文档模式:整个文档作为一个父块,适合内容密度高、前后关联强的合同、报告

父子模式只支持 High Quality 索引,不支持 Economy 模式。

Q&A 模式

文档上传后,Dify 用 LLM 自动从每个段落生成若干问答对,存储的不是原文而是问答对。检索时用用户问题和这些预生成问题做匹配。

适合场景非常具体:FAQ 文档、产品客服知识库、帮助中心。用户通常直接问"怎么退货""发货多久"这类问题,和预生成问题的相似度非常高,召回精度远高于通用模式。

不适合:技术文档、合同文本、需要综合多个段落来回答的问题。

Q&A 模式只支持 High Quality,而且处理成本比通用模式高很多——每个段落都要调一次 LLM 生成问答对。文档量大的时候算一下 token 消耗再决定。


索引质量:High Quality vs Economy

High Quality Economy
索引方式 调用 embedding 模型向量化 倒排索引(关键词)
检索精度 高,理解语义 低,只做关键词匹配
成本 按 token 计费 免费
支持的检索模式 向量 / 全文 / 混合 仅全文
支持父子/Q&A 模式 ✅ ❌

生产环境没有理由用 Economy。Embedding 的成本不高——1MB 的文档用 text-embedding-3-small 处理大概花几美分。Economy 存在是给本地测试用的。


检索模式配置

三种检索模式

向量检索(Vector Search):把用户问题也向量化,计算和文档块的余弦相似度,返回语义最接近的块。能处理同义词和表达方式不同的情况,但对专有名词、产品型号这类需要精确匹配的词效果不好。

全文检索(Full-text Search):BM25 算法,关键词匹配。对 SKU、命令名称、专有名词精准,但不理解语义。

混合检索(Hybrid Search):两者都跑,结果合并后排序。生产环境默认选混合,几乎总比单一模式强。

混合检索有个权重参数 α(通常 0-1),控制向量分数和全文分数的比重:

final_score = α × vector_score + (1 - α) × keyword_score
  • α = 1:纯向量
  • α = 0:纯关键词
  • α = 0.5:各占一半(默认,大多数场景合适)

文档里专有名词多、精确查询多的场景把 α 调低;通用问答场景 α = 0.5 或稍高。

TopK 和 Score Threshold

TopK:检索阶段返回多少个块送给下游(reranker 或直接给 LLM)。默认通常是 5。

TopK 不是越大越好:

  • 太小:漏掉相关内容
  • 太大:送给 LLM 的 context 里噪声变多,而且吃 token

经验值:混合检索 TopK 设 5-10,如果接了 reranker 可以设 15-20 让 reranker 从更多候选里挑。

Score Threshold:低于这个分数的块直接过滤掉,不送给 LLM。

用 Score Threshold 要小心——设太高容易什么都检索不到。建议先把 threshold 设 0(不过滤),观察检索到的块的分数分布,再决定合理的下限。


Reranking:召回率的最后一关

Reranker 是一个独立的评分模型,接受(用户问题, 候选块)对,重新打分并排序,输出真正相关的 Top N 给 LLM。

它解决的问题:向量相似度不等于实际相关性。两段话向量很近,但未必都能回答当前问题。Reranker 做的是精排,代价是计算量更大,只适合在 TopK 候选集上跑。

可选的 Reranker 模型

Cohere Rerank 3:商业 API,精度高,直接在 Dify 模型设置里填 API key 接入。对英文效果最好,中文效果也可以接受。按每次 rerank 调用的文档数计费。

BGE Reranker(BAAI/bge-reranker-v2-m3):开源模型,中英双语,可以自部署在 Ollama 或 vLLM 上,自部署后没有 API 费用。中文场景优先考虑这个。

Dify 里接入 BGE Reranker 的配置示意:

# 在 Dify 模型提供商里添加自部署 rerank 端点
model_type: rerank
model: BAAI/bge-reranker-v2-m3
endpoint: http://your-server:8080/rerank  # vLLM 或 xinference 部署

接入后在知识库的检索设置里勾选「启用 Reranking」,选择对应模型,设置:

  • Rerank TopK:从候选里最终保留多少个块给 LLM(通常 3-5)
  • Score Threshold:reranker 分数低于此值的块丢弃(可选)

Reranker 调用流程

用户问题
    ↓
混合检索 → TopK=15 个候选块
    ↓
Reranker 对 15 个候选重打分
    ↓
按 Reranker 分数排序,取 Top 5
    ↓
送给 LLM 生成答案

检索 TopK 设大(15-20),Reranker TopK 设小(3-5),让精排模型承担过滤职责。


实战调优流程

遇到知识库回答质量差,不要乱调参数,按这个顺序排查:

第一步:确认内容在知识库里

在知识库页面直接搜索关键词,看有没有召回结果。没有召回说明分块出了问题,或者文档根本没被正确解析(PDF 的图片内容、扫描件默认无法提取文字)。

# Dify 支持测试检索,在知识库详情页 → 召回测试
# 输入用户的问题,观察返回的块和分数

第二步:看召回块是否包含答案

召回了内容,但回答还是不对,看一下召回的块里有没有答案。

  • 有答案但没用:LLM 忽略了相关内容,可能是 context 太长、噪声太多,降低 TopK 或开启 reranker
  • 没有答案:分块切得太碎把相关信息分散了,换父子模式,或者调大块长度

第三步:针对文档类型选分块策略

文档类型 推荐分块模式 推荐检索模式
产品 FAQ / 帮助中心 Q&A 模式 向量或混合
技术文档(有层级结构) 父子模式(段落) 混合 + Reranker
合同 / 长报告 父子模式(全文档) 混合 + Reranker
新闻 / 博客文章 通用模式 混合
产品目录 / 含 SKU 通用模式 混合,α 偏向关键词

第四步:调整参数组合

一个在大多数场景表现稳定的配置:

分块模式: 父子模式(段落)
索引质量: High Quality
检索模式: 混合检索,α=0.5
检索 TopK: 15
Reranker: BGE-reranker-v2-m3(中文场景)或 Cohere Rerank 3(英文场景)
Reranker TopK: 5
Score Threshold: 0.3(先跑几轮再调)

这不是最优解,是个稳健的起点。根据你的文档类型和问答模式,每个参数都可能需要调整。


几个容易踩的坑

分块后不能改模式:选错了只能删重传,大文档要重新 embedding,代价不小。第一次上传小样本测试清楚再批量导入。

PDF 扫描件无法检索:扫描 PDF 里的文字是图片,Dify 默认不做 OCR。要么换成文字版 PDF,要么用支持 OCR 的 parser(Dify 的知识管道里可以配置)。

Reranker 和 Embedding 要语言匹配:用了中文 embedding 模型(比如 text-embedding-3-small 支持多语言),但 Reranker 选了只支持英文的版本,中文结果排序会乱。中文场景 Reranker 用 BGE 或 Cohere v3(支持多语言)。

知识库版本和应用绑定:一个知识库可以绑定多个 Dify 应用,更新文档后所有绑定的应用都会受影响。生产环境的知识库更新前先在测试应用里验证。

父子模式的索引成本:父子模式存了子块又存父块,索引存储量是通用模式的 2 倍左右。不是成本问题,但向量数据库容量要留余量。

Author
Share or copy the link

Related learning resources

  • AI Engineer learning path
← Previous articleDify 实战手册:用可视化拖拽搭建 AI 应用 — Dify 常见问题 FAQ:定价、踩坑和选型建议Next article →Dify 实战手册:用可视化拖拽搭建 AI 应用 — Dify 自部署完整指南:Docker Compose + Nginx 反向代理 + HTTPS

Related articles

USYD 医疗初创盘点、网络平台注意义务法案、全身 MRI 广告研究

2026-12-02

UQ 皮肤癌在线硕士开办 20 周年、中澳绿色钢铁对话、HIV 预防提醒

2026-12-02

UNSW iFire 2.3 火场模拟系统、AI 卵巢癌预后研究、艺术家与 AI 版权调查

2026-12-02

ANS-C01 退役倒计时 29 天 · AIB-C01 Beta $50 新认证上线 · MLA-C02 Beta 报名开放

2026-12-02

Amazon开放首个自研大模型Ergo,代理作弊率实测差距悬殊,Anthropic格密码结果暂无现实威胁

2026-12-02

GitHub Copilot 实战指南 — Copilot AI Code Review:30 秒让 AI 帮你审 PR,三档深度随需切换

2026-12-01
View all articles →

Done reading? Next steps

Not sure what to learn next? Tell us where you are

Tell us what you do now and where you want to go. See your gaps in skills, evidence, experience, expression and positioning, and what to work on first. No sign-in needed.

Compare with my situation
  • SkillAI Engineer Bootcamp13 weeks, 12 Theory + 13 Practice live classes. You build one Agent system across Context, RAG, Tools, Memory and production Evals. Built for Applied AI and Agent Engineer roles.See the program →
  • PositioningLearning roadmaps by roleFrontend, backend, data, AI and more, laid out stage by stage in the order to learn them.All roadmaps →
  • ExpressionTry an AI mock interviewPick a role and run a mock interview to practise explaining your experience and projects.Practise now →

Not sure what to do next?

Take this page's topic with you and see where your gaps are.

Compare with my situation
JR Academy
AI learning for the global Chinese community
BootcampsFree resourcesLearn AICareer coaching
精选推荐
AI Career Impact Map
Assess career exposure and explore transition paths and learning options
Popular tool
AI & Data Bootcamps
Build your skills through structured courses and hands-on projects
Popular courses
1:1 Career Coaching
Work with an experienced mentor on your resume and interview preparation
Career coaching
Custom Corporate Training
AI training tailored to your team
Business services
Popular tags
Vibe CodingAI codingCursorClaudeJob searchPromptFrontend developmentBackend development
Subscribe to updates

Receive AI learning resources, technical tutorials and career advice by email.

We respect your privacy and do not send spam.