作者:微信小助手
<section> <span leaf="">随着这几年 AI 数字人的兴起,前端需要通过一些工具来更生动的展示这些虚拟人角色。</span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">live2D 就是先进的二维动画技术,能够在前端网页中实现高度逼真的角色动画效果。</span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">它是</span></span><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">日本公司开发的,主要还是动画风格。</span></span><span leaf=""><span textstyle="" style="font-size: 17px;">核心技术是:</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">基于多层次的2D绘制,通过对角色进行分割并赋予不同部位独立的动作能力,实现角色的自由变形和动态效果。</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">官方文档:</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">https://www.live2d.com/zh-CHS/learn/sample/</span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><br></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">需要模型文件:</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">准备一个 Live2D 模型文件,通常是以.moc或.moc3等格式存储的。这些文件包含了角色的图形和骨架信息。</span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><strong style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: -apple-system, BlinkMacSystemFont, " segoe ui, roboto, ubuntu, helvetica neue, helvetica, arial, pingfang sc, hiragino sans gb, microsoft yahei yahei, source han cn, sans-serif, apple color emoji, segoe ui emoji;list-style: none;margin: 0px;scrollbar-width: none;font-weight: 600;color: rgb(6, 7, 31);font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; data-pm-slice="0 0 []"><span leaf="">下面就是Live2D 模型文件</span></strong><span style="color: rgb(6, 7, 31);font-family: PingFang-SC-Regular;font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none;"><span leaf="">,具体来说是一个基于 Cubism 4 SDK 的</span></span><code style="box-sizing: border-box;padding: 1px 4px;-webkit-font-smoothing: antialiased;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;list-style: none;margin: 0px 2px;scrollbar-width: none;font-size: 12.75px;tab-size: 4;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;color: rgb(6, 7, 31);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">.model3.json</span></code><span style="color: rgb(6, 7, 31);font-family: PingFang-SC-Regular;font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none;"><span leaf="">文件,</span><span style="color: rgb(6, 7, 31);font-family: PingFang-SC-Regular;font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none;" data-pm-slice="0 0 []"><span leaf="">描述了 3D 模型的参数、纹理、骨骼绑定等信息。</span></span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">https://cdn.jsdelivr.net/gh/guansss/pixi-live2d-display/test/assets/haru/haru_greeter_t03.model3.json</span></span></span> </section> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="json"><code><span leaf=""><span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Version"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__number">3</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"FileReferences"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Moc"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"haru_greeter_t03.moc3"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Textures"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">[</span></span></code><code><span leaf=""> <span class="code-snippet__string">"haru_greeter_t03.2048/texture_00.png"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__string">"haru_greeter_t03.2048/texture_01.png"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">],</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Physics"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"haru_greeter_t03.physics3.json"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Pose"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"haru_greeter_t03.pose3.json"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"DisplayInfo"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"haru_greeter_t03.cdi3.json"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Expressions"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">[</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"f00"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"expressions/F01.exp3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"f01"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"expressions/F02.exp3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"f02"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"expressions/F03.exp3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"f03"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"expressions/F04.exp3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"f04"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"expressions/F05.exp3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"f05"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"expressions/F06.exp3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"f06"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"expressions/F07.exp3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"f07"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"expressions/F08.exp3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">}</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">],</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Motions"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Idle"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">[</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"motion/haru_g_idle.motion3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"motion/haru_g_m07.motion3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"motion/haru_g_m15.motion3.json"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">}</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">],</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Tap"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">[</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"motion/haru_g_m14.motion3.json"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Sound"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"../shizuku/sounds/flickHead_00.mp3"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"File"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"motion/haru_g_m05.motion3.json"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Sound"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"../shizuku/sounds/flickHead_01.mp3"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">}</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">]</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">}</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Groups"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">[</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Target"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"Parameter"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"EyeBlink"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Ids"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">[</span></span></code><code><span leaf=""> <span class="code-snippet__string">"ParamEyeLOpen"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__string">"ParamEyeROpen"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">]</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Target"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"Parameter"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"LipSync"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Ids"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">[</span></span></code><code><span leaf=""> <span class="code-snippet__string">"ParamMouthOpenY"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">]</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">}</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">],</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"HitAreas"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">[</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Id"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"HitArea"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"Head"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">},</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Id"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"HitArea2"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Name"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"Body"</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">}</span></span></code><code><span leaf=""> <span class="code-snippet__punctuation">]</span></span></code><code><span leaf=""><span class="code-snippet__punctuation">}</span></span></code></pre> </section> <section> <span leaf=""><br></span> </section> <section> <span leaf="">下面我们一一解析下:</span> </section> <p style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: none;margin: 0px;scrollbar-width: none;font-size: 15px;line-height: 1.7;color: rgb(6, 7, 31);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" data-pm-slice="0 0 []"><code style="box-sizing: border-box;padding: 1px 4px;-webkit-font-smoothing: antialiased;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;list-style: none;margin: 0px 2px;scrollbar-width: none;font-size: 12.75px;tab-size: 4;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;><span leaf="">.model3.json</span></code><span leaf="">文件通常包含以下关键部分:</span></p> <ul style="box-sizing: border-box;padding: 0px 0px 0px 30px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: outside none disc;margin: 14px 0px 1em;scrollbar-width: none;font-size: 15px;line-height: 1.7;color: rgb(6, 7, 31);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"></ul> <section> <span leaf="">模型版本信息:</span> </section> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="json"><code><span leaf=""><span class="code-snippet__attr">"Version"</span><span class="code-snippet__punctuation">:</span><span class="code-snippet__number">3</span></span></code></pre> </section> <section> <span leaf="">该模型基于 Cubism 4 SDK 生成。</span> </section> <ul style="box-sizing: border-box;padding: 0px 0px 0px 30px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: outside none disc;margin: 14px 0px 1em;scrollbar-width: none;font-size: 15px;line-height: 1.7;color: rgb(6, 7, 31);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"> <li style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: none;margin: 0px;scrollbar-width: none;font-size: 15px;line-height: 1.7;"> <section> <span leaf="" data-pm-slice="1 1 [" list,{type:ul,style:box-sizing: border-box;padding: 0px 30px;-webkit-font-smoothing: antialiased;font-family: pingfang-sc-regular;list-style: outside none disc;margin: 14px 1em;scrollbar-width: none;font-size: 15px;line-height: 1.7;color: rgb(6, 7, 31);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;,class:list-paddingleft-1},listitem,{style:box-sizing: 0px;-webkit-font-smoothing: none;margin: 0px;scrollbar-width: 1.7;},para,{tagname:section,attributes:{},namespaceuri:http: www.w3.org 1999 xhtml}]><br></span> </section></li> </ul> <section> <span leaf="">文件引用:</span> </section> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="json"><code><span leaf=""><span class="code-snippet__attr">"FileReferences"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">{</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Moc"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__string">"haru_**.moc3"</span><span class="code-snippet__punctuation">,</span></span></code><code><span leaf=""> <span class="code-snippet__attr">"Textures"</span><span class="code-snippet__punctuation">:</span> <span class="code-snippet__punctuation">[</span><span class="code-snippet__string">"haru_**.1024/texture_00.png"</span><span class="code-snippet__punctuation">]</span></span></code><code><span leaf=""><span class="code-snippet__punctuation">}</span></span></code></pre> </section> <ul style="list-style-type: disc;" class="list-paddingleft-1"> <li> <section> <span leaf=""><span textstyle="" style="font-size: 14px;">Moc 指向 .moc3 文件,包含模型的骨骼动画数据</span></span> </section></li> <li> <section> <span leaf=""><span textstyle="" style="font-size: 14px;">Textures 指向纹理图片,用于渲染模型外观</span></span> </section> <section> <span leaf=""><br></span> </section></li> </ul> <section> <span leaf="">参数和部件:</span> </section> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="javascript"><code><span leaf=""><span class="code-snippet__string">"Parameters"</span>: { ... },</span></code><code><span leaf=""><span class="code-snippet__string">"Parts"</span>: { ... }</span></code></pre> </section> <ul style="box-sizing: border-box;padding: 0px 0px 0px 30px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: outside none disc;margin: 14px 0px 1em;scrollbar-width: none;font-size: 15px;line-height: 1.7;color: rgb(6, 7, 31);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"> <li> <section> <span leaf="">Parameters 定义模型的变形参数</span> </section></li> <li> <section> <span leaf="">Parts 定义模型的部件结构(头发等)</span> </section></li> <li style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: none;margin: 6px 0px 0px;scrollbar-width: none;font-size: 15px;line-height: 1.7;"><p style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: none;margin: 0px;scrollbar-width: none;font-size: 15px;line-height: 1.7;display: inline;"><strong style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: -apple-system, BlinkMacSystemFont, " segoe ui, roboto, ubuntu, helvetica neue, helvetica, arial, pingfang sc, hiragino sans gb, microsoft yahei yahei, source han cn, sans-serif, apple color emoji, segoe ui emoji;list-style: none;margin: 0px;scrollbar-width: none;font-weight: 600;><span leaf=""><br></span></strong></p></li> </ul> <section> <span style="font-weight: bold;"><span leaf=""><br></span></span> </section> <section> <span leaf=""> 物理设置:</span> </section> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="javascript"><code><span leaf=""><span class="code-snippet__string">"Physics"</span>: { ... }</span></code></pre> </section> <ul style="box-sizing: border-box;padding: 0px 0px 0px 30px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: outside none disc;margin: 14px 0px 1em;scrollbar-width: none;font-size: 15px;line-height: 1.7;color: rgb(6, 7, 31);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"> <li style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: none;margin: 6px 0px 0px;scrollbar-width: none;font-size: 15px;line-height: 1.7;"> <section> <span leaf="" data-pm-slice="1 1 [" list,{type:ul,style:box-sizing: border-box;padding: 0px 30px;-webkit-font-smoothing: antialiased;font-family: pingfang-sc-regular;list-style: outside none disc;margin: 14px 1em;scrollbar-width: none;font-size: 15px;line-height: 1.7;color: rgb(6, 7, 31);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;,class:list-paddingleft-1},listitem,{style:box-sizing: 0px;-webkit-font-smoothing: none;margin: 6px 0px;scrollbar-width: 1.7;},para,{tagname:section,attributes:{},namespaceuri:http: www.w3.org 1999 xhtml}]>描述模型的物理特性(如重力)</span> </section></li> </ul> <section> <span style="font-weight: bold;"><span leaf=""><span textstyle="" style="font-size: 17px;"> </span></span></span> </section> <section> <span style="font-weight: bold;"><span leaf=""><span textstyle="" style="font-size: 17px;">表达式和动作:</span></span></span> </section> <ul style="list-style-type: disc;" class="list-paddingleft-1"> <li style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: none;margin: 6px 0px 0px;scrollbar-width: none;font-size: 15px;line-height: 1.7;"> <section> <span leaf="">Expressions</span> </section></li> <li style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: none;margin: 6px 0px 0px;scrollbar-width: none;font-size: 15px;line-height: 1.7;"> <section> <span leaf="">定义表情数据</span> </section></li> <li style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: none;margin: 6px 0px 0px;scrollbar-width: none;font-size: 15px;line-height: 1.7;"> <section> <span leaf="">Motions</span> </section></li> <li style="box-sizing: border-box;padding: 0px;-webkit-font-smoothing: antialiased;font-family: PingFang-SC-Regular;list-style: none;margin: 6px 0px 0px;scrollbar-width: none;font-size: 15px;line-height: 1.7;"> <section> <span leaf="">定义动作数据</span> </section> <section> <span style="font-family: -apple-system, BlinkMacSystemFont, " segoe ui, roboto, ubuntu, helvetica neue, helvetica, arial, pingfang sc, hiragino sans gb, microsoft yahei yahei, source han cn, sans-serif, apple color emoji, segoe ui emoji;font-weight: 600;><span leaf=""><br></span></span> </section></li> </ul> <section> <span leaf=""><br></span> </section> <section> <span leaf=""><br></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">SDK 的选择:</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">pixijs 的版本 </span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">https://github.com/guansss/pixi-live2d-display</span></span></span> </section> <section style="text-align: center;" nodeleaf=""> <img class="rich_pages wxw-img" data-imgfileid="503119406" data-ratio="0.4" data-s="300,640" src="/upload/baf1fda81b45c00e781d26e130607b8e.png" data-type="png" data-w="1080" type="block"> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><br></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">它有多个版本:</span></span></span> </section> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="javascript"><code><span leaf=""><span class="code-snippet__keyword">import</span> { <span class="code-snippet__title">Live2DModel</span> } <span class="code-snippet__keyword">from</span> <span class="code-snippet__string">'pixi-live2d-display'</span>;</span></code><code><span leaf=""><span class="code-snippet__comment">// 如果只需要 Cubism 2.1</span></span></code><code><span leaf=""><span class="code-snippet__keyword">import</span> { <span class="code-snippet__title">Live2DModel</span> } <span class="code-snippet__keyword">from</span> <span class="code-snippet__string">'pixi-live2d-display/cubism2'</span>;</span></code><code><span leaf=""><span class="code-snippet__comment">// 如果只需要 Cubism 4</span></span></code><code><span leaf=""><span class="code-snippet__keyword">import</span> { <span class="code-snippet__title">Live2DModel</span> } <span class="code-snippet__keyword">from</span> <span class="code-snippet__string">'pixi-live2d-display/cubism4'</span>;</span></code></pre> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><br></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">调用方式:</span> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="javascript"><code><span leaf=""><span class="code-snippet__keyword">import</span> { </span></code><code><span leaf=""> <span class="code-snippet__title">Live2DModel</span></span></code><code><span leaf="">} <span class="code-snippet__keyword">from</span><span class="code-snippet__string">'pixi-live2d-display'</span>;</span></code><code><span leaf=""><br></span></code><code><span leaf=""><span class="code-snippet__keyword">const</span> model = <span class="code-snippet__keyword">await</span> <span class="code-snippet__title">Live2DModel</span>.<span class="code-snippet__title">from</span>(<span class="code-snippet__string">'**.model.json'</span>);</span></code></pre> </section></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><code style="box-sizing: border-box;padding: 1px 4px;-webkit-font-smoothing: antialiased;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;list-style: none;margin: 0px 2px;scrollbar-width: none;font-size: 12.75px;tab-size: 4;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;color: rgb(6, 7, 31);font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; data-pm-slice="0 0 []"><span leaf="">Live2DModel.from()</span></code><span style="color: rgb(6, 7, 31);font-family: PingFang-SC-Regular;font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none;"><span leaf="">方法加载模型文件。</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">那如何把</span><span style="color: rgb(6, 7, 31);font-family: PingFang-SC-Regular;font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none;" data-pm-slice="0 0 []"><span leaf="">模型添加到 PixiJS 舞台进行渲染</span></span></span></span> </section> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="javascript"><code><span leaf=""><span class="code-snippet__keyword">import</span> * <span class="code-snippet__keyword">as</span> <span class="code-snippet__variable">PIXI</span> <span class="code-snippet__keyword">from</span> <span class="code-snippet__string">'pixi.js'</span>;</span></code><code><span leaf=""><span class="code-snippet__keyword">const</span> app = <span class="code-snippet__keyword">new</span> <span class="code-snippet__variable">PIXI</span>.<span class="code-snippet__title">Application</span>({</span></code><code><span leaf=""> <span class="code-snippet__attr">view</span>: <span class="code-snippet__variable">document</span>.<span class="code-snippet__title">getElementById</span>(<span class="code-snippet__string">'canvas'</span>),</span></code><code><span leaf="">});</span></code><code><span leaf=""><br></span></code><code><span leaf="">app.<span class="code-snippet__property">stage</span>.<span class="code-snippet__title">addChild</span>(model);</span></code></pre> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(6, 7, 31);font-family: PingFang-SC-Regular;font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(253, 253, 254);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none;" data-pm-slice="0 0 []"><span leaf=""><br></span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">还支持</span><span textstyle="" style="font-size: 17px;font-weight: bold;">嘴型同步</span><span textstyle="" style="font-size: 17px;">功能</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">官方文档:</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">https://docs.live2d.com/en/cubism-editor-manual/motion-sync/</span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(37, 41, 51);font-family: -apple-system, system-ui, " segoe ui, roboto, ubuntu, cantarell, noto sans, sans-serif, system-ui, helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei, arial;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">很多简单的方式:通过不同播放中的音频的声调大小来控制口型的开合程度</span></span></span></span> </section> <section> <span leaf="">比如可以通过 py 的 </span><span style="color: rgb(37, 41, 51);font-family: -apple-system, system-ui, " segoe ui, roboto, ubuntu, cantarell, noto sans, sans-serif, system-ui, helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei, arial;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">librosa 这种工具</span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-size: 17px;">相关文档:</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">https://github.com/Live2D/CubismWebMotionSyncComponents</span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><br></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">当然也有一些项目可以参考:</span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(37, 41, 51);font-family: -apple-system, system-ui, " segoe ui, roboto, ubuntu, cantarell, noto sans, sans-serif, system-ui, helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei, arial;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">通过一些算法提取音频流的信息,在每一帧中不断的分析,得到设置口型开合的大小以及设置最接近的元音口型</span></span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">https://github.com/liyao1520/live2d-motionSync</span></span></span> </section> <section> <span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgb(25, 26, 36);font-family: -apple-system, " system-ui, sf pro sc, text, helvetica neue, helvetica, pingfang segoe ui, roboto, hiragino sans gb, arial, microsoft yahei yahei, simsun, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><br></span></span></span> </section> <p style="display: none;"> <mp-style-type data-value="3"></mp-style-type></p>
作者:微信小助手
<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="padding: 0 10px;line-height: 1.6;word-spacing: 0px;word-break: break-word;word-wrap: break-word;text-align: left;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-left: 5px;padding-right: 5px;padding-top: 0px;margin-top: 0px;" data-pm-slice="0 0 []"> <section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="padding: 0 10px;line-height: 1.6;word-spacing: 0px;word-break: break-word;word-wrap: break-word;text-align: left;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-left: 5px;padding-right: 5px;padding-top: 0px;margin-top: 0px;" data-pm-slice="0 0 []"> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">这篇文章,我们聊聊 四种实时通信技术:短轮询、长轮询、WebSocket 和 SSE 。</span></p> <h1 data-tool="mdnice编辑器" style="padding: 0px;font-weight: bold;color: black;font-size: 24px;text-align: center;margin-top: 35px;margin-bottom: 20px;"><span style="display: none;"></span><span style="font-size: 16px;color: rgb(234, 84, 41);letter-spacing: 0.5444px;padding-bottom: 10px;border-bottom: 2px solid rgb(234, 84, 41);"><span leaf="">1 短轮询</span></span></h1> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">浏览器 </span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">定时</span></strong><span leaf="">(如每秒)向服务器发送 HTTP 请求,服务器立即返回当前数据(无论是否有更新)。</span></p> <figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img src="/upload/e590b6de7d124b1581715b899a916b78.png" class="rich_pages wxw-img" data-ratio="0.32314814814814813" data-type="png" data-w="1080" style="display: block;margin: 0 auto;max-width: 100%;margin-bottom: 15px;" data-imgfileid="100036469"></span> </figure> <ul style="margin-top: 8px;color: black;list-style-type: square;padding-left: 1.2em;margin-bottom: 20px;" class="list-paddingleft-1"> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">优点</span></strong><span leaf="">:实现简单,兼容性极佳</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">缺点</span></strong><span leaf="">:高频请求浪费资源,实时性差(依赖轮询间隔)</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">延迟</span></strong><span leaf="">:高(取决于轮询频率)</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">适用场景</span></strong><span leaf="">:兼容性要求高,延迟不敏感的简单场景。</span> </section></li> </ul> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">笔者职业生涯印象最深刻的短轮询应用场景是</span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">比分直播</span></strong><span leaf="">:</span></p> <figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img src="/upload/52f7582f717f97c65bcacb97e5339aca.png" class="rich_pages wxw-img" data-ratio="0.10185185185185185" data-type="png" data-w="1080" style="display: block;margin: 0 auto;max-width: 100%;margin-bottom: 15px;" data-imgfileid="100036467"></span> </figure> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">如图所示,用户进入比分直播界面,浏览器定时查询赛事信息(比分变动、黄红牌等),假如数据有变化,则重新渲染页面。</span></p> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">这种方式实现起来非常简单可靠,但是频繁的调用后端接口,会对后端性能会有影响(主要是 CPU)。同时,因为依赖轮询间隔,页面数据变化有延迟,用户体验并不算太好。</span></p> <h1 data-tool="mdnice编辑器" style="padding: 0px;font-weight: bold;color: black;font-size: 24px;text-align: center;margin-top: 35px;margin-bottom: 20px;"><span style="display: none;"></span><span style="font-size: 16px;color: rgb(234, 84, 41);letter-spacing: 0.5444px;padding-bottom: 10px;border-bottom: 2px solid rgb(234, 84, 41);"><span leaf="">2 长轮询</span></span></h1> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">浏览器发送 HTTP 请求后,服务器 </span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">挂起连接</span></strong><span leaf=""> 直到数据更新或超时,返回响应后浏览器立即发起新请求。</span></p> <figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img src="/upload/9cc41c56f42110d5e7d0350323d89b5a.png" class="rich_pages wxw-img" data-ratio="0.3212962962962963" data-type="png" data-w="1080" style="display: block;margin: 0 auto;max-width: 100%;margin-bottom: 15px;" data-imgfileid="100036470"></span> </figure> <ul style="margin-top: 8px;color: black;list-style-type: square;padding-left: 1.2em;margin-bottom: 20px;" class="list-paddingleft-1"> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">优点</span></strong><span leaf="">:减少无效请求,比短轮询实时性更好</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">缺点</span></strong><span leaf="">:服务器需维护挂起连接,高并发时资源消耗大</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">延迟</span></strong><span leaf="">:中(取决于数据更新频率)</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">适用场景</span></strong><span leaf="">:需要较好实时性且无法用 WebSocket/SSE 的场景(如消息通知)</span> </section></li> </ul> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">长轮询最常见的应用场景是:配置中心,我们耳熟能详的注册中心 Nacos 、阿波罗都是依赖长轮询机制。</span></p> <figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img src="/upload/d0f44b9b10c9c5200fbf602e7c9bcb43.png" alt="nacos长轮询" class="rich_pages wxw-img" data-ratio="0.48143236074270557" data-type="other" data-w="754" style="display: block;margin: 0 auto;max-width: 100%;margin-bottom: 15px;" data-imgfileid="100036466"></span> <figcaption style="margin-top: 5px;text-align: center;color: #888;font-size: 14px;"> <span leaf="">Nacos长轮询</span> </figcaption> </figure> <blockquote style="border: none;display: block;font-size: 0.9em;overflow: auto;overflow-scrolling: touch;color: #6a737d;padding-top: 10px;padding-bottom: 10px;padding-left: 20px;padding-right: 10px;border-left: 2px solid #888;padding: 8px 10px 8px 15px;background: rgb(255, 249, 249);border-left-color: rgb(239, 112, 96);margin-top: 0px;margin-bottom: 10px;letter-spacing: 0.5444px;"> <p style="text-align: justify;padding-top: 0px;padding-bottom: 0px;margin: 0px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 14px;margin-bottom: 10px;color: rgb(74,74,74);line-height: 30px;letter-spacing: 0.5444px;"><span leaf="">客户端发起请求后,Nacos 服务端不会立即返回请求结果,而是将请求挂起等待一段时间,如果此段时间内服务端数据变更,立即响应客户端请求,若是一直无变化则等到指定的超时时间后响应请求,客户端重新发起长轮询。</span></p> </blockquote> <h1 data-tool="mdnice编辑器" style="padding: 0px;font-weight: bold;color: black;font-size: 24px;text-align: center;margin-top: 35px;margin-bottom: 20px;"><span style="display: none;"></span><span style="font-size: 16px;color: rgb(234, 84, 41);letter-spacing: 0.5444px;padding-bottom: 10px;border-bottom: 2px solid rgb(234, 84, 41);"><span leaf="">3 WebSocket</span></span></h1> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">基于 TCP 的全双工协议,通过 HTTP 升级握手(</span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(234, 84, 41);"><span leaf="">Upgrade: websocket</span></code></strong><span leaf="">)建立持久连接(</span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">双向实时通信)。</span></strong><span leaf=""><img src="/upload/91b66fadf53a24312b84d654a82eb87a.png" alt="image.png" class="rich_pages wxw-img" data-ratio="0.32222222222222224" data-type="png" data-w="1080" style="display: block;margin: 0 auto;max-width: 100%;margin-bottom: 15px;" data-imgfileid="100036468"></span></p> <ul style="margin-top: 8px;color: black;list-style-type: square;padding-left: 1.2em;margin-bottom: 20px;" class="list-paddingleft-1"> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">优点</span></strong><span leaf="">:最低延迟,支持双向交互,节省带宽</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">缺点</span></strong><span leaf="">:实现复杂,需单独处理连接状态</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">延迟</span></strong><span leaf="">:极低</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">适用场景</span></strong><span leaf="">:聊天室、在线游戏、协同编辑等 </span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">高实时双向交互</span></strong><span leaf=""> 需求</span> </section></li> </ul> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">笔者曾经服务于北京一家电商公司,参与直播答题功能的研发。</span></p> </section> <section style="text-align: center;" nodeleaf=""> <img src="/upload/2a6c78e28130bf8403c8857331fa313d.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.47058823529411764" data-s="300,640" data-type="png" data-w="952" type="block" data-imgfileid="100036475"> </section> <section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="padding: 0 10px;line-height: 1.6;word-spacing: 0px;word-break: break-word;word-wrap: break-word;text-align: left;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-left: 5px;padding-right: 5px;padding-top: 0px;margin-top: 0px;" data-pm-slice="0 0 []"> <figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><br></span> </figure> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">直播答题整体架构见下图:</span></p> <figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100036474" data-ratio="0.7300469483568075" src="/upload/b39d1516c918b962aee29555840b2e8f.png" data-type="png" data-w="852" style=";"></span> </figure> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">TCP 网关的技术选型是:Netty、ProtoBuf、WebSocket ,选择 WebSocket 是因为它支持双向实时通信,同时 Netty 内置了 WebSocket 实现类,工程实现起来相对简单。</span></p> <h1 data-tool="mdnice编辑器" style="padding: 0px;font-weight: bold;color: black;font-size: 24px;text-align: center;margin-top: 35px;margin-bottom: 20px;"><span style="display: none;"></span><span style="font-size: 16px;color: rgb(234, 84, 41);letter-spacing: 0.5444px;padding-bottom: 10px;border-bottom: 2px solid rgb(234, 84, 41);"><span leaf="">4 Server Send Event(SSE)</span></span></h1> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">基于 HTTP 协议,服务器可 </span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">主动推送</span></strong><span leaf=""> 数据流(如</span><code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(234, 84, 41);"><span leaf="">Content-Type: text/event-stream</span></code><span leaf="">),浏览器通过</span><code style="font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(234, 84, 41);"><span leaf="">EventSource</span></code><span leaf=""> API 监听。</span></p> <figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img src="/upload/b3abdb2a5cb86aea49ec06eef023d607.png" class="rich_pages wxw-img" data-ratio="0.32037037037037036" data-type="png" data-w="1080" style="display: block;margin: 0 auto;max-width: 100%;margin-bottom: 15px;" data-imgfileid="100036473"></span> </figure> <ul style="margin-top: 8px;color: black;list-style-type: square;padding-left: 1.2em;margin-bottom: 20px;" class="list-paddingleft-1"> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">优点</span></strong><span leaf="">:原生支持断线重连,轻量级(HTTP协议)</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">缺点</span></strong><span leaf="">:单向通信(服务端--》客户端),低版本 IE 浏览器不支持</span> </section><span data-lark-record-data="{" rootid:rrkndkuqponoczxkqrccfajunkg,text:{initialattributedtexts:{text:{0:单向通信(服务端--》客户端),低版本 ie 浏览器不支持},attribs:{0:*0+t}},apool:{numtoattrib:{0:[author,7258839859043844124]},nextnum:1}},type:text,referencerecordmap:{},extra:{channel:saas,isequalblockselection:false,pasterandomid:31c65345-4dc8-4768-a601-439223fc6de5,mention_page_title:{},external_mention_url:{}},iskeepquotecontainer:false,isfromcode:false,selection:[{id:40,type:text,selection:{start:3,end:32},recordid:wbtjd3hlzosftfxjhz4ckah5nid}],payloadmap:{},iscut:false} data-lark-record-format="docx/text"></span></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">延迟</span></strong><span leaf="">:低(服务器可即时推送)</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">适用场景</span></strong><span leaf="">:股票行情、实时日志等 </span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">服务器单向推送</span></strong><span leaf=""> 需求。</span> </section></li> </ul> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">SSE 最经典的应用场景是 : DeepSeek web 聊天界面 ,如图所示:</span></p> <figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img src="/upload/1ca1744b86e53ce34bc952a8588cb69f.png" class="rich_pages wxw-img" data-ratio="0.23422159887798036" data-type="png" data-w="713" style="display: block;margin: 0 auto;max-width: 100%;margin-bottom: 15px;" data-imgfileid="100036471"></span> </figure> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><span leaf="">当在 DeepSeek 对话框发送消息后,浏览器会发送一个 HTTP 请求 ,服务端会通过 SSE 方式将数据返回到浏览器。</span></p> <figure data-tool="mdnice编辑器" style="margin: 0;margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img src="/upload/c6e9b1715bc167440ea042345f4b23e5.png" class="rich_pages wxw-img" data-ratio="0.528957528957529" data-type="png" data-w="1036" style="display: block;margin: 0 auto;max-width: 100%;margin-bottom: 15px;" data-imgfileid="100036472"></span> </figure> <h1 data-tool="mdnice编辑器" style="padding: 0px;font-weight: bold;color: black;font-size: 24px;text-align: center;margin-top: 35px;margin-bottom: 20px;"><span style="display: none;"></span><span style="font-size: 16px;color: rgb(234, 84, 41);letter-spacing: 0.5444px;padding-bottom: 10px;border-bottom: 2px solid rgb(234, 84, 41);"><span leaf="">5 总结</span></span></h1> <section data-tool="mdnice编辑器" style="overflow-x: auto;"> <table style="display:table;text-align:left;min-width:249px;"> <thead> <tr style="border: 0;border-top: 1px solid #ccc;background-color: white;"> <th style="font-size: 16px;padding: 5px 10px;text-align: left;font-weight: bold;border: 1px solid #009688;background-color: #009688;color: #f8f8f8;border-bottom: 0;min-width: 85px;"><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">特性</span></strong></th> <th style="font-size: 16px;padding: 5px 10px;text-align: left;font-weight: bold;border: 1px solid #009688;background-color: #009688;color: #f8f8f8;border-bottom: 0;min-width: 85px;"><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">短轮询</span></strong></th> <th style="font-size: 16px;padding: 5px 10px;text-align: left;font-weight: bold;border: 1px solid #009688;background-color: #009688;color: #f8f8f8;border-bottom: 0;min-width: 85px;"><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">长轮询</span></strong></th> <th style="font-size: 16px;padding: 5px 10px;text-align: left;font-weight: bold;border: 1px solid #009688;background-color: #009688;color: #f8f8f8;border-bottom: 0;min-width: 85px;"><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">SSE</span></strong></th> <th data-colwidth="149" style="font-size: 16px;padding: 5px 10px;text-align: left;font-weight: bold;border: 1px solid #009688;background-color: #009688;color: #f8f8f8;border-bottom: 0;min-width: 85px;"><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">WebSocket</span></strong></th> </tr> </thead> <tbody> <tr style="border: 0;border-top: 1px solid #ccc;background-color: #f8f8f8;"> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">协议</span></strong></td> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">HTTP</span> </section></td> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">HTTP</span> </section></td> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">HTTP</span> </section></td> <td data-colwidth="149" style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">WebSocket(基于TCP)</span> </section></td> </tr> <tr style="border: 0;border-top: 1px solid #ccc;background-color: white;"> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">实时性</span></strong></td> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">低</span> </section></td> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">中</span> </section></td> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">高</span> </section></td> <td data-colwidth="149" style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">极高</span> </section></td> </tr> <tr style="border: 0;border-top: 1px solid #ccc;background-color: #f8f8f8;"> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">资源消耗</span></strong></td> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">高(频繁请求)</span> </section></td> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">中(挂起连接)</span> </section></td> <td style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">低</span> </section></td> <td data-colwidth="149" style="font-size: 16px;padding: 5px 10px;text-align: left;border: 1px solid #009688;min-width: 85px;"> <section> <span leaf="">低(长连接)</span> </section></td> </tr> </tbody> </table> </section> <p data-tool="mdnice编辑器" style="margin: 0;text-align: justify;line-height: 30px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 15px;color: rgb(74,74,74);letter-spacing: 0.5444px;padding-top: 0px;padding-bottom: 0px;margin-bottom: 20px;"><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">选择建议</span></strong><span leaf="">:</span></p> <ul style="margin-top: 8px;color: black;list-style-type: square;padding-left: 1.2em;margin-bottom: 20px;" class="list-paddingleft-1"> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <span leaf="">需要 </span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">简单兼容性</span></strong><span leaf=""> → 短轮询</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <span leaf="">需要 </span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">中等实时性</span></strong><span leaf=""> → 长轮询</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <span leaf="">只需 </span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">服务器推送</span></strong><span leaf=""> → SSE</span> </section></li> <li> <section style="text-align: left;font-weight: 500;margin-top: 0px;margin-bottom: 10px;line-height: 25px;font-family: 'Avenir, -apple-system-font, 微软雅黑, sans-serif';font-size: 16px;color: #4A4A4A;letter-spacing: 0.5444px;"> <span leaf="">需要 </span><strong style="color: #222222;font-weight: bold;letter-spacing: 0.5444px;"><span leaf="">全双工实时交互</span></strong><span leaf=""> → WebSocket</span> </section></li> </ul> </section> </section> <figure data-tool="mdnice编辑器" style="-webkit-tap-highlight-color: transparent;margin: 10px 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgb(74, 74, 74);font-family: " avenir, -apple-system-font, 微软雅黑, sans-serif;font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.5444px;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: flex;flex-direction: column;justify-content: center;align-items: center; data-pm-slice="0 0 []"></figure> <figure data-tool="mdnice编辑器" style="-webkit-tap-highlight-color: transparent;margin: 10px 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgb(74, 74, 74);font-family: " avenir, -apple-system-font, 微软雅黑, sans-serif;font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.5444px;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: flex;flex-direction: column;justify-content: center;align-items: center;></figure>
作者:微信小助手
<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 10px;padding-right: 10px;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;font-family: Optima, 'Microsoft YaHei', PingFangSC-regular, serif;font-size: 16px;color: rgb(0, 0, 0);line-height: 1.5em;word-spacing: 0em;letter-spacing: 0em;word-break: break-word;overflow-wrap: break-word;text-align: left;" data-pm-slice="0 0 []"> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在分布式架构中,MySQL与Elasticsearch(ES)的协同已成为解决高并发查询与复杂检索的标配组合。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">然而,如何实现两者间的高效数据同步,是架构设计中绕不开的难题。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这篇文章跟大家一起聊聊MySQL同步ES的6种主流方案,结合代码示例与场景案例,帮助开发者避开常见陷阱,做出最优技术选型。</span></p> <section class="mp_profile_iframe_wrp" data-pm-slice="0 0 []" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;orphans: 2;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;color: rgba(0, 0, 0, 0.9);font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;font-size: 17px;letter-spacing: 0.544px;text-align: justify;background-color: rgb(255, 255, 255);> <span data-pm-slice="0 0 []" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgba(0, 0, 0, 0.55);font-family: PingFangSC-regular, sans-serif;font-size: 15px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: left;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;float: none;display: inline !important;"><span leaf="" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span textstyle="" style="font-weight: bold;">最近建了一些工作内推群,各大城市都有,欢迎各位HR和找工作的小伙伴进群交流,群里目前已经收集了不少的工作内推岗位。加苏三的微信:li_su223,备注:所在城市,即可进群。</span></span></span> </section> <section nodeleaf="" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;orphans: 2;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;color: rgba(0, 0, 0, 0.9);font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;font-size: 17px;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);text-align: center;> <img src="/upload/81d24f4b6540ebdccbb6659ca7fb7468.jpg" alt="图片" class="rich_pages wxw-img" data-ratio="1.3324607329842932" data-s="300,640" data-type="jpeg" data-w="764" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;vertical-align: bottom;height: auto !important;width: 179px !important;visibility: visible !important;" type="block" data-imgfileid="100042697"> </section> <h2 data-cacheurl="" data-remoteid="" data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-left: 0px;padding-right: 0px;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 50%;background-position-y: 50%;background-repeat: no-repeat;background-size: 63px;width: auto;height: auto;align-items: unset;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;text-align: left;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvztmgbxh6ndrwtxb8xsoevtqgdjqyq1gwdoegwplibehbcr3hwdazoo47lgv2tqbljfnygkekckg 640?wx_fmt="png&from=appmsg");""><span style="display: none;"></span><span style="font-size: 18px;color: rgb(72, 179, 120);line-height: 2.4em;letter-spacing: 0em;margin-top: 38px;margin-bottom: 10px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: 38px;justify-content: unset;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: center;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">方案一:同步双写</span></span><span style="display: none;"></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">场景</span></strong><span leaf="">:适用于对数据实时性要求极高,且业务逻辑简单的场景,如金融交易记录同步。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在业务代码中同时写入MySQL与ES。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">代码如下:</span></p> <pre data-tool="mdnice编辑器" style="border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;text-align: left;margin-top: 10px;margin-bottom: 10px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;"><span data-cacheurl="" data-remoteid="" style="display: block;background: none;height: 30px;width: 100%;background-size: 40px;background-repeat: no-repeat;background-color: #282c34;margin-bottom: -7px;border-radius: 5px;background-position: 10px 10px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg wzjhlvpsrd1bfxruh2q6pljiamcu9ys8j7uzf3uvf2fmmkicdrdpynytbneic03cayv2tviapaxpmu4fmexxkd0a8v3hoawcz7nz 640?wx_fmt="svg&from=appmsg");""></span><code style="overflow-x: auto;padding: 16px;color: #abb2bf;padding-top: 15px;background: #282c34;border-radius: 5px;display: -webkit-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;"><span style="color: #61aeee;line-height: 26px;"><span leaf="">@Transactional</span></span><span leaf=""> </span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">public</span></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">void</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">createOrder</span></span><span style="line-height: 26px;"><span leaf="">(Order order)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 写入MySQL </span></span><span leaf=""><br></span><span leaf=""> orderMapper.insert(order); </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 同步写入ES </span></span><span leaf=""><br></span><span leaf=""> IndexRequest request = </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">new</span></span><span leaf=""> IndexRequest(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"orders"</span></span><span leaf="">) </span><span leaf=""><br></span><span leaf=""> .id(order.getId()) </span><span leaf=""><br></span><span leaf=""> .source(JSON.toJSONString(order), XContentType.JSON); </span><span leaf=""><br></span><span leaf=""> client.index(request, RequestOptions.DEFAULT); </span><span leaf=""><br></span><span leaf="">}</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">痛点</span></strong><span leaf="">:</span></p> <ol style="list-style-type: decimal;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">硬编码侵入</span></strong><span leaf="">:所有涉及写操作的地方均需添加ES写入逻辑。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">性能瓶颈</span></strong><span leaf="">:双写操作导致事务时间延长,TPS下降30%以上。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">数据一致性风险</span></strong><span leaf="">:若ES写入失败,需引入补偿机制(如本地事务表+定时重试)。</span> </section></li> </ol> <h2 data-cacheurl="" data-remoteid="" data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-left: 0px;padding-right: 0px;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 50%;background-position-y: 50%;background-repeat: no-repeat;background-size: 63px;width: auto;height: auto;align-items: unset;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;text-align: left;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvztmgbxh6ndrwtxb8xsoevtqgdjqyq1gwdoegwplibehbcr3hwdazoo47lgv2tqbljfnygkekckg 640?wx_fmt="png&from=appmsg");""><span style="display: none;"></span><span style="font-size: 18px;color: rgb(72, 179, 120);line-height: 2.4em;letter-spacing: 0em;margin-top: 38px;margin-bottom: 10px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: 38px;justify-content: unset;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: center;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">方案二:异步双写</span></span><span style="display: none;"></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">场景</span></strong><span leaf="">:电商订单状态更新后需同步至ES供客服系统检索。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">我们可以使用MQ进行解耦。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">架构图如下</span></strong><span leaf="">:</span></p> <figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img src="/upload/a1fdc509cb9286c8a422a552ab7e5321.png" class="rich_pages wxw-img" data-ratio="0.7168539325842697" data-type="png" data-w="445" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100044243"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">代码示例如下</span></strong><span leaf="">:</span></p> <pre data-tool="mdnice编辑器" style="border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;text-align: left;margin-top: 10px;margin-bottom: 10px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;"><span data-cacheurl="" data-remoteid="" style="display: block;background: none;height: 30px;width: 100%;background-size: 40px;background-repeat: no-repeat;background-color: #282c34;margin-bottom: -7px;border-radius: 5px;background-position: 10px 10px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg wzjhlvpsrd1bfxruh2q6pljiamcu9ys8j7uzf3uvf2fmmkicdrdpynytbneic03cayv2tviapaxpmu4fmexxkd0a8v3hoawcz7nz 640?wx_fmt="svg&from=appmsg");""></span><code style="overflow-x: auto;padding: 16px;color: #abb2bf;padding-top: 15px;background: #282c34;border-radius: 5px;display: -webkit-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;"><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 生产者端 </span></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">public</span></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">void</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">updateProduct</span></span><span style="line-height: 26px;"><span leaf="">(Product product)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> productMapper.update(product); </span><span leaf=""><br></span><span leaf=""> kafkaTemplate.send(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"product-update"</span></span><span leaf="">, product.getId()); </span><span leaf=""><br></span><span leaf="">} </span><span leaf=""><br></span><span leaf=""><br></span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 消费者端 </span></span><span leaf=""><br></span><span style="color: #61aeee;line-height: 26px;"><span leaf="">@KafkaListener</span></span><span leaf="">(topics = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"product-update"</span></span><span leaf="">) </span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">public</span></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">void</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">syncToEs</span></span><span style="line-height: 26px;"><span leaf="">(String productId)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> Product product = productMapper.selectById(productId); </span><span leaf=""><br></span><span leaf=""> esClient.index(product); </span><span leaf=""><br></span><span leaf="">}</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">优势</span></strong><span leaf="">:</span></p> <ul style="list-style-type: disc;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">吞吐量提升:通过MQ削峰填谷,可承载万级QPS。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">故障隔离:ES宕机不影响主业务链路。</span> </section></li> </ul> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">缺陷</span></strong><span leaf="">:</span></p> <ul style="list-style-type: disc;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">消息堆积</span></strong><span leaf="">:突发流量可能导致消费延迟(需监控Lag值)。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">顺序性问题</span></strong><span leaf="">:需通过分区键保证同一数据的顺序消费。</span> </section></li> </ul> <h2 data-cacheurl="" data-remoteid="" data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-left: 0px;padding-right: 0px;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 50%;background-position-y: 50%;background-repeat: no-repeat;background-size: 63px;width: auto;height: auto;align-items: unset;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;text-align: left;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvztmgbxh6ndrwtxb8xsoevtqgdjqyq1gwdoegwplibehbcr3hwdazoo47lgv2tqbljfnygkekckg 640?wx_fmt="png&from=appmsg");""><span style="display: none;"></span><span style="font-size: 18px;color: rgb(72, 179, 120);line-height: 2.4em;letter-spacing: 0em;margin-top: 38px;margin-bottom: 10px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: 38px;justify-content: unset;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: center;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">方案三:Logstash定时拉取</span></span><span style="display: none;"></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">场景</span></strong><span leaf="">:用户行为日志的T+1分析场景。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">该方案低侵入但高延迟。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">配置示例如下</span></strong><span leaf="">:</span></p> <pre data-tool="mdnice编辑器" style="border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;text-align: left;margin-top: 10px;margin-bottom: 10px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;"><span data-cacheurl="" data-remoteid="" style="display: block;background: none;height: 30px;width: 100%;background-size: 40px;background-repeat: no-repeat;background-color: #282c34;margin-bottom: -7px;border-radius: 5px;background-position: 10px 10px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg wzjhlvpsrd1bfxruh2q6pljiamcu9ys8j7uzf3uvf2fmmkicdrdpynytbneic03cayv2tviapaxpmu4fmexxkd0a8v3hoawcz7nz 640?wx_fmt="svg&from=appmsg");""></span><code style="overflow-x: auto;padding: 16px;color: #abb2bf;padding-top: 15px;background: #282c34;border-radius: 5px;display: -webkit-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;"><span style="color: #98c379;line-height: 26px;"><span leaf="">input</span></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">jdbc</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">jdbc_driver</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">=></span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"com.mysql.jdbc.Driver"</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">jdbc_url</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">=></span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"jdbc:mysql://localhost:3306/log_db"</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">schedule</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">=></span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"*/5 * * * *"</span></span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 每5分钟执行 </span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">statement</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">=></span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"SELECT * FROM user_log WHERE update_time > :sql_last_value"</span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">}</span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">}</span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">output</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">elasticsearch</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">hosts</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">=></span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">["es-host:9200"]</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">index</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">=></span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user_logs"</span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">}</span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">}</span></span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">适用性分析</span></strong><span leaf="">:</span></p> <ul style="list-style-type: disc;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">优点</span></strong><span leaf="">:零代码改造,适合历史数据迁移。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">致命伤</span></strong><span leaf="">:</span> </section></li> <ul style="list-style-type: disc;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">分钟级延迟(无法满足实时搜索)</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">全表扫描压力大(需优化增量字段索引)</span> </section></li> </ul> </ul> <h2 data-cacheurl="" data-remoteid="" data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-left: 0px;padding-right: 0px;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 50%;background-position-y: 50%;background-repeat: no-repeat;background-size: 63px;width: auto;height: auto;align-items: unset;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;text-align: left;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvztmgbxh6ndrwtxb8xsoevtqgdjqyq1gwdoegwplibehbcr3hwdazoo47lgv2tqbljfnygkekckg 640?wx_fmt="png&from=appmsg");""><span style="display: none;"></span><span style="font-size: 18px;color: rgb(72, 179, 120);line-height: 2.4em;letter-spacing: 0em;margin-top: 38px;margin-bottom: 10px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: 38px;justify-content: unset;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: center;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">方案四:Canal监听Binlog</span></span><span style="display: none;"></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">场景</span></strong><span leaf="">:社交平台动态实时搜索(如微博热搜更新)。</span><span leaf=""><br></span><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">技术栈</span></strong><span leaf="">:Canal + RocketMQ + ES</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">该方案高实时,并且低侵入。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">架构流程如下</span></strong><span leaf="">:</span></p> <figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><img src="/upload/f86e6a59e00c35d2c1619cf27f86f249.png" class="rich_pages wxw-img" data-ratio="0.4111111111111111" data-type="png" data-w="990" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100044242"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">关键配置</span></strong><span leaf="">:</span></p> <pre data-tool="mdnice编辑器" style="border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;text-align: left;margin-top: 10px;margin-bottom: 10px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;"><span data-cacheurl="" data-remoteid="" style="display: block;background: none;height: 30px;width: 100%;background-size: 40px;background-repeat: no-repeat;background-color: #282c34;margin-bottom: -7px;border-radius: 5px;background-position: 10px 10px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg wzjhlvpsrd1bfxruh2q6pljiamcu9ys8j7uzf3uvf2fmmkicdrdpynytbneic03cayv2tviapaxpmu4fmexxkd0a8v3hoawcz7nz 640?wx_fmt="svg&from=appmsg");""></span><code style="overflow-x: auto;padding: 16px;color: #abb2bf;padding-top: 15px;background: #282c34;border-radius: 5px;display: -webkit-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;"><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># canal.properties </span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">canal.instance.master.address=127.0.0.1:3306</span></span><span leaf=""> </span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">canal.mq.topic=canal.es.sync</span></span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">避坑指南</span></strong><span leaf="">:</span></p> <ol style="list-style-type: decimal;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">数据漂移</span></strong><span leaf="">:需处理DDL变更(通过Schema Registry管理映射)。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">幂等消费</span></strong><span leaf="">:通过</span><code style="background-attachment: scroll;background-clip: border-box;background-color: rgba(27, 31, 35, 0.05);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 2px;margin-right: 2px;padding-top: 2px;padding-bottom: 2px;padding-left: 4px;padding-right: 4px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;overflow-wrap: break-word;font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace;word-break: break-all;"><span leaf="">_id</span></code><span leaf="">唯一键避免重复写入。</span> </section></li> </ol> <h2 data-cacheurl="" data-remoteid="" data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-left: 0px;padding-right: 0px;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 50%;background-position-y: 50%;background-repeat: no-repeat;background-size: 63px;width: auto;height: auto;align-items: unset;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;text-align: left;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvztmgbxh6ndrwtxb8xsoevtqgdjqyq1gwdoegwplibehbcr3hwdazoo47lgv2tqbljfnygkekckg 640?wx_fmt="png&from=appmsg");""><span style="display: none;"></span><span style="font-size: 18px;color: rgb(72, 179, 120);line-height: 2.4em;letter-spacing: 0em;margin-top: 38px;margin-bottom: 10px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: 38px;justify-content: unset;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: center;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">方案五:DataX批量同步</span></span><span style="display: none;"></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">场景</span></strong><span leaf="">:将历史订单数据从分库分表MySQL迁移至ES。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">该方案是大数据迁移的首选。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">配置文件如下</span></strong><span leaf="">:</span></p> <pre data-tool="mdnice编辑器" style="border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;text-align: left;margin-top: 10px;margin-bottom: 10px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;"><span data-cacheurl="" data-remoteid="" style="display: block;background: none;height: 30px;width: 100%;background-size: 40px;background-repeat: no-repeat;background-color: #282c34;margin-bottom: -7px;border-radius: 5px;background-position: 10px 10px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg wzjhlvpsrd1bfxruh2q6pljiamcu9ys8j7uzf3uvf2fmmkicdrdpynytbneic03cayv2tviapaxpmu4fmexxkd0a8v3hoawcz7nz 640?wx_fmt="svg&from=appmsg");""></span><code style="overflow-x: auto;padding: 16px;color: #abb2bf;padding-top: 15px;background: #282c34;border-radius: 5px;display: -webkit-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;"><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span leaf=""> </span><span leaf=""><br></span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"job":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"content":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">[{</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"reader":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"name":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"mysqlreader"</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">,</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"parameter":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"splitPk":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"id"</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">,</span></span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"querySql":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"SELECT * FROM orders"</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">}</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">},</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"writer":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"name":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"elasticsearchwriter"</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">,</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"parameter":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">{</span></span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"endpoint":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"http://es-host:9200"</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">,</span></span><span style="color: #d19a66;line-height: 26px;"><span leaf="">"index":</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"orders"</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">}</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">}</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">}]</span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">}</span></span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">}</span></span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">性能调优</span></strong><span leaf="">:</span></p> <ul style="list-style-type: disc;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">调整</span><code style="background-attachment: scroll;background-clip: border-box;background-color: rgba(27, 31, 35, 0.05);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 2px;margin-right: 2px;padding-top: 2px;padding-bottom: 2px;padding-left: 4px;padding-right: 4px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;overflow-wrap: break-word;font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace;word-break: break-all;"><span leaf="">channel</span></code><span leaf="">数提升并发(建议与分片数对齐)</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">启用</span><code style="background-attachment: scroll;background-clip: border-box;background-color: rgba(27, 31, 35, 0.05);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 2px;margin-right: 2px;padding-top: 2px;padding-bottom: 2px;padding-left: 4px;padding-right: 4px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;overflow-wrap: break-word;font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace;word-break: break-all;"><span leaf="">limit</span></code><span leaf="">分批查询避免OOM</span> </section></li> </ul> <h2 data-cacheurl="" data-remoteid="" data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-left: 0px;padding-right: 0px;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 50%;background-position-y: 50%;background-repeat: no-repeat;background-size: 63px;width: auto;height: auto;align-items: unset;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;text-align: left;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvztmgbxh6ndrwtxb8xsoevtqgdjqyq1gwdoegwplibehbcr3hwdazoo47lgv2tqbljfnygkekckg 640?wx_fmt="png&from=appmsg");""><span style="display: none;"></span><span style="font-size: 18px;color: rgb(72, 179, 120);line-height: 2.4em;letter-spacing: 0em;margin-top: 38px;margin-bottom: 10px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: 38px;justify-content: unset;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: center;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">方案六:Flink流处理</span></span><span style="display: none;"></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">场景</span></strong><span leaf="">:商品价格变更时,需关联用户画像计算实时推荐评分。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">该方案适合于复杂的ETL场景。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">代码片段如下</span></strong><span leaf="">:</span></p> <pre data-tool="mdnice编辑器" style="border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;text-align: left;margin-top: 10px;margin-bottom: 10px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;"><span data-cacheurl="" data-remoteid="" style="display: block;background: none;height: 30px;width: 100%;background-size: 40px;background-repeat: no-repeat;background-color: #282c34;margin-bottom: -7px;border-radius: 5px;background-position: 10px 10px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg wzjhlvpsrd1bfxruh2q6pljiamcu9ys8j7uzf3uvf2fmmkicdrdpynytbneic03cayv2tviapaxpmu4fmexxkd0a8v3hoawcz7nz 640?wx_fmt="svg&from=appmsg");""></span><code style="overflow-x: auto;padding: 16px;color: #abb2bf;padding-top: 15px;background: #282c34;border-radius: 5px;display: -webkit-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;"><span leaf="">StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); </span><span leaf=""><br></span><span leaf="">env.addSource(</span><span style="color: #c678dd;line-height: 26px;"><span leaf="">new</span></span><span leaf=""> CanalSource()) </span><span leaf=""><br></span><span leaf=""> .map(record -> parseToPriceEvent(record)) </span><span leaf=""><br></span><span leaf=""> .keyBy(event -> event.getProductId()) </span><span leaf=""><br></span><span leaf=""> .connect(userProfileBroadcastStream) </span><span leaf=""><br></span><span leaf=""> .process(</span><span style="color: #c678dd;line-height: 26px;"><span leaf="">new</span></span><span leaf=""> PriceRecommendationProcess()) </span><span leaf=""><br></span><span leaf=""> .addSink(</span><span style="color: #c678dd;line-height: 26px;"><span leaf="">new</span></span><span leaf=""> ElasticsearchSink());</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">优势</span></strong><span leaf="">:</span></p> <ul style="list-style-type: disc;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">状态管理</span></strong><span leaf="">:精准处理乱序事件(Watermark机制)</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">维表关联</span></strong><span leaf="">:通过Broadcast State实现实时画像关联</span> </section></li> </ul> <h2 data-cacheurl="" data-remoteid="" data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-left: 0px;padding-right: 0px;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 50%;background-position-y: 50%;background-repeat: no-repeat;background-size: 63px;width: auto;height: auto;align-items: unset;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;box-shadow: none;display: flex;flex-direction: unset;float: unset;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;text-align: left;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvztmgbxh6ndrwtxb8xsoevtqgdjqyq1gwdoegwplibehbcr3hwdazoo47lgv2tqbljfnygkekckg 640?wx_fmt="png&from=appmsg");""><span style="display: none;"></span><span style="font-size: 18px;color: rgb(72, 179, 120);line-height: 2.4em;letter-spacing: 0em;margin-top: 38px;margin-bottom: 10px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: rgb(0, 0, 0);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: transparent;background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;box-shadow: none;display: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: 38px;justify-content: unset;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: center;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">总结:</span></span><span style="display: none;"></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">对于文章上面给出的这6种技术方案,我们在实际工作中,该如何做选型呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">下面用一张表格做对比:</span></p> <section data-tool="mdnice编辑器" style="margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;overflow-x: auto;"> <table style="display: table;text-align: left;"> <thead> <tr> <th style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.5em;letter-spacing: 0.02em;text-align: left;font-weight: bold;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgb(240, 240, 240);height: auto;border-style: solid;border-width: 1px;border-color: rgba(204, 204, 204, 0.4);border-radius: 0px;padding: 5px 10px;min-width: 85px;"> <section> <span leaf="">方案</span> </section></th> <th style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.5em;letter-spacing: 0.02em;text-align: left;font-weight: bold;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgb(240, 240, 240);height: auto;border-style: solid;border-width: 1px;border-color: rgba(204, 204, 204, 0.4);border-radius: 0px;padding: 5px 10px;min-width: 85px;"> <section> <span leaf="">实时性</span> </section></th> <th style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.5em;letter-spacing: 0.02em;text-align: left;font-weight: bold;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgb(240, 240, 240);height: auto;border-style: solid;border-width: 1px;border-color: rgba(204, 204, 204, 0.4);border-radius: 0px;padding: 5px 10px;min-width: 85px;"> <section> <span leaf="">侵入性</span> </section></th> <th style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.5em;letter-spacing: 0.02em;text-align: left;font-weight: bold;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgb(240, 240, 240);height: auto;border-style: solid;border-width: 1px;border-color: rgba(204, 204, 204, 0.4);border-radius: 0px;padding: 5px 10px;min-width: 85px;"> <section> <span leaf="">复杂度</span> </section></th> <th style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.5em;letter-spacing: 0.02em;text-align: left;font-weight: bold;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgb(240, 240, 240);height: auto;border-style: solid;border-width: 1px;border-color: rgba(204, 204, 204, 0.4);border-radius: 0px;padding: 5px 10px;min-width: 85px;"> <section> <span leaf="">适用阶段</span> </section></th> </tr> </thead> <tbody> <tr style="color: rgb(63, 63, 63);background-attachment: scroll;background-clip: border-box;background-color: rgb(255, 255, 255);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;"> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">同步双写</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">秒级</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">高</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">低</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">小型单体项目</span> </section></td> </tr> <tr style="color: rgb(0, 0, 0);background-attachment: scroll;background-clip: border-box;background-color: rgb(248, 248, 248);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;"> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">MQ异步</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">秒级</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">中</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">中</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">中型分布式系统</span> </section></td> </tr> <tr style="color: rgb(63, 63, 63);background-attachment: scroll;background-clip: border-box;background-color: rgb(255, 255, 255);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;"> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">Logstash</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">分钟级</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">无</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">低</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">离线分析</span> </section></td> </tr> <tr style="color: rgb(0, 0, 0);background-attachment: scroll;background-clip: border-box;background-color: rgb(248, 248, 248);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;"> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">Canal</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">毫秒级</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">无</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">高</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">高并发生产环境</span> </section></td> </tr> <tr style="color: rgb(63, 63, 63);background-attachment: scroll;background-clip: border-box;background-color: rgb(255, 255, 255);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;"> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">DataX</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">小时级</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">无</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">中</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">历史数据迁移</span> </section></td> </tr> <tr style="color: rgb(0, 0, 0);background-attachment: scroll;background-clip: border-box;background-color: rgb(248, 248, 248);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;"> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">Flink</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">毫秒级</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">低</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">极高</span> </section></td> <td style="padding-top: 5px;padding-right: 10px;padding-bottom: 5px;padding-left: 10px;min-width: 85px;border-top-style: solid;border-bottom-style: solid;border-left-style: solid;border-right-style: solid;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-top-color: rgba(204, 204, 204, 0.4);border-bottom-color: rgba(204, 204, 204, 0.4);border-left-color: rgba(204, 204, 204, 0.4);border-right-color: rgba(204, 204, 204, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"> <section> <span leaf="">实时数仓</span> </section></td> </tr> </tbody> </table> </section> <p data-tool="mdnice编辑器" style="color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(74, 74, 74);font-weight: bold;background-attachment: scroll;background-clip: border-box;background-color: rgba(0, 0, 0, 0);background-image: none;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: auto;width: auto;height: auto;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 3px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgba(0, 0, 0, 0.4);border-bottom-color: rgba(0, 0, 0, 0.4);border-left-color: rgba(0, 0, 0, 0.4);border-right-color: rgba(0, 0, 0, 0.4);border-top-left-radius: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;"><span leaf="">苏三的建议</span></strong><span leaf="">:</span></p> <ol style="list-style-type: decimal;margin-top: 8px;margin-bottom: 8px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 25px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">若团队无运维中间件能力 → 选择Logstash或同步双写</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">需秒级延迟且允许改造 → MQ异步 + 本地事务表</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">追求极致实时且资源充足 → Canal + Flink双保险</span> </section></li> </ol> </section>
作者:微信小助手
<section class="mp_profile_iframe_wrp" nodeleaf=""> <mp-common-profile class="js_uneditable custom_select_card mp_profile_iframe" data-pluginname="mpprofile" data-nickname="韦东东" data-alias="JIBAI_AIGC" data-from="0" data-headimg="http://mmbiz.qpic.cn/mmbiz_png/3OZeSOuRw3f0UfiboA2EooV6gxE23nUmwREHMHWnUmrtWcPHRe5CsMMQwa4c65tXKE39I0n2RKNkwgSZrICrnlg/0?wx_fmt=png" data-signature="这个公众号给大家分享我日常大模型应用学习和开发实践,其中涉及Lora微调、RAG、Text2SQL、Multi-Agent等方法,25年会着重关注有行业Know-how的垂直产业场景应用开发和咨询,欢迎大家交流。" data-id="MzI1ODIxNjk1OQ==" data-is_biz_ban="0" data-service_type="1" data-verify_status="0"></mp-common-profile> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">先前文章中提到,不断优化</span><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">原始文档解析</span></strong><span leaf="">和</span><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">分块策略</span></strong><span leaf="">是控制变量法下,是提高最后检索效果天花板的务实做法,前面已经介绍了 MinerU vs DeepDoc 在文档解析方面的效果对比。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf=""><a style="" href="https://mp.weixin.qq.com/s?__biz=MzI1ODIxNjk1OQ==&mid=2649609596&idx=1&sn=f6541a9baf4319b19d07ae4bfa245657&scene=21#wechat_redirect" textvalue="MinerU vs DeepDoc:集成方案+图片显示优化" data-itemshowtype="0" target="_blank" linktype="text" data-linktype="2">MinerU vs DeepDoc:集成方案+图片显示优化</a></span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">关于文档解析部分简单的结论是,MinerU 无疑是值得关注和尝试的一个文档解析框架,但具体效果还要结合特定项目文档做仔细横评。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf=""><span textstyle="" style="font-size: 12px;color: rgb(136, 136, 136);">我目前在常规项目中,主要是对照使用 DeepDoc 和 MinerU 两个方法。后续计划花时间再针对 PaddleOCR、Mistra OCR 等工具做进一步的测评,感兴趣的可以蹲一下。</span></span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">这篇试图说清楚:</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px 10px;max-width: 100%;min-height: 1em;color: rgb(43, 43, 43);text-align: justify;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;background-color: rgb(238, 253, 247);border-left: 10px solid #49c895;padding: 16px;border-right: 2px solid #6bdeb0;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">业界常用的五种 RAG 分块策略核心思想、LlamaIndex 代码演示以及 RAGFlow/Dify 等框架实践思路。</span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/72acb98d3c9ec6806011f9ca3b802e17.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="1.2828125" data-s="300,640" data-type="gif" data-w="640" type="block" data-imgfileid="502125988"> </section> <section style="text-align: center;"> <span style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" data-pm-slice="1 1 [" para,{tagname:section,attributes:{style:text-align: center;},namespaceuri:http: www.w3.org 1999 xhtml},node,{tagname:span,attributes:{style:max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: pingfangsc-light, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;},namespaceuri:http: xhtml}]><span textstyle="" style="font-size: 12px;color: rgb(136, 136, 136);">本篇中 RAG 分块相关图示均来自https://blog.dailydoseofds.com/p/5-chunking-strategies-for-rag 下述相关图片出处不再做单独说明</span></span></span> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf=""><span textstyle="" style="font-weight: normal;">以下,enjoy:</span></span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(41, 148, 128);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;box-sizing: border-box !important;padding-left:4px;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">1</span></span></em></strong></p> <h2 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;font-family: PingfangSC-LIGHT,sans-serif;line-height: 9px;color: white;border-radius: 10px;background:linear-gradient(to right,rgb(41, 148, 128) 25%,rgb(73, 200, 149) 10%);"><span leaf=""> </span></h2> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"> <jncounttag></jncounttag><span leaf="">RAG 与分块的重要性</span></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">在正式开始前,老规矩温故知新,先来复习下传统 RAG 出现的背景、典型 RAG 流程以及分块的重要意义所在。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">1.1</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">典型 RAG 流程</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">为了让大模型能够回答私有知识的问题,抛开高成本的 LLM 微调方法外,我们可以选择在提问时,直接传入私有知识相关的参考信息,这种方法更加简便且高效。</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/f8e40f153babd7443cebbdffb6b35eab.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.3351851851851852" data-s="300,640" data-type="png" data-w="1080" type="block" data-imgfileid="502125986"> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">然而,这种方法的缺点很明显。毕竟提示词长度有限,当私有数据量过大时,传入所有背景信息可能导致提示词过长,从而影响模型的处理效率或达到长度上限。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">而 RAG 巧妙地将 LLM 的生成能力与外部知识库的信息检索能力结合起来:</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/0f72d23384613b3a943e3b0f88ddadb3.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.41836734693877553" data-s="300,640" data-type="gif" data-w="1078" type="block" data-imgfileid="502125987"> </section> <section> <span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;" data-pm-slice="2 2 [" para,{tagname:p,attributes:{label:converted by knb formatter from jason ng https: knb.im mp,style:margin: 20px; max-width: 100%; min-height: 1em; white-space: pre-wrap; color: rgb(43, 43, 43); text-align: justify; line-height: 1.5; box-sizing: border-box !important; word-wrap: break-word !important;},namespaceuri:http: www.w3.org 1999 xhtml}]><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> </span><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> 接收问题 (Query): </span><span leaf="">用户向系统提出查询。</span></span> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">信息检索 (Retrieval): </span></strong><span leaf="">系统在向量数据库或搜索引擎中查找与问题相关的文档片段。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">上下文增强 (Augmentation): </span></strong><span leaf="">将检索到的信息片段整合进发送给 LLM 的提示 (Prompt) 中。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">答案</span><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">生成 </span><span leaf="">(Generation):</span></strong><span leaf=""> LLM 基于原始问题和增强的上下文生成最终回答。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">在这个流程中,要实现高质量的检索,需要对原始知识文档进行有效的预处理,这也就引出了 RAG 流程中一个至关重要的准备工作——<span textstyle="" style="font-weight: bold;">文档分块</span> (Chunking)。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">1.2</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">为啥分块这么重要</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">分块,简单来说就是将原始文档按照某种策略分割成更小的、语义相对完整、适合进行索引和检索的文本单元(Chunks)的过程。 这一步通常在文档被送入向量数据库进行 Embedding(向量化)之前完成。分块策略选择和执行质量,是构建一个 RAG 应用的准确性基础。结合以下三种情形,会更好理解些:</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/10c0d1a935306c12718a30956c9ca6e4.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.21388888888888888" data-s="300,640" data-type="png" data-w="1080" type="block" data-imgfileid="502125989"> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">分块过大:</span><span leaf=""> 可能导致检索到的单个块包含过多无关信息(噪音),增加了 LLM 理解上下文的难度,降低了答案的精确性,甚至可能超出 LLM 的上下文窗口限制。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">分块过小或切分不当</span><span leaf="">: 可能破坏原文的语义连贯性,导致一个完整的知识点被拆散到多个块中。检索时可能只召回了部分信息,使得 LLM 无法获得完整的背景,难以生成全面、准确的答案。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">未能适应文档结构:</span><span leaf=""> 不同的文档类型(如论文、手册、报告、网页)具有不同的结构特点。死板的分块方式可能无法有效利用标题、列表、表格等结构信息,影响信息提取的完整性。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(41, 148, 128);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;box-sizing: border-box !important;padding-left:4px;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">2</span></span></em></strong></p> <h2 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;font-family: PingfangSC-LIGHT,sans-serif;line-height: 9px;color: white;border-radius: 10px;background:linear-gradient(to right,rgb(41, 148, 128) 50%,rgb(73, 200, 149) 10%);"><span leaf=""> </span></h2> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"> <jncounttag></jncounttag><span leaf="">五种分块策略详解</span></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">2.1</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">固定大小分块</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">核心思想</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">这是最直观、最简单的分块方式。按照预先设定的固定长度( 最大 token 数)将文本进行切割。为了尽量减少信息损失,通常会在相邻的块之间保留一部分重叠内容(Overlap)。</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/45232c0fc97ebff25b8f970ac8eaca31.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.24602332979851538" data-s="300,640" data-type="png" data-w="943" type="block" data-imgfileid="502125990"> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">优点:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">实现简单,处理速度快。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">块大小统一,便于批量处理和管理,能精确控制输入 LLM 的 token 数量。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">缺点:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">容易在句子或语义完整的表达中间被“拦腰斩断”,破坏文本的语义连贯性。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">可能将关联紧密的关键信息分散到不同的块中,影响后续检索和理解的完整性。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">适用场景:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">处理结构简单、对语义连贯性要求不高的文本。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">需要快速实现或作为基线对比策略时。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">对块大小有严格限制的应用。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">2.2</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">语义分块</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">核心思想</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">尝试根据文本的语义含义进行切分,将语义关联紧密的句子或段落聚合在一起。通常做法是先将文本分成基础单元(如句子),然后计算相邻单元的语义相似度(例如通过嵌入向量的余弦相似度),如果相似度高于某个阈值,则合并这些单元,直到相似度显著下降时才创建一个新的块。</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/e0f65749b7f6a139182a0c6209b5ead7.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.2703125" data-s="300,640" data-type="gif" data-w="640" type="block" data-imgfileid="502125991"> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">优点</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">能更好地保持文本的语义连贯性和上下文的完整性。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">生成的块通常包含更集中的信息,有助于提升检索精度。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">为 LLM 提供更高质量的上下文,有助于生成更连贯、相关的回答。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">缺点</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">实现相对复杂,依赖于嵌入模型的质量和相似度阈值的设定。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">阈值可能需要根据不同的文档类型进行调整和优化。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">计算成本通常高于固定大小分块。</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/b9636f7b660947edefa97c2117e79c4d.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.2398753894080997" data-s="300,640" data-type="png" data-w="963" type="block" data-imgfileid="502125994"> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">适用场景</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">对上下文理解和语义连贯性要求较高的场景,如问答系统、聊天机器人、文档摘要等。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">处理叙事性或论述性较强的长文本。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">2.3</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">递归分块</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">核心思想:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">采用“分而治之”的策略。首先尝试使用一组优先级较高的、较大的文本分隔符(如段落、章节标记)来分割文本。然后,检查分割出的每个块的大小。如果某个块仍然超过预设的大小限制,就换用下一组优先级更低、更细粒度的分隔符(如句子结束符、换行符)对其进行再次分割,此过程递归进行,直到所有块都满足大小要求。</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/080935082e37fdabb9fee9db9279fba5.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.296875" data-s="300,640" data-type="gif" data-w="640" type="block" data-imgfileid="502125992"> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">优点:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">在保持一定语义结构的同时,能灵活地控制块的大小。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">比固定大小分块更能尊重原文的自然结构。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">适应性较好,是一种常用的通用分块策略。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">缺点:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">实现比固定大小分块更复杂一些。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">需要预先定义好一组有效的分隔符及其优先级顺序。</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/4f4ce4434e26824ffd2832cba4314ccb.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.4349593495934959" data-s="300,640" data-type="png" data-w="984" type="block" data-imgfileid="502125995"> </section> <section> <span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" data-pm-slice="1 1 [" para,{tagname:p,attributes:{label:converted by knb formatter from jason ng https: knb.im mp,style:margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;},namespaceuri:http: www.w3.org 1999 xhtml},node,{tagname:span,attributes:{style:max-width: 100%;line-height: 28px;box-sizing: !important;letter-spacing:1px;font-size:15px;font-family: pingfangsc-light,sans-serif;},namespaceuri:http: xhtml}]><span textstyle="" style="font-size: 12px;color: rgb(136, 136, 136);">注:两个段落(紫色)被识别为初始块,接着第一个段落再被拆成更小的块。这种方式既保留了语义完整性,又能灵活控制分块大小。</span></span></span> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">适用场景:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">适用于大多数类型的文档,特别是那些具有一定层次结构(如章节、段落、列表)但又不完全规整的文档。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">是许多 RAG 框架(如 LangChain)中推荐的默认策略之一。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">2.4</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">基于文档结构的分块</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">核心思想:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">直接利用文档本身固有的、明确的结构元素(如标题层级、章节、列表项、表格、代码块、Markdown 标记等)来定义块的边界。目标是使每个块尽可能对应文档中的一个逻辑组成部分。</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/bc06c016ad0f247e5757bbe1c133356d.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.2776230269266481" data-s="300,640" data-type="gif" data-w="1077" type="block" data-imgfileid="502125993"> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">优点:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">能最大程度地保留文档的原始逻辑结构和上下文信息。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">块的划分方式自然,符合人类的阅读和理解习惯。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">缺点:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">强依赖于文档本身具有清晰、一致的结构,这在现实世界的文档中并非总是得到满足。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">生成的块大小可能差异巨大,某些块可能非常长,超出 LLM 的处理限制。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">通常需要结合递归分块等方法来处理过大的块。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf=""><img src="/upload/50764f0186b96422a649b598f7df8e14.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.646829268292683" data-s="300,640" data-type="png" data-w="1025" type="block" data-imgfileid="502125996"></span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">适用场景:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">特别适合处理结构化或半结构化特征明显的文档,如技术手册、法律合同、API 文档、教程、带有章节的书籍、格式良好的 Markdown 文件等。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">注:某些结构下的分块长度差异较大,可能会超出模型支持的 token 限制。可以考虑结合递归切分法来处理。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">2.5</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">基于 LLM 的分块</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">核心思想:</span></strong><span leaf=""> 不再依赖固定的规则或启发式方法,而是利用大型语言模型 (LLM) 自身的理解能力来判断文本的最佳分割点。可以通过设计合适的提示 (Prompt),让 LLM 将文本分割成语义上内聚且与其他部分相对独立的块。</span></span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/de87a53022dbabb18b7598cae91f0c78.png" class="rich_pages wxw-img js_insertlocalimg" data-ratio="0.17363045496750232" data-s="300,640" data-type="gif" data-w="1077" type="block" data-imgfileid="502125997"> </section> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">优点:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">理论上具有最高的潜力,能实现最符合语义逻辑的分割效果,因为 LLM 能更深入地理解文本内容、上下文和细微差别。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">缺点:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">计算成本最高昂,处理速度最慢,因为涉及到多次调用 LLM。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">需要精心设计有效的 Prompt 来指导 LLM 完成分块任务。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">同样受到 LLM 本身上下文窗口大小的限制。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">适</span><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">用场景:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">对分块质量有极致要求,并且能够承担高昂计算成本和较慢处理速度的场景。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">用于处理语义关系特别复杂、传统方法难以处理的文本。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">也可能作为更复杂策略(如生成摘要树、构建知识图谱)的一部分。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(41, 148, 128);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;box-sizing: border-box !important;padding-left:4px;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">3</span></span></em></strong></p> <h2 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;font-family: PingfangSC-LIGHT,sans-serif;line-height: 9px;color: white;border-radius: 10px;background:linear-gradient(to right,rgb(41, 148, 128) 75%,rgb(73, 200, 149) 10%);"><span leaf=""> </span></h2> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"> <jncounttag></jncounttag><span leaf="">LlamaIndex 分块策略演示</span></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">为了更好的理解五种不同的分块策略原理和实现细节,下面以 LlamaIndex 为例,展示五种策略对应的示例 python 代码。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">在具体介绍前,先补充说明两个问题:LlamaIndex 是什么?以及为什么不选择 RAGFlow/Dify 等框架来进行分块策略的演示?</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">3.1</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">LlamaIndex 扫盲介绍</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf=""><span textstyle="" style="font-weight: normal;">LlamaIndex 也是一个非常流行的开</span></span><span leaf="" style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span textstyle="" style="font-weight: normal;">源</span></span><strong style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span textstyle="" style="font-weight: normal;">数据框架</span></span></strong><span leaf="" style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span textstyle="" style="font-weight: normal;">,与 Ragflow 不同,LlamaIndex 更像是一个灵活的</span></span><strong style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span textstyle="" style="font-weight: normal;">工具箱或库</span></span></strong><span leaf="" style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span textstyle="" style="font-weight: normal;">,提供了丰富、模块化的组件来处理 RAG 流程中的各个阶段,特别是</span></span><strong style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span textstyle="" style="font-weight: normal;">数据加载、转换(包括分块/节点解析)、索引和查询</span></span></strong><span leaf="" style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span textstyle="" style="font-weight: normal;">。</span></span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 16px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">主要组件特点</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">数据连接器</span><span leaf=""> (Data Connectors): 支持从各种来源(文件、API、数据库等)加载数据。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">数据索引</span><span leaf=""> (Data Indexes): 提供多种索引结构(如向量存储索引、列表索引、关键词表索引、树状索引、知识图谱索引等)来组织数据,以适应不同的查询需求。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">节点解析/文本分割</span><span leaf=""> (Node Parsing / Text Splitting): 这是 LlamaIndex 处理分块的核心部分。它提供了多种可配置的文本分割器 (Text Splitters),让开发者可以精细地控制文档如何被分割成“节点 (Nodes)”<span textstyle="" style="font-size: 12px;color: rgb(136, 136, 136);">(LlamaIndex 中对“块/Chunk”的称呼)。</span></span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">检索器</span><span leaf=""> (Retrievers): 基于索引,提供不同的方式来检索与查询相关的节点。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">查询引擎</span><span leaf=""> (Query Engines): 结合检索器和 LLM,构建端到端的查询和响应能力。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">代理</span><span leaf=""> (Agents): 构建更复杂的、可以自主规划和使用工具的 LLM 应用。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">模块</span><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">化和可</span><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">扩展性</span><span leaf="">: 开发者可以方便地组合、替换或自定义各个组件。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 16px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">演示底层机制的优势</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">LlamaIndex 的设计哲学就是提供明确的、可编程的接口。对于分块(节点解析),我们可以直接在代码中:</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">导入特定的 TextSplitter 类</span><span leaf="">: LlamaIndex 提供了与多种分块策略对应的类。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">实例化分割器并配置参数</span><span leaf="">: 显式地设置块大小、重叠大小、分隔符、模型(用于语义分割)、结构解析规则等。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">调用分割器的 split_text 或类似方法</span><span leaf="">: 将原始文本输入,直接获得分割后的节点列表。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">下文会通过具体的 Python 代码清晰和直接地展示五种分块策略的实现。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">3.2</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">高集成度的局限</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">像 Ragflow、Dify 这样封装度较高的框架,提供的开箱即用的端到端解决方案,必然会通过 UI 或 API 参数将底层的实现细节抽象化。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">这虽然方便用户快速搭建应用,但对于希望理解<span textstyle="" style="font-weight: bold;">“引擎盖”</span>下面发生了什么的用户来说会不够透明,难以窥见不同策略的具体代码实现和细微差别。具体来说:</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">抽象层级的差异:</span></strong><span leaf=""> Ragflow/Dify 等平台为了易用性,会将底层的分块逻辑封装在更高级的选项(如 Ragflow 的 chunk_method 下拉菜单和相关配置)。用户无法直接编写或修改 LlamaIndex 那样的底层分块代码。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">平台特定实现:</span></strong><span leaf=""> 即便 Ragflow 提供了一个名为 "Paper" 的分块方法,其内部的具体实现逻辑、使用的分隔符、递归策略等细节,与 LlamaIndex 的 MarkdownNodeParser 组合有所不同。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">配置而非编码:</span></strong><span leaf=""> 在这些平台上,用户更多的是通过图形界面 (UI) 或平台的 Python API </span><span leaf="" style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">来</span><strong style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span textstyle="" style="font-weight: normal;">配置</span></span></strong><span leaf="" style="min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">分</span><span leaf="">块选项,而不是直接编写分块算法的代码。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">3.3</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">LlamaIndex 五种分块策略代码参考</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">固定大小分块:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">可以使用SentenceSplitter(设置 chunk_size控制token数,chunk_overlap 控制重叠) 或 TokenTextSplitter。代码会清晰展示如何设置大小和重叠。</span></span></p> <pre class="code-snippet__js code-snippet code-snippet_nowrap" data-lang="javascript" style="background: rgba(0,0,0,0.03);border: 1px solid #f0f0f0;border-radius: 3px;color: #333;margin-bottom: 10px;padding: 10px;width:90%;"><code><span leaf="">from llama_index.core.node_parser import SentenceSplitter</span></code><code><span leaf=""><br></span></code><code><span leaf="">splitter = SentenceSplitter(chunk_size=128, chunk_overlap=20)</span></code><code><span leaf="">nodes = splitter.get_nodes_from_documents(documents) # 'documents' 是加载后的文档对象</span></code><code><span leaf=""># 可以打印 nodes[0].get_content() 查看第一个块的内容</span></code></pre> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">语义分块:</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">LlamaIndex 提供了 SemanticSplitterNodeParser。需要配置一个嵌入模型,并设定相似度阈值 (breakpoint_percentile_threshold)。</span></span></p> <pre class="code-snippet__js code-snippet code-snippet_nowrap" data-lang="javascript" style="background: rgba(0,0,0,0.03);border: 1px solid #f0f0f0;border-radius: 3px;color: #333;margin-bottom: 10px;padding: 10px;width:90%;"><code><span leaf="">from llama_index.core.node_parser import SemanticSplitterNodeParser</span></code><code><span leaf="">from llama_index.embeddings.openai import OpenAIEmbedding # 或其他嵌入模型</span></code><code><span leaf=""><br></span></code><code><span leaf="">embed_model = OpenAIEmbedding()</span></code><code><span leaf="">splitter = SemanticSplitterNodeParser(</span></code><code><span leaf=""> buffer_size=1, breakpoint_percentile_threshold=95, embed_model=embed_model</span></code><code><span leaf="">)</span></code><code><span leaf="">nodes = splitter.get_nodes_from_documents(documents)</span></code></pre> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">递归分块</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">SentenceSplitter 本身就具有一定递归特性,它会按顺序尝试使用不同的分隔符(默认从 \n\n 到 . 到 等)。可以自定义 paragraph_separator 等参数。<span textstyle="" style="font-size: 12px;color: rgb(136, 136, 136);">更复杂的递归(如构建摘要树)可能涉及 HierarchicalNodeParser。</span></span></span></p> <pre class="code-snippet__js code-snippet code-snippet_nowrap" data-lang="javascript" style="background: rgba(0,0,0,0.03);border: 1px solid #f0f0f0;border-radius: 3px;color: #333;margin-bottom: 10px;padding: 10px;width:90%;"><code><span leaf="">from llama_index.core.node_parser import SentenceSplitter</span></code><code><span leaf=""><br></span></code><code><span leaf=""># 默认行为就是递归的,可以定制分隔符</span></code><code><span leaf="">splitter = SentenceSplitter(</span></code><code><span leaf=""> separator=" ", # 可以简化分隔符用于演示</span></code><code><span leaf=""> chunk_size=256,</span></code><code><span leaf=""> chunk_overlap=30,</span></code><code><span leaf=""> paragraph_separator="\n\n\n", # 示例:自定义段落分隔符</span></code><code><span leaf="">)</span></code><code><span leaf="">nodes = splitter.get_nodes_from_documents(documents)</span></code></pre> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">基于文档结构的分块</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">LlamaIndex 有专门的 MarkdownNodeParser 或 JSONNodeParser。对于 PDF 中提取的 Markdown,MarkdownNodeParser 能很好地利用标题、列表等结构。</span></span></p> <pre class="code-snippet__js code-snippet code-snippet_nowrap" data-lang="javascript" style="background: rgba(0,0,0,0.03);border: 1px solid #f0f0f0;border-radius: 3px;color: #333;margin-bottom: 10px;padding: 10px;width:90%;"><code><span leaf="">from llama_index.core.node_parser import MarkdownNodeParser</span></code><code><span leaf=""><br></span></code><code><span leaf="">parser = MarkdownNodeParser()</span></code><code><span leaf="">nodes = parser.get_nodes_from_documents(documents) # 假设 documents 是加载的 Markdown 内容</span></code><code><span leaf=""># 对于从 PDF 解析得到的 Markdown 尤其有效</span></code></pre> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><strong style="background: linear-gradient(to right,rgb(73, 200, 149),rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0;display: inline;font-weight: normal;padding: 2px 4px 2px 4px;"><span leaf="">基于 LLM</span><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> 的分块</span></strong></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">虽然没有一个现成的 LLMTextSplitter,但 LlamaIndex 的灵活性允许我们构建自定义的 NodeParser,在其中调用 LLM 来决定分割点或生成摘要块。<span textstyle="" style="font-size: 15px;color: rgb(0, 0, 0);">例如结合 LLM 进行章节总结或主题划分,或者利用 LLM 对元数据进行分析来指导分割。</span><span textstyle="" style="font-size: 12px;color: rgb(136, 136, 136);">这部分后续我结合具体案例再做演示。</span></span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(41, 148, 128);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;box-sizing: border-box !important;padding-left:4px;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">4</span></span></em></strong></p> <h2 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;font-family: PingfangSC-LIGHT,sans-serif;line-height: 9px;color: white;border-radius: 10px;background:linear-gradient(to right,rgb(41, 148, 128) 100%,rgb(73, 200, 149) 10%);"><span leaf=""> </span></h2> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"> <jncounttag></jncounttag><span leaf="">写在最后</span></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">4.1</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">如何在 Ragflow/Dify 中应用不同分块策略</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">上述 LlamaIndex 的演示只是提供了评估的思路和方向,不能替代在目标平台上的实际验证。各位可以利用上述LlamaIndex 演示中的原理,去解读 Ragflow/Dify等框架提供的分块选项。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">以RAGFlow为例,相关分块选项和上述的五种分块策略很难一一映射,结合官方的python api解读参考如下:</span></span></p> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">固定大小分块:</span><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> Ragflow 的 "naive" 方法最接近这个概念,尤其是当配置了 chunk_token_num 时。它可能也结合了 delimiter 进行分割。</span></p> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">语义分块:</span><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> API 文档中没有直接命名为 "semantic" 的选项。然而,某些高级方法(像 "qa"、"knowledge_graph" 某种程度上)可能隐含了语义理解。但 API 没有提供一个像 LangChain 那样明确的 Semantic Splitter 选项。</span></p> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">递归分块:</span><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> 像 "book" 或 "paper" 这样的方法内部猜测是采用了递归或基于结构的分块逻辑,会先尝试按大纲(章节、标题)分割,如果块太大再按段落或句子递归分割。但API 文档没有明确说明其内部递归逻辑。</span></p> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">基于文档结构的分块:</span><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> "paper", "book", "laws", "presentation", "table" 这些方法明显是针对特定文档结构的,它们会优先利用文档的固有结构(标题、章节、表格结构、幻灯片等)来定义块边界。</span></p> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="min-height: 1em;text-align: justify;max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;background: linear-gradient(to right, rgb(73, 200, 149), rgb(38, 198, 218));color: white;white-space: pre-wrap;border-width: 0.25em 0px;display: inline;font-weight: normal;padding: 2px 4px;box-sizing: border-box !important;overflow-wrap: break-word !important;">基于 LLM 的分块:</span><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">API 中没有通用的、直接让 LLM 决定分块边界的选项。</span></p> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf=""><img src="/upload/15036662b3764d0c1216dd64751d22bb.png" class="rich_pages wxw-img" data-ratio="0.7728937728937729" data-s="300,640" data-type="png" data-w="819" type="block" data-imgfileid="502126001"></span></p> <p style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">这里需要特别说明的是,在RAGFlow中创建知识库环节,自动关键词/问题提取不是LLM-based Chunking,而是分块后的 LLM 增强。但RAPTOR(递归摘要树,多粒度检索) 策略涉及对初始块进行聚类,并使用 LLM 对聚类进行摘要,生成新的、更高层次的“摘要块”。 这个策略可以被认为是“基于 LLM 的分块”的一种高级形式或应用。<span textstyle="" style="font-size: 12px;color: rgb(136, 136, 136);">虽然它可能建立在初始分块之上,但它确实利用 LLM 生成了新的、语义层级更高的块(摘要),这些新块是文档内容的一种 LLM 驱动的重新组织和分割。它不仅仅是分析现有块,而是创造了新的块边界和内容。</span></span><span leaf="" style="max-width: 100%;line-height: 28px;letter-spacing: 1px;font-size: 15px;font-family: PingfangSC-LIGHT, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;" data-pm-slice="1 1 [" para,{tagname:p,attributes:{style:margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;overflow-wrap: break-word !important;},namespaceuri:http: www.w3.org 1999 xhtml}]><br></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">4.2</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">成熟框架的分块策略定制问题</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">如果你想实现的功能(例如一种非常特定的、Ragflow 没有内置或通过 API 参数暴露的分块方法,或者你想彻底改变其检索逻辑)超出了 Ragflow 提供的 API 和配置选项的范畴,理论上唯一的途径就是修改 Ragflow 的源代码。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">但像 Ragflow 这样的框架通常有复杂的内部结构和依赖关系,理解并安全地修改其核心代码需要投入大量时间和精力。而且鉴于 RAGFlow 在常态化更新中,创建一个 Ragflow 的“定制分支”意味着官方的更新、补丁或新功能无法直接合并,需要自己手动同步或重新应用你的修改,维护成本很高。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">类似Dify 支持编写插件来添加自定义功能,而无需修改核心代码。RAGFlow 等类似框架后续预期都会陆续支持更加灵活的扩展机制,建议短期内不要在二开上耗费精力。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="line-height: 25.6px;min-height: 1em;max-width: 100%;white-space: pre-wrap;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-left: 10px;max-width: 100%;color: rgb(26, 149, 165);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><em style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 24px;padding-left:4px;box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">4.3</span></span></em></strong></span></p> <h3 label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin-top: -10px;line-height: 5px;background:linear-gradient(to right,rgb(26, 149, 165) ,rgb(38, 198, 218));"><span leaf=""> </span></h3> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(137, 137, 137);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(62, 62, 62);line-height: 25.6px;min-height: 1em;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 20px;box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(137, 137, 137);font-size: 18px;line-height: 1.5;white-space: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(62, 62, 62);box-sizing: border-box !important;word-wrap: break-word !important;font-family: PingFangSC-Semibold,sans-serif;"><span leaf="">使用 LlamaIndex 替代 Ragflow/Dify?</span></span></strong></span></strong></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">这是我近期被问到比较多的一个问题,我在实施或咨询的一些项目中,部分企业选择直接基于 LlamaIndex(或 LangChain 等类似库)来构建自己的企业级 RAG 应用,而不是使用封装好的平台。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">除了可以更好的与现有技术栈集成外,企业可以完全掌控 RAG 流程的每一个环节,选择最适合需求的模型(嵌入、LLM、重排)、向量数据库、索引策略、检索逻辑等,并进行深度定制和优化。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">但问题也随着而来,这需要开发或集成几乎所有“外围”组件,包括 UI、API、数据库、部署运维在内的所有周边系统。 毕竟LlamaIndex 虽然提供了 RAG 的核心“引擎”和“管道”,但它本身不是一个可以直接部署给最终用户的完整应用。</span></span></p> <p label="Converted by KNB Formatter from Jason Ng https://knb.im/mp" style="margin: 20px;max-width: 100%;min-height: 1em;white-space: pre-wrap;color: rgb(43, 43, 43);text-align: justify;line-height: 1.5;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 28px;box-sizing: border-box !important;word-wrap: break-word !important;letter-spacing:1px;font-size:15px;font-family: PingfangSC-LIGHT,sans-serif;"><span leaf="">一般的建议是,针对企业级知识库项目落地,如果需求与某个成熟框架的功能高度匹配,且对定制化要求不高,或者时间紧迫需要快速验证,那么选择 Ragflow/Dify 显然更高效。但如果企业对 RAG 的性能、逻辑有深度定制的需求,希望完全掌控技术栈,拥有较强的内部研发能力,或者需要将 RAG 深度嵌入现有复杂系统,那么基于 LlamaIndex 自建通常是更长远、更灵活的选择,尽管前期投入更大。</span></span></p>
作者:微信小助手
<section> <span leaf=""><span textstyle="" style="font-size: 24px;color: rgb(0, 82, 255);font-weight: bold;">前言</span></span> </section> <section> <span style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="">在当下数字化浪潮汹涌澎湃的时代,人工智能技术如雨后春笋般不断涌现,数字人作为其中一颗璀璨的新星,正逐渐走进大众视野并改变着我们的生活方式。与此同时,Dify 作为一种新兴的技术平台或概念,与数字人相结合,正展现出巨大的潜力和无限可能,为智能交互领域带来前所未有的变革。</span></span> </section> <section> <span leaf="">最近发现一款名为</span><span leaf="" data-pm-slice="1 1 [" para,null]><span textstyle="" style="color: rgb(0, 128, 255);">awesome-digital-human-live2d</span>的数字人产品,该产品的主要特性:</span> </section> <ul style="box-sizing: border-box;padding-left: 2em;margin-top: 0px;margin-bottom: 16px;color: rgb(31, 35, 40);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, noto sans, helvetica, arial, sans-serif, apple color emoji, segoe ui emoji;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; class="list-paddingleft-1"> <li style="box-sizing: border-box;"> <section> <span leaf="">支持 Docker 快速部署</span> </section></li> <li style="box-sizing: border-box;margin-top: 0.25em;"> <section> <span leaf="">超轻量级,配置要求低于2核2G</span> </section></li> <li style="box-sizing: border-box;margin-top: 0.25em;"> <section> <span leaf="">支持 Dify/FastGPT 等编排框架服务接入</span> </section></li> <li style="box-sizing: border-box;margin-top: 0.25em;"> <section> <span leaf="">支持 ASR、LLM、TTS、Agent 模块化扩展</span> </section></li> <li style="box-sizing: border-box;margin-top: 0.25em;"> <section> <span leaf="">支持 Live2d 人物模型扩展和控制方式</span> </section></li> <li style="box-sizing: border-box;margin-top: 0.25em;"> <section> <span leaf="">支持PC端和移动端web访问</span> </section></li> </ul> <section> <span leaf=""><span textstyle="" style="color: rgb(255, 104, 39);">传送门:</span><span textstyle="" style="font-size: 14px;color: rgb(255, 104, 39);">https://github.com/wan-h/awesome-digital-human-live2d/tree/main</span></span> </section> <ul style="box-sizing: border-box;padding-left: 2em;margin-top: 0px;margin-bottom: 16px;color: rgb(31, 35, 40);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, noto sans, helvetica, arial, sans-serif, apple color emoji, segoe ui emoji;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; class="list-paddingleft-1"></ul> <section> <span leaf=""><br></span> </section> <section> <span leaf=""><span textstyle="" style="font-size: 24px;color: rgb(0, 82, 255);font-weight: bold;">关于</span></span><span leaf="" data-pm-slice="1 1 [" para,null]><span textstyle="" style="font-size: 24px;color: rgb(0, 82, 255);font-weight: bold;">live2d</span></span> </section> <p style="box-sizing: border-box;border: 0px solid rgb(229, 231, 235);" data-pm-slice="0 0 []"><span leaf="" style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;float: none;display: inline !important;>Live2D 是一种能够将平面动画图像(如插画)转变为可动画化的三维模型,使得角色能够在不同角度进行动态表现。</span></p> <p style="box-sizing: border-box;border: 0px solid rgb(229, 231, 235);" data-pm-slice="0 0 []"><span leaf="" style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;float: none;display: inline !important;><br></span></p> <p style="box-sizing: border-box;border: 0px solid rgb(229, 231, 235);"><span leaf="" style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;float: none;display: inline !important;>这样的产品通常用于视频游戏、动画、直播或者社交媒体等场景,让虚拟角色看起来更生动、更具互动性。</span></p> <section> <span leaf=""><br></span> </section> <section> <span leaf=""><br></span> </section> <section> <span leaf="" data-pm-slice="1 1 [" para,null]><span textstyle="" style="font-size: 24px;color: rgb(0, 82, 255);font-weight: bold;">awesome-digital-human-live2d的安装和使用</span></span> </section> <section> <span leaf="">容器部署(体验首选,推荐)</span> </section> <section> <span leaf=""><span textstyle="" style="font-weight: bold;">1、下载代码安装容器镜像</span></span> </section> <pre style="box-sizing: border-box;font-family: ui-monospace, SFMono-Regular, " sf mono, menlo, consolas, liberation monospace;font-size: 13.6px;margin-top: 0px;margin-bottom: 0px;overflow-wrap: normal;padding: 16px;overflow: auto;line-height: 1.45;color: rgb(31, 35, 40);background-color: rgb(246, 248, 250);border-radius: 6px;word-break: normal;min-height: 52px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; data-pm-slice="0 0 []"><span style="box-sizing: border-box;color: rgb(89, 99, 110);"><span style="box-sizing: border-box;color: rgb(89, 99, 110);"><span leaf="">#</span></span><span leaf=""> 在项目根目录下执行</span></span><span leaf="">docker-compose -f docker-compose-quickStart.yaml up -d</span></pre> <section style="text-align: center;" nodeleaf=""> <img class="rich_pages wxw-img" data-imgfileid="100003623" data-ratio="0.5222222222222223" data-s="300,640" src="/upload/c1584e7986201d3b591f5ef9bd675ae5.png" data-type="png" data-w="1080" type="block"> </section> <section> <span leaf=""><span textstyle="" style="font-weight: bold;">2、访问页面</span></span> </section> <h3 tabindex="-1" dir="auto" style="box-sizing: border-box;border: 0px solid rgb(229, 231, 235);" data-pm-slice="0 0 []"><span leaf="" style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;float: none;display: inline !important;>本地浏览器访问路径: http://localhost:3000</span><span leaf=""><br></span><span leaf="" style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;float: none;display: inline !important;>非本地浏览器访问路径: http://{部署服务器IP}:3000</span></h3> <section style="text-align: center;" nodeleaf=""> <img class="rich_pages wxw-img" data-imgfileid="100003624" data-ratio="0.5962962962962963" data-s="300,640" src="/upload/ca9dffa03c7dc77efbf28eb0cccb69b6.png" data-type="png" data-w="1080" type="block"> </section> <h3 tabindex="-1" dir="auto" style="box-sizing: border-box;border: 0px solid rgb(229, 231, 235);" data-pm-slice="0 0 []"><span leaf=""><br></span></h3> <h3 tabindex="-1" dir="auto" style="box-sizing: border-box;border: 0px solid rgb(229, 231, 235);" data-pm-slice="0 0 []"><span leaf=""><br></span></h3> <section> <span leaf=""><br></span> </section> <section> <span leaf="" data-pm-slice="1 1 [" para,{tagname:h3,attributes:{tabindex:-1,class:heading-element,dir:auto,style:box-sizing: border-box; border: 0px solid rgb(229, 231, 235); --tw-border-spacing-x: 0; --tw-border-spacing-y: --tw-translate-x: --tw-translate-y: --tw-rotate: --tw-skew-x: --tw-skew-y: --tw-scale-x: 1; --tw-scale-y: --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(59,130,246,.5); --tw-ring-offset-shadow: 0 #0000; --tw-ring-shadow: --tw-shadow: --tw-shadow-colored: margin: color: rgb(75, 85, 99); font-family: ui-sans-serif, system-ui, sans-serif, \apple color emoji\, \segoe ui symbol\, \noto emoji\; font-size: 12px; font-style: normal; font-variant-ligatures: font-variant-caps: font-weight: 400; letter-spacing: orphans: 2; text-align: start; text-indent: text-transform: none; widows: word-spacing: -webkit-text-stroke-width: white-space: text-decoration-thickness: initial; text-decoration-style: text-decoration-color: initial;,data-pm-slice:0 []},namespaceuri:http: www.w3.org 1999 xhtml}]><span textstyle="" style="font-weight: bold;">3、选择人物和背景</span></span> </section> <section style="text-align: center;" nodeleaf=""> <img class="rich_pages wxw-img" data-imgfileid="100003625" data-ratio="0.5398148148148149" data-s="300,640" src="/upload/a787228980ddc11698a8ac692a9ea518.png" data-type="png" data-w="1080" type="block"> </section> <section style="text-align: center;" nodeleaf=""> <img src="/upload/1f999e4bd33a712f0ea75b6b7da48330.png" class="rich_pages wxw-img" data-ratio="0.5787037037037037" data-s="300,640" data-type="png" data-w="1080" type="block" data-imgfileid="100003626"> </section> <section> <span leaf=""><span textstyle="" style="font-weight: bold;">4、设置基础配置</span></span> </section> <section style="text-align: center;" nodeleaf=""> <img class="rich_pages wxw-img" data-imgfileid="100003627" data-ratio="0.6027777777777777" data-s="300,640" src="/upload/5e7cdebb2ed76538195dd9fe2604fea5.png" data-type="png" data-w="1080" type="block"> </section> <section> <span leaf=""><br></span> </section> <section> <span leaf=""><span textstyle="" style="font-weight: bold;">5、设置服务</span></span> </section> <section> <span leaf="">该产品支持多个Agent模式,可以根据自己的业务实际情况进行选择</span> </section> <section style="text-align: center;" nodeleaf=""> <img class="rich_pages wxw-img" data-imgfileid="100003628" data-ratio="0.47962962962962963" data-s="300,640" src="/upload/cb49509bf064bf5acde51ff8e3c749fb.png" data-type="png" data-w="1080" type="block"> </section> <h4 tabindex="-1" dir="auto" style="box-sizing: border-box;margin-top: 24px;margin-bottom: 16px;font-size: 1em;font-weight: 600;line-height: 1.25;" data-pm-slice="0 0 []"><span leaf="">6、获取dify API & 密钥</span></h4> <h4 tabindex="-1" dir="auto" style="box-sizing: border-box;margin-top: 24px;margin-bottom: 16px;font-size: 1em;font-weight: 600;line-height: 1.25;" data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="font-weight: normal;">构建完成自己的dify应用后,点击 </span></span><strong style="box-sizing: border-box;font-weight: 600;"><span leaf=""><span textstyle="" style="font-weight: normal;">发布</span></span></strong><span leaf=""><span textstyle="" style="font-weight: normal;">、</span></span><strong style="box-sizing: border-box;font-weight: 600;"><span leaf=""><span textstyle="" style="font-weight: normal;">运行</span></span></strong><span leaf=""><span textstyle="" style="font-weight: normal;">,然后点击 </span></span><strong style="box-sizing: border-box;font-weight: 600;"><span leaf=""><span textstyle="" style="font-weight: normal;">访问API</span></span></strong><span leaf=""><span textstyle="" style="font-weight: normal;"> 获取API地址和密钥</span></span><span leaf=""><br></span><span leaf=""><br></span></h4> <h4 tabindex="-1" dir="auto" style="box-sizing: border-box;margin-top: 24px;margin-bottom: 16px;font-size: 1em;font-weight: 600;line-height: 1.25;" data-pm-slice="0 0 []"><a href="https://mp.weixin.qq.com/s?__biz=Mzg2NDAzMzY1OA==&mid=2247487269&idx=1&sn=d124f79b168a06df5f37eb743fa5150f&scene=21#wechat_redirect" imgurl="https://mmbiz.qlogo.cn/sz_mmbiz_png/FUIf67fxpmphjzbf0V632hcoDbjCoq1mux5YkDmkVmrh7dKU2PqcUjetydaL2PM2odwibzgJfX937QurBt4CrUQ/0?wx_fmt=png&from=appmsg" linktype="image" tab="innerlink" data-itemshowtype="0" target="_blank" data-linktype="1"><span class="js_jump_icon h5_image_link"><img class="rich_pages wxw-img" src=""></span></a><span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100003632" data-ratio="0.8461538461538461" src="/upload/cfdbb267ee0f1514ffdb235acb3884f5.png" data-type="png" data-w="403" style="box-sizing: content-box;border-style: none;max-width: 100%;"></span><span leaf=""><span textstyle="" style="font-size: 15px;font-weight: normal;">在</span></span><strong style="box-sizing: border-box;font-weight: 600;"><span leaf=""><span textstyle="" style="font-size: 15px;font-weight: normal;">访问API</span></span></strong><span leaf=""><span textstyle="" style="font-size: 15px;font-weight: normal;">页面,右上角分别可以获取API地址和创建API密钥</span></span></h4> <h4 tabindex="-1" dir="auto" style="box-sizing: border-box;margin-top: 24px;margin-bottom: 16px;font-size: 1em;font-weight: 600;line-height: 1.25;" data-pm-slice="0 0 []"><a href="https://mp.weixin.qq.com/s?__biz=Mzg2NDAzMzY1OA==&mid=2247487151&idx=1&sn=d95a1ca9d654bb54fede73dae8700d52&scene=21#wechat_redirect" imgurl="" linktype="image" tab="innerlink" data-itemshowtype="0" target="_blank" data-linktype="1"><span style="width:100%;" class="js_jump_icon h5_image_link"></span></a><span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100003631" data-ratio="0.4048716260697828" src="/upload/a11cb9e791c00f1615a37a344a9617d1.png" data-type="png" data-w="1519" style="box-sizing: content-box;border-style: none;max-width: 100%;"></span></h4> <section> <span leaf=""><br></span> </section> <section style="box-sizing: border-box;margin-top: 24px;margin-bottom: 16px;font-size: 1em;font-weight: 600;line-height: 1.25;"> <span leaf="">7、使用</span> </section> <section> <span leaf="">打开浏览器输入网站后,点击左小角的语音图标后</span> </section> <section style="text-align: center;" nodeleaf=""> <img class="rich_pages wxw-img" data-imgfileid="100003633" data-ratio="0.6" data-s="300,640" src="/upload/48e3b5aa9fd8347085bfb5473d04ca32.png" data-type="png" data-w="1080" type="block"> </section> <section> <span leaf="">变成红色圆圈后,可以开始说话;说完后再点击红色圆圈结束说话</span> </section> <section style="text-align: center;" nodeleaf=""> <img class="rich_pages wxw-img" data-imgfileid="100003635" data-ratio="0.5453703703703704" data-s="300,640" src="/upload/fb2a7990c4a42c00920e69fe5f7a70c9.png" data-type="png" data-w="1080" type="block"> </section> <section> <span leaf=""><br></span> </section> <section> <span leaf=""><span textstyle="" style="color: rgb(255, 104, 39);font-weight: bold;">整体交互效果:</span></span> </section> <section nodeleaf=""> <iframe class="video_iframe rich_pages" src="https://mp.weixin.qq.com/mp/readtemplate?t=pages/video_player_tmpl&action=mpvideo&auto=0&vid=wxv_3976939393821917187" data-mpvid="wxv_3976939393821917187" data-vidtype="2" data-cover="http%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FFUIf67fxpmphjzbf0V632hcoDbjCoq1mibuqCw8U7yOOwNZNNlqA3tdjk7rK2qvxljd3UMk3xpag3vjbmwvPBbg%2F0%3Fwx_fmt%3Djpeg"></iframe> </section> <section> <span leaf=""><br></span> </section> <section> <span leaf=""><span textstyle="" style="font-size: 24px;color: rgb(0, 82, 255);font-weight: bold;">总结</span></span><span style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><br></span></span> </section> <section> <span style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(245, 245, 245);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="" style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;float: none;display: inline !important;>通过live2d结合dify工作流,</span><span data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [" para,null,node,{tagname:span,attributes:{style:color: rgba(0, 0, 0.9); font-family: -apple-system, blinkmacsystemfont, \segoe ui\, system-ui, roboto, ubuntu, cantarell, \noto sans\, sans-serif, arial, \pingfang sc\, \source han sans \microsoft yahei yahei\, cjk sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: font-variant-caps: font-weight: 400; letter-spacing: orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: word-spacing: -webkit-text-stroke-width: white-space: pre-wrap; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: text-decoration-color: display: inline !important; float: none;,data-pm-slice:0 0 []},namespaceuri:http: www.w3.org 1999 xhtml}] style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, segoe noto sans, pingfang sc, source microsoft yahei, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;float: none;display: !important;>绝大</span></span><span style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [" para,null,node,{tagname:span,attributes:{style:color: rgba(0, 0, 0.9); font-family: -apple-system, blinkmacsystemfont, \segoe ui\, system-ui, roboto, ubuntu, cantarell, \noto sans\, sans-serif, arial, \pingfang sc\, \source han sans \microsoft yahei yahei\, cjk sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: font-variant-caps: font-weight: 400; letter-spacing: orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: word-spacing: -webkit-text-stroke-width: white-space: pre-wrap; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: text-decoration-color: display: inline !important; float: none;,data-pm-slice:0 0 []},namespaceuri:http: www.w3.org 1999 xhtml}]>多数自然语言对话场景得以生动而流畅地实现。但对描述要求较高的场景来说,</span><span style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [" para,null,node,{tagname:span,attributes:{style:color: rgba(0, 0, 0.9); font-family: -apple-system, blinkmacsystemfont, \segoe ui\, system-ui, roboto, ubuntu, cantarell, \noto sans\, sans-serif, arial, \pingfang sc\, \source han sans \microsoft yahei yahei\, cjk sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: font-variant-caps: font-weight: 400; letter-spacing: orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: word-spacing: -webkit-text-stroke-width: white-space: pre-wrap; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: text-decoration-color: display: inline !important; float: none;,data-pm-slice:0 0 []},namespaceuri:http: www.w3.org 1999 xhtml}]>文字交互依然占据着不可替代的重要地位。所以需要根据自己的场景进行适当的在文字和语音之间选择。</span></span></span></span></span> </section> <section> <span style="color: rgba(0, 0, 0, 0.9);font-family: -apple-system, BlinkMacSystemFont, " segoe ui, system-ui, -apple-system, segoe roboto, ubuntu, cantarell, noto sans, sans-serif, arial, pingfang sc, source han sans microsoft yahei yahei, cjk sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: pre-wrap;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;display: inline !important;float: none; data-pm-slice="0 0 []"><span leaf=""><br></span></span> </section> <p style="display: none;"> <mp-style-type data-value="3"></mp-style-type></p>