作者:微信小助手
<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>
作者:微信小助手
<p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px; data-pm-slice="0 0 []"><span leaf="">你的微信里有没有一个对话窗?它很久都没有弹出新消息,但你却常常在深夜里点开反反复复地翻着。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">如果现在,你可以用这些聊天记录克隆出对方的“数字分身”,保存下 TA 说话的语气、风格、独特的口头禅,甚至还能给你发来语音,你会怎么选?</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">最近,GitHub 上新开源了一个项目 WeClone——让你记忆里的那个 TA 在数字世界里永生,已不再是不可能。</span></p> <figure data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 10px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;padding: 0px;display: flex;flex-direction: column;justify-content: center;align-items: center;> <span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100059038" data-ratio="0.9092592592592592" src="/upload/8b8cb20cdf41f52d623440276cf7ec5f.jpg" data-type="jpeg" data-w="1080" style="box-sizing: border-box;vertical-align: middle;border-style: none;display: block;margin: 0px auto;max-width: 100%;border-width: 3px;border-color: rgba(0, 0, 0, 0.4);border-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;"></span> </figure> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">WeClone 通过个人微信聊天记录对大语言模型( LLM )进行微调,打造个性化的数字分身。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">它提供从文本生成到语音克隆、从训练到部署的全链路解决方案。让数字分身不仅替 TA 说话,还听起来像 TA 本人。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">除了留住记忆里的 TA,你也可以创造自己的数字分身。 你有没有想过,和自己聊天会是什么样的体验?你会喜欢和自己聊天吗?</span></p> <figure data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 10px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;padding: 0px;display: flex;flex-direction: column;justify-content: center;align-items: center;> <span leaf=""><img src="/upload/c95ec2961c48f761d92136e9e33f1c0b.png" class="rich_pages wxw-img" data-ratio="1.6527415143603132" data-type="png" data-w="383" style="box-sizing: border-box;vertical-align: middle;border-style: none;display: block;margin: 0px auto;max-width: 100%;border-width: 3px;border-color: rgba(0, 0, 0, 0.4);border-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100059037"></span> </figure> <figure data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 10px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;padding: 0px;display: flex;flex-direction: column;justify-content: center;align-items: center;> <span leaf=""><img src="/upload/d5eab91b448d055b90770730dcde8b8f.png" class="rich_pages wxw-img" data-ratio="2.160664819944598" data-type="png" data-w="361" style="box-sizing: border-box;vertical-align: middle;border-style: none;display: block;margin: 0px auto;max-width: 100%;border-width: 3px;border-color: rgba(0, 0, 0, 0.4);border-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100059036"></span> </figure> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">数字人技术的可玩性确实很高,一经推出,内网和外网上都引来了一大波网友的关注。许多网友也是纷纷脑洞大开。<img class="rich_pages wxw-img" data-imgfileid="100059035" data-ratio="0.36848072562358275" src="/upload/e6eb27ca556719a09e28c5e699f02415.jpg" data-type="jpeg" data-w="882" style="box-sizing: border-box;vertical-align: middle;border-style: none;display: block;margin: 0px auto;max-width: 100%;"></span></p> <figure data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 10px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;padding: 0px;display: flex;flex-direction: column;justify-content: center;align-items: center;> <span leaf=""><img src="/upload/1f6e68d8647c383ef84662fbcd9dc00e.jpg" class="rich_pages wxw-img" data-ratio="0.38163716814159293" data-type="jpeg" data-w="904" style="box-sizing: border-box;vertical-align: middle;border-style: none;display: block;margin: 0px auto;max-width: 100%;border-width: 3px;border-color: rgba(0, 0, 0, 0.4);border-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100059034"></span> </figure> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">项目指路: https://github.com/xming521/weclone</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">我们先一起来了解一下WeClone的核心功能。</span></p> <h1 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 24px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">核心功能</span></span></h1> <ul style="box-sizing: border-box;margin: 8px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;list-style-type: disc;padding: 0px 25px; class="list-paddingleft-1"> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">使用微信聊天记录微调LLM</span> </section></li> </ul> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">WeClone 支持导出微信聊天记录,并进行格式化处理成问答格式,用于模型微调。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">在模型微调方面,WeClone 基于 LoRA 支持对主流 0.5B–7B 规模模型进行低资源微调,包括 ChatGLM3-6B、Qwen2.5-7B 等模型。有效捕捉用户的语言习惯和表达方式。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">模型训练需要约 16GB 显存,显存需求可控,训练效率高,满足小样本低资源场景。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">需要的显存估算值如下:</span></p> <figure data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 10px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;padding: 0px;display: flex;flex-direction: column;justify-content: center;align-items: center;> <span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100059043" data-ratio="0.36944444444444446" src="/upload/aeef04881126d1c8e6ad87a43fa4af0d.jpg" data-type="jpeg" data-w="1080" style="box-sizing: border-box;vertical-align: middle;border-style: none;display: block;margin: 0px auto;max-width: 100%;border-width: 3px;border-color: rgba(0, 0, 0, 0.4);border-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;"></span> </figure> <ul style="box-sizing: border-box;margin: 8px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;list-style-type: disc;padding: 0px 25px; class="list-paddingleft-1"> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">使用微信语音消息 + Spark-TTS 模型实现高质量声音克隆</span> </section></li> </ul> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">项目配套子模块 WeClone - audio (https://github.com/xming521/WeClone/tree/master/WeClone-audio)基于轻量级 Tacotron 或 WavLM 模型,用 0.5B 参数模型和 5 秒语音样本,就可以克隆出相似度高达95%的声音,进一步增强数字分身的真实感。</span></p> <ul style="box-sizing: border-box;margin: 8px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;list-style-type: disc;padding: 0px 25px; class="list-paddingleft-1"> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">多平台部署</span> </section></li> </ul> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">通过 AstrBot 框架,将数字分身部署到微信、QQ、Telegram、企业微信、飞书等多个聊天平台。一行命令即可快速启动,即可与数字分身实时对话。</span></p> <h1 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 24px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">可能的应用场景</span></span></h1> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">个人助理定制:在你忙碌时,数字分身可以代替你回复消息,处理日常事务,例如写邮件、回复评论等。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">内容创作:快速产出特定风格的个性化文本内容,帮助你运营多个风格一致的小号。例如写推文、写脚本、写解说等。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">数字永生:创建自己或者他人的数字分身,实现永存。</span></p> <h1 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 24px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">核心模块介绍</span></span></h1> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">WeClone 的数字分身全链路核心模块包括了三部分:</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">数据导出与预处理 → LoRA模型微调 → 多平台部署</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">接下来,我们分模块看看各部分的技术亮点。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">1. 数据导出与预处理</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">WeClone 首先将微信导出的 CSV/SQLite 文件转为标准的 JSON 文件。 然后进行文本清洗,主要是为了去除噪声,以及过滤掉敏感信息。最后分割对话信息,对聊天记录进行分段标注,并保留时间戳、</span></p> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">2. 模型微调</span> </section> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">WeClone 使用 ChatGLM3-6B 为基础模型,基于 LoRA 框架进行 SFT(Supervised Fine-Tuning)阶段的微调。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">关键的亮点点包括:</span></p> <ul style="box-sizing: border-box;margin: 8px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;list-style-type: disc;padding: 0px 25px; class="list-paddingleft-1"> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <p style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;padding: 8px 0px;"><span leaf="">使用低秩适配器,显著减少可训练参数。</span></p> </section></li> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <p style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;padding: 8px 0px;"><span leaf="">单机/分布式训练兼容,支持多卡训练加速。</span></p> </section></li> </ul> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">3. 模型部署</span> </section> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">WeClone 使用 FastAPI/Flask 打包微调后的模型,支持 GPU/CPU 混合部署、多平台登录,并且支持自定义参数。</span></p> <h1 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 24px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">安装部署教程</span></span></h1> <h2 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 22px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">环境搭建</span></span></h2> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">建议使用 uv ,这是一个非常快速的 Python 环境管理器。安装uv后,您可以使用以下命令创建一个新的Python环境并安装依赖项,注意这不包含xcodec(音频克隆)功能的依赖:</span></p> <pre data-tool="mdnice编辑器" style="box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;margin: 10px 0px;overflow: auto;color: rgb(0, 0, 0);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;border-radius: 5px;box-shadow: rgba(0, 0.55) 0px 2px 10px;padding: 0px;><span data-cacheurl="" data-remoteid="" style="box-sizing: border-box;display: block;background: none 10px 10px / 40px no-repeat rgb(40, 44, 52);height: 30px;width: 657px;margin-bottom: -7px;border-radius: 5px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg 3lqm1xhojtywase9jcyjtk01xictfvxcxrmk34ltibuhdw79ehsgupccayqliqiaqv3vzpshwgv7f3olvgib6mh7usiazhcibcmpyp 640?wx_fmt="svg&from=appmsg");""></span><code style="box-sizing: border-box;font-size: 12px;font-family: Consolas, Monaco, Menlo, monospace;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);border-radius: 5px;display: -webkit-box;"><span leaf="">git </span><span style="box-sizing: border-box;color: rgb(230, 192, 123);line-height: 26px;"><span leaf="">clone</span></span><span leaf=""> https://github.com/xming521/WeClone.git</span><span leaf=""><br></span><span style="box-sizing: border-box;color: rgb(230, 192, 123);line-height: 26px;"><span leaf="">cd</span></span><span leaf=""> WeClone</span><span leaf=""><br></span><span leaf="">uv venv .venv --python=3.9</span><span leaf=""><br></span><span style="box-sizing: border-box;color: rgb(230, 192, 123);line-height: 26px;"><span leaf="">source</span></span><span leaf=""> .venv/bin/activate</span><span leaf=""><br></span><span leaf="">uv pip install --group main -e . </span><span leaf=""><br></span><span leaf="">Note</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">训练以及推理相关配置统一在文件 settings.json。</span></p> <h2 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 22px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">数据准备</span></span></h2> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">请使用 PyWxDump 提取微信聊天记录。下载软件并解密数据库后,点击聊天备份,导出类型为 CSV ,可以导出多个联系人或群聊,然后将导出的位于 </span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;height: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">wxdump_tmp/export</span></code><span leaf=""> 的 csv 文件夹放在 </span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;height: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">./data</span></code><span leaf=""> 目录即可,也就是不同人聊天记录的文件夹一起放在 </span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;height: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">./data/csv</span></code><span leaf="">。 示例数据位于 </span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;height: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">data/example_chat.csv</span></code><span leaf="">。</span></p> <h2 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 22px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">数据预处理</span></span></h2> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">项目默认去除了数据中的手机号、身份证号、邮箱、网址。还提供了一个禁用词词库 blocked_words ,可以自行添加需要过滤的词句(会默认去掉包括禁用词的整句)。 执行 </span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;height: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">./make_dataset/csv_to_json.py</span></code><span leaf=""> 脚本对数据进行处理。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">在同一人连续回答多句的情况下,有三种处理方式:</span></p> <figure data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 10px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;padding: 0px;display: flex;flex-direction: column;justify-content: center;align-items: center;> <span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100059042" data-ratio="0.42857142857142855" src="/upload/003c06b80a3da83d6e95eae841b3695d.jpg" data-type="jpeg" data-w="700" style="box-sizing: border-box;vertical-align: middle;border-style: none;display: block;margin: 0px auto;max-width: 100%;border-width: 3px;border-color: rgba(0, 0, 0, 0.4);border-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;"></span> </figure> <h2 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 22px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">模型下载</span></span></h2> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">首选在 Hugging Face 下载 ChatGLM3 模型。如果在 Hugging Face 模型的下载中遇到了问题,可以通过下述方法使用魔搭社区,后续训练推理都需要先执行 </span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;height: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">export USE_MODELSCOPE_HUB=1</span></code><span leaf=""> 来使用魔搭社区的模型。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">由于模型较大,下载过程比较漫长请耐心等待。</span></p> <pre data-tool="mdnice编辑器" style="box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;margin: 10px 0px;overflow: auto;color: rgb(0, 0, 0);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;border-radius: 5px;box-shadow: rgba(0, 0.55) 0px 2px 10px;padding: 0px;><span data-cacheurl="" data-remoteid="" style="box-sizing: border-box;display: block;background: none 10px 10px / 40px no-repeat rgb(40, 44, 52);height: 30px;width: 657px;margin-bottom: -7px;border-radius: 5px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg 3lqm1xhojtywase9jcyjtk01xictfvxcxrmk34ltibuhdw79ehsgupccayqliqiaqv3vzpshwgv7f3olvgib6mh7usiazhcibcmpyp 640?wx_fmt="svg&from=appmsg");""></span><code style="box-sizing: border-box;font-size: 12px;font-family: Consolas, Monaco, Menlo, monospace;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);border-radius: 5px;display: -webkit-box;"><span style="box-sizing: border-box;color: rgb(230, 192, 123);line-height: 26px;"><span leaf="">export</span></span><span leaf=""> USE_MODELSCOPE_HUB=1 </span><span style="box-sizing: border-box;color: rgb(92, 99, 112);font-style: italic;line-height: 26px;"><span leaf=""># Windows 使用 `set USE_MODELSCOPE_HUB=1`</span></span><span leaf=""><br></span><span leaf="">git lfs install</span><span leaf=""><br></span><span leaf="">git </span><span style="box-sizing: border-box;color: rgb(230, 192, 123);line-height: 26px;"><span leaf="">clone</span></span><span leaf=""> https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">魔搭社区的 </span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;height: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">modeling_chatglm.py</span></code><span leaf=""> 文件需要更换为 Hugging Face 的。</span></p> <h2 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 22px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">配置参数并微调模型</span></span></h2> <ul style="box-sizing: border-box;margin: 8px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;list-style-type: disc;padding: 0px 25px; class="list-paddingleft-1"> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <p style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;padding: 8px 0px;"><span leaf="">(可选) 修改 settings.json 选择本地下载好的其他模型。</span></p> </section></li> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <p style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;padding: 8px 0px;"><span leaf="">修改</span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;height: auto;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">per_device_train_batch_size</span></code><span leaf="">以及</span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;height: auto;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">gradient_accumulation_steps</span></code><span leaf="">来调整显存占用。</span></p> </section></li> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <p style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;padding: 8px 0px;"><span leaf="">可以根据自己数据集的数量和质量修改</span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;height: auto;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">num_train_epochs</span></code><span leaf="">、</span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;height: auto;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">lora_rank</span></code><span leaf="">、</span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;height: auto;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">lora_dropout</span></code><span leaf="">等参数。</span></p> </section></li> </ul> <h3 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 20px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">单卡训练</span></span></h3> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">运行 </span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;height: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">src/train_sft.py</span></code><span leaf=""> 进行sft阶段微调,本人loss只降到了3.5左右,降低过多可能会过拟合,我使用了大概2万条整合后的有效数据。</span></p> <pre data-tool="mdnice编辑器" style="box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;margin: 10px 0px;overflow: auto;color: rgb(0, 0, 0);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;border-radius: 5px;box-shadow: rgba(0, 0.55) 0px 2px 10px;padding: 0px;><span data-cacheurl="" data-remoteid="" style="box-sizing: border-box;display: block;background: none 10px 10px / 40px no-repeat rgb(40, 44, 52);height: 30px;width: 657px;margin-bottom: -7px;border-radius: 5px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg 3lqm1xhojtywase9jcyjtk01xictfvxcxrmk34ltibuhdw79ehsgupccayqliqiaqv3vzpshwgv7f3olvgib6mh7usiazhcibcmpyp 640?wx_fmt="svg&from=appmsg");""></span><code style="box-sizing: border-box;font-size: 12px;font-family: Consolas, Monaco, Menlo, monospace;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);border-radius: 5px;display: -webkit-box;"><span leaf="">python src/train_sft.py</span><span leaf=""><br></span></code></pre> <h3 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 20px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">多卡训练</span></span></h3> <pre data-tool="mdnice编辑器" style="box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;margin: 10px 0px;overflow: auto;color: rgb(0, 0, 0);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;border-radius: 5px;box-shadow: rgba(0, 0.55) 0px 2px 10px;padding: 0px;><span data-cacheurl="" data-remoteid="" style="box-sizing: border-box;display: block;background: none 10px 10px / 40px no-repeat rgb(40, 44, 52);height: 30px;width: 657px;margin-bottom: -7px;border-radius: 5px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg 3lqm1xhojtywase9jcyjtk01xictfvxcxrmk34ltibuhdw79ehsgupccayqliqiaqv3vzpshwgv7f3olvgib6mh7usiazhcibcmpyp 640?wx_fmt="svg&from=appmsg");""></span><code style="box-sizing: border-box;font-size: 12px;font-family: Consolas, Monaco, Menlo, monospace;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);border-radius: 5px;display: -webkit-box;"><span leaf="">uv pip install deepspeed</span><span leaf=""><br></span><span leaf="">deepspeed --num_gpus=使用显卡数量 src/train_sft.py</span><span leaf=""><br></span></code></pre> <h2 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 22px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">使用浏览器demo简单推理</span></span></h2> <pre data-tool="mdnice编辑器" style="box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;margin: 10px 0px;overflow: auto;color: rgb(0, 0, 0);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;border-radius: 5px;box-shadow: rgba(0, 0.55) 0px 2px 10px;padding: 0px;><span data-cacheurl="" data-remoteid="" style="box-sizing: border-box;display: block;background: none 10px 10px / 40px no-repeat rgb(40, 44, 52);height: 30px;width: 657px;margin-bottom: -7px;border-radius: 5px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg 3lqm1xhojtywase9jcyjtk01xictfvxcxrmk34ltibuhdw79ehsgupccayqliqiaqv3vzpshwgv7f3olvgib6mh7usiazhcibcmpyp 640?wx_fmt="svg&from=appmsg");""></span><code style="box-sizing: border-box;font-size: 12px;font-family: Consolas, Monaco, Menlo, monospace;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);border-radius: 5px;display: -webkit-box;"><span leaf="">python ./src/web_demo.py </span><span leaf=""><br></span></code></pre> <h2 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 22px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">使用接口进行推理</span></span></h2> <pre data-tool="mdnice编辑器" style="box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;margin: 10px 0px;overflow: auto;color: rgb(0, 0, 0);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;border-radius: 5px;box-shadow: rgba(0, 0.55) 0px 2px 10px;padding: 0px;><span data-cacheurl="" data-remoteid="" style="box-sizing: border-box;display: block;background: none 10px 10px / 40px no-repeat rgb(40, 44, 52);height: 30px;width: 657px;margin-bottom: -7px;border-radius: 5px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg 3lqm1xhojtywase9jcyjtk01xictfvxcxrmk34ltibuhdw79ehsgupccayqliqiaqv3vzpshwgv7f3olvgib6mh7usiazhcibcmpyp 640?wx_fmt="svg&from=appmsg");""></span><code style="box-sizing: border-box;font-size: 12px;font-family: Consolas, Monaco, Menlo, monospace;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);border-radius: 5px;display: -webkit-box;"><span leaf="">python ./src/api_service.py</span><span leaf=""><br></span></code></pre> <h2 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 22px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">使用常见聊天问题测试</span></span></h2> <pre data-tool="mdnice编辑器" style="box-sizing: border-box;font-size: 16px;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;margin: 10px 0px;overflow: auto;color: rgb(0, 0, 0);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;border-radius: 5px;box-shadow: rgba(0, 0.55) 0px 2px 10px;padding: 0px;><span data-cacheurl="" data-remoteid="" style="box-sizing: border-box;display: block;background: none 10px 10px / 40px no-repeat rgb(40, 44, 52);height: 30px;width: 657px;margin-bottom: -7px;border-radius: 5px;background-image: url(" https: mmbiz.qpic.cn mmbiz_svg 3lqm1xhojtywase9jcyjtk01xictfvxcxrmk34ltibuhdw79ehsgupccayqliqiaqv3vzpshwgv7f3olvgib6mh7usiazhcibcmpyp 640?wx_fmt="svg&from=appmsg");""></span><code style="box-sizing: border-box;font-size: 12px;font-family: Consolas, Monaco, Menlo, monospace;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);border-radius: 5px;display: -webkit-box;"><span leaf="">python ./src/api_service.py</span><span leaf=""><br></span><span leaf="">python ./src/test_model.py</span><span leaf=""><br></span></code></pre> <h2 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 22px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">部署到聊天机器人</span></span></h2> <h3 data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 30px 0px 15px;color: rgba(0, 0, 0, 0.85);font-weight: 500;line-height: 1.6;font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;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;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;padding: 0px;display: block;><span style="box-sizing: border-box;font-size: 20px;color: rgb(0, 0, 0);line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: bold;display: block;"><span leaf="">AstrBot方案</span></span></h3> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">AstrBot 是易上手的多平台 LLM 聊天机器人及开发框架。</span></p> <p data-tool="mdnice编辑器" style="box-sizing: border-box;margin: 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0em;orphans: 2;text-align: left;text-indent: 0em;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;line-height: 1.8em;padding: 8px 0px;><span leaf="">使用步骤:</span></p> <ol style="box-sizing: border-box;margin: 8px 0px;color: rgb(0, 0, 0);font-family: Optima, " microsoft yahei, pingfangsc-regular, 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: 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;list-style-type: decimal;padding: 0px 25px; class="list-paddingleft-1"> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">部署 AstrBot</span> </section></li> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">在 AstrBot 中部署消息平台</span> </section></li> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">执行 </span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf="">python ./src/api_service.py </span></code><span leaf="">,启动api服务</span> </section></li> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">在 AstrBot 中新增服务提供商,类型选择OpenAI,API Base URL 根据AstrBot部署方式填写(例如docker部署可能为http://172.17.0.1:8005/v1) ,模型填写gpt-3.5-turbo</span> </section></li> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">微调后不支持工具调用,请先关掉默认的工具,消息平台发送指令:</span><code style="box-sizing: border-box;font-size: 14px;font-family: Consolas, Monaco, Menlo, monospace;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none 0% 0% / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;"><span leaf=""> /tool off reminder</span></code><span leaf="">,否则会没有微调后的效果。</span> </section></li> <li style="box-sizing: border-box;"> <section style="box-sizing: border-box;margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">根据微调时使用的 default_system ,在 AstrBot 中设置系统提示词。</span> </section></li> </ol> <p data-pm-slice="0 0 []" class="js_darkmode__82" style="-webkit-tap-highlight-color: transparent;margin: 0px 8px 8px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgb(163, 163, 163);background-color: rgb(255, 255, 255);clear: both;min-height: 1em;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;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;font-family: system-ui, -apple-system, BlinkMacSystemFont, " helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;letter-spacing: 0.544px;><span class="js_darkmode__83" 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;text-decoration-color: rgba(0, 0, 0, 0.9);background-color: rgb(255, 255, 255);color: rgb(178, 178, 178);font-family: system-ui, -apple-system, BlinkMacSystemFont, " helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;text-align: left;text-decoration-style: solid;letter-spacing: 0.578px;font-size: 12px;><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="color: rgb(136, 136, 136);">>/ 本期作者:Tashi & JackCui</span></span></span></p> <p class="js_darkmode__84" style="-webkit-tap-highlight-color: transparent;margin: 0px 8px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgb(163, 163, 163);background-color: rgb(255, 255, 255);clear: both;min-height: 1em;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;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;font-family: system-ui, -apple-system, BlinkMacSystemFont, " helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;letter-spacing: 0.544px;><span class="js_darkmode__85" 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;text-decoration-color: rgba(0, 0, 0, 0.9);color: rgb(178, 178, 178);text-decoration-style: solid;letter-spacing: 0.578px;font-size: 12px;"><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="color: rgb(136, 136, 136);">>/ JackCui:AI领域从业者,毕业于东北大学,</span></span><span data-pm-slice="2 2 [" para,{tagname:section,attributes:{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);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: georgia, pingfangsc-light, serif;font-size: 16px;color: rgb(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 []},namespaceuri:http: www.w3.org 1999 xhtml},para,{tagname:p,attributes:{style:outline: 0px;font-family: system-ui, -apple-system, blinkmacsystemfont, \helvetica neue\, \pingfang sc\, \hiragino sans gb\, \microsoft yahei ui\, yahei\, arial, sans-serif;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 24px;margin-left: 8px;margin-right: 8px;},namespaceuri:http: xhtml}] class="js_darkmode__86" 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;text-decoration-color: rgba(0, 0, 0, 0.9);color: rgb(178, 178, 178);text-decoration-style: solid;letter-spacing: 0.578px;font-size: 12px;"><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="color: rgb(136, 136, 136);">大厂</span></span><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="color: rgb(136, 136, 136);">算法工程师,热爱技术分享。</span></span></span></span></p> <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="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="">"苏工!首页崩了!"</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="">打开监控一看:</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">缓存命中率:0% </span><span leaf=""><br></span><span leaf="">数据库QPS:10万+ </span><span leaf=""><br></span><span leaf="">线程阻塞数:2000+</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;"><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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">public</span></span><span leaf=""> Product </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">getProduct</span></span><span style="line-height: 26px;"><span leaf="">(Long id)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> productDao.findById(id); </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;"><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="">这一刻我意识到:</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="">。</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="">今天这篇文章跟大家一起聊聊使用缓存的10条军规,希望对你会有所帮助。</span></p> <section style="text-align: center;" nodeleaf=""> <img src="/upload/53ec07e59e778214b946752893e66a35.png" class="rich_pages wxw-img" data-ratio="0.984" data-s="300,640" data-type="png" data-w="1000" type="block" data-imgfileid="100044696"> </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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">军规1: 避免大key</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> <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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">@Cacheable</span></span><span leaf="">(value = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user"</span></span><span leaf="">, key = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"#id"</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=""> User </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">getUser</span></span><span style="line-height: 26px;"><span leaf="">(Long id)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> userDao.findWithAllRelations(id); </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;"><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="">如果通过id查询用户信息的请求量非常大,会导致频繁的GC。</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">@Cacheable</span></span><span leaf="">(value = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user_base"</span></span><span leaf="">, key = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"#id"</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=""> UserBase </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">getBaseInfo</span></span><span style="line-height: 26px;"><span leaf="">(Long id)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">/*...*/</span></span><span leaf=""> } </span><span leaf=""><br></span><span leaf=""><br></span><span style="color: #61aeee;line-height: 26px;"><span leaf="">@Cacheable</span></span><span leaf="">(value = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user_detail"</span></span><span leaf="">, key = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"#id"</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=""> UserDetail </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">getDetailInfo</span></span><span style="line-height: 26px;"><span leaf="">(Long id)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">/*...*/</span></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;"><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="">缓存不是存储数据的垃圾桶,需要根据数据访问频率、读写比例、数据一致性要求进行分级管理。</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="">大对象缓存会导致内存碎片化,甚至触发Full GC。</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="">建议将基础信息(如用户ID、名称)与扩展信息(如订单记录)分离存储。</span></p> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">军规2: 永远设置过期时间</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><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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">@Cacheable</span></span><span leaf="">(value = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"config"</span></span><span leaf="">, key = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"#key"</span></span><span leaf="">, </span><span leaf=""><br></span><span leaf=""> unless = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"#result == null"</span></span><span leaf="">, </span><span leaf=""><br></span><span leaf=""> cacheManager = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"redisCacheManager"</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=""> String </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">getConfig</span></span><span style="line-height: 26px;"><span leaf="">(String key)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> configDao.get(key); </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;"><span leaf="">Redis配置如下:</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">spring.cache.redis.time-to-live=300000</span></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">//</span></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">5</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">分钟</span></span><span leaf=""> </span><span leaf=""><br></span><span style="color: #98c379;line-height: 26px;"><span leaf="">spring.cache.redis.cache-null-values=false</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;"><span leaf="">需要指定key的存活时间,比如:time-to-live设置成5分钟。</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="">TTL设置公式</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">最优TTL = 平均数据变更周期 × 0.3</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><span leaf=""><br></span><span leaf="">过期时间过短会导致缓存穿透风险,过长会导致数据不一致。</span></p> <blockquote style="margin-top: 20px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;padding-top: 10px;padding-bottom: 10px;padding-left: 20px;padding-right: 10px;border-top-style: none;border-bottom-style: none;border-left-style: solid;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: rgb(53, 179, 120);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;background-attachment: scroll;background-clip: border-box;background-color: rgb(251, 249, 253);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;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;display: block;overflow-x: auto;overflow-y: auto;"> <span style="display: none;color: rgb(0, 0, 0);font-size: 16px;line-height: 1.5em;letter-spacing: 0em;text-align: left;font-weight: normal;"></span> <p style="text-indent: 0em;padding-top: 16px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;color: rgb(63, 63, 63);font-size: 16px;line-height: 1.8em;letter-spacing: 0.02em;text-align: left;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;"><span leaf="">建议采用动态TTL策略。</span></p> </blockquote> <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="">例如电商商品详情页可设置30分钟基础TTL+随机5分钟抖动。</span></p> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">军规3: 避免批量失效</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><span leaf="">所有缓存设置相同TTL,导致每天凌晨集中失效,数据库瞬时被打爆。</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> <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="">使用基础TTL + 随机抖动的方案:</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="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="">long</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">randomTtl</span></span><span style="line-height: 26px;"><span leaf="">(</span><span style="color: #c678dd;line-height: 26px;"><span leaf="">long</span></span><span leaf=""> baseTtl)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> baseTtl + </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">new</span></span><span leaf=""> Random().nextInt(</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">300</span></span><span leaf="">); </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;"><span leaf="">TTL增加0-5分钟随机值。</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redisTemplate.opsForValue().</span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">set</span></span><span leaf="">(key, value, randomTtl(1800), TimeUnit.SECONDS);</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> <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/278a2305b99ac50cce29d78d5526baa9.png" class="rich_pages wxw-img" data-ratio="0.8211009174311926" data-type="png" data-w="872" 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="100044649"></span> </figure> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">军规4: 需要增加熔断降级</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="">我们在使用缓存的时候,需要增加熔断降级策略,防止万一缓存挂了,不能影响整个服务的可用性。</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="">Hystrix实现示例</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">@HystrixCommand</span></span><span leaf="">(fallbackMethod = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"getProductFallback"</span></span><span leaf="">, </span><span leaf=""><br></span><span leaf=""> commandProperties = { </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">@HystrixProperty</span></span><span leaf="">(name = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"circuitBreaker.requestVolumeThreshold"</span></span><span leaf="">, value = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"20"</span></span><span leaf="">), </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">@HystrixProperty</span></span><span leaf="">(name = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"circuitBreaker.sleepWindowInMilliseconds"</span></span><span leaf="">, value = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"5000"</span></span><span leaf="">) </span><span leaf=""><br></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=""> Product </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">getProduct</span></span><span style="line-height: 26px;"><span leaf="">(Long id)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> productDao.findById(id); </span><span leaf=""><br></span><span leaf="">} </span><span leaf=""><br></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">public</span></span><span leaf=""> Product </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">getProductFallback</span></span><span style="line-height: 26px;"><span leaf="">(Long id)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">new</span></span><span leaf=""> Product().setDefault(); </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 返回兜底数据 </span></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> <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/03f2b9b4638dd0eaba5816975201419c.png" class="rich_pages wxw-img" data-ratio="1.4067164179104477" data-type="png" data-w="536" 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="100044645"></span> </figure> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">▶ 军规5: 空值缓存</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="">在用户请求并发量大的业务场景种,我们需要把空值缓存起来。</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="">防止大批量在系统中不存在的用户id,没有命中缓存,而直接查询数据库的情况。</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">public</span></span><span leaf=""> Product </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">getProduct</span></span><span style="line-height: 26px;"><span leaf="">(Long id)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> String key = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"product:"</span></span><span leaf=""> + id; </span><span leaf=""><br></span><span leaf=""> Product product = redis.get(key); </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> (product != </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">null</span></span><span leaf="">) { </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> (product.isEmpty()) { </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 空对象标识 </span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">null</span></span><span leaf="">; </span><span leaf=""><br></span><span leaf=""> } </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> product; </span><span leaf=""><br></span><span leaf=""> } </span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> product = productDao.findById(id); </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> (product == </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">null</span></span><span leaf="">) { </span><span leaf=""><br></span><span leaf=""> redis.setex(key, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">300</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"empty"</span></span><span leaf="">); </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: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">null</span></span><span leaf="">; </span><span leaf=""><br></span><span leaf=""> } </span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> redis.setex(key, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">3600</span></span><span leaf="">, product); </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> 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> <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/24ee71a091bed6927094f957a22f1aed.png" class="rich_pages wxw-img" data-ratio="1.1647597254004576" data-type="png" data-w="874" 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="100044646"></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;"><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="">后面如果有相同的key查询数据,则直接从缓存中返回空值。</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> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">军规6: 分布式锁用Redisson</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="">用Redis做分布式锁的时候,可能会遇到很多问题。</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="">感兴趣的小伙伴可以看看我的这篇文章《<a class="normal_text_link" target="_blank" style="color: rgb(72, 179, 120);font-weight: bold;border-style: none none solid;border-width: 1px;border-color: rgb(30, 107, 184) rgb(30, 107, 184) rgb(72, 179, 120);border-radius: 0px;margin: 0px;padding: 0px;text-decoration: none;overflow-wrap: break-word;" href="https://mp.weixin.qq.com/s?__biz=MzkwNjMwMTgzMQ==&mid=2247490430&idx=1&sn=a1f42f9a981a8f161941a6472f317b10&scene=21#wechat_redirect" textvalue="" linktype="text" data-linktype="2">聊聊redis分布式锁的8大坑</a>》。</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="">建议大家使用Redisson做分布式锁。</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="">Redisson分布式锁实现</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">public Product getProduct(Long id) { </span><span leaf=""><br></span><span leaf=""> String key = "product:" + id; </span><span leaf=""><br></span><span leaf=""> Product product = redis.get(key); </span><span leaf=""><br></span><span leaf=""> if (product == null) { </span><span leaf=""><br></span><span leaf=""> RLock lock = redisson.getLock("lock:" + key); </span><span leaf=""><br></span><span leaf=""> try { </span><span leaf=""><br></span><span leaf=""> if (lock.tryLock(3, 30, TimeUnit.SECONDS)) { </span><span leaf=""><br></span><span leaf=""> product = productDao.findById(id); </span><span leaf=""><br></span><span leaf=""> redis.setex(key, 3600, product); </span><span leaf=""><br></span><span leaf=""> } </span><span leaf=""><br></span><span leaf=""> } finally { </span><span leaf=""><br></span><span leaf=""> lock.unlock(); </span><span leaf=""><br></span><span leaf=""> } </span><span leaf=""><br></span><span leaf=""> } </span><span leaf=""><br></span><span leaf=""> return 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> <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/37b4f387e5a7c721194b331aa6e7bc12.png" class="rich_pages wxw-img" data-ratio="1.3673469387755102" data-type="png" data-w="686" 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="100044648"></span> </figure> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">军规7: 延迟双删策略</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="">在保证数据库和缓存双写数据一致性的业务场景种,可以使用延迟双删的策略。</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">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=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 1. 先删缓存 </span></span><span leaf=""><br></span><span leaf=""> redis.delete(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"product:"</span></span><span leaf=""> + product.getId()); </span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 2. 更新数据库 </span></span><span leaf=""><br></span><span leaf=""> productDao.update(product); </span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 3. 延时再删 </span></span><span leaf=""><br></span><span leaf=""> executor.schedule(() -> { </span><span leaf=""><br></span><span leaf=""> redis.delete(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"product:"</span></span><span leaf=""> + product.getId()); </span><span leaf=""><br></span><span leaf=""> }, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">500</span></span><span leaf="">, TimeUnit.MILLISECONDS); </span><span leaf=""><br></span><span leaf="">}</span><span leaf=""><br></span></code></pre> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">军规8: 最终一致性方案</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="">延迟双删可能还有其他的问题。</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="">对延迟双删问题比较感兴趣的小伙伴可以看看我的《<a class="normal_text_link" target="_blank" style="color: rgb(72, 179, 120);font-weight: bold;border-style: none none solid;border-width: 1px;border-color: rgb(30, 107, 184) rgb(30, 107, 184) rgb(72, 179, 120);border-radius: 0px;margin: 0px;padding: 0px;text-decoration: none;overflow-wrap: break-word;" href="https://mp.weixin.qq.com/s?__biz=MzkwNjMwMTgzMQ==&mid=2247493521&idx=1&sn=bff84e7a819d79e4b8eb7e722e96ddfc&scene=21#wechat_redirect" textvalue="" linktype="text" data-linktype="2">如何保证数据库和缓存双写一致性?</a>》,里面有详细的介绍。</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="">基于Binlog的方案</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/6f8b1ec9793c8ef963acb02ff3d4e315.png" class="rich_pages wxw-img" data-ratio="0.3648148148148148" data-type="png" data-w="1080" 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="100044647"></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;"><span leaf="">DB更新数据之后,Canal会自动监听数据的变化,它会解析数据事件,然后发送一条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;"><span leaf="">在MQ消费者中,删除缓存。</span></p> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">军规9: 热点数据预加载</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="">对于一些经常使用的热点数据,我们可以提前做数据的预加载。</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">// 使用Redis HyperLogLog统计访问频率 </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="">recordAccess</span></span><span style="line-height: 26px;"><span leaf="">(Long productId)</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> String key = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"access:product:"</span></span><span leaf=""> + productId; </span><span leaf=""><br></span><span leaf=""> redis.pfadd(key, UUID.randomUUID().toString()); </span><span leaf=""><br></span><span leaf=""> redis.expire(key, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">60</span></span><span leaf="">); </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 统计最近60秒 </span></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="">@Scheduled</span></span><span leaf="">(fixedRate = </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">10000</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="">detectHotKeys</span></span><span style="line-height: 26px;"><span leaf="">()</span></span><span leaf=""> </span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> Set <string> keys = redis.keys( </string></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"access:product:*"</span></span><span leaf="">); </span><span leaf=""><br></span><span leaf=""> keys.forEach(key -> { </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">long</span></span><span leaf=""> count = redis.pfcount(key); </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> (count > </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1000</span></span><span leaf="">) { </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// 阈值 </span></span><span leaf=""><br></span><span leaf=""> Long productId = extractId(key); </span><span leaf=""><br></span><span leaf=""> preloadProduct(productId); </span><span leaf=""><br></span><span leaf=""> } </span><span leaf=""><br></span><span leaf=""> }); </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;"><span leaf="">定时任务检测热点,并且更新到缓存中。</span></p> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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="">军规10: 根据场景选择数据结构</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><span leaf="">某社交平台使用String类型存储用户信息。</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="">错误用String存储对象:</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.set(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user:123"</span></span><span leaf="">, JSON.toJSONString(user)); </span><span leaf=""><br></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;"><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="">导致问题:</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="">序列化/反序列化开销大</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> <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> </ol> <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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">// 使用Hash存储 </span><span leaf=""><br></span><span leaf="">redis.opsForHash().putAll(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user:123"</span></span><span leaf="">, userToMap(user)); </span><span leaf=""><br></span><span leaf=""><br></span><span leaf="">// 局部更新 </span><span leaf=""><br></span><span leaf="">redis.opsForHash().put(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user:123"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"age"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"25"</span></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;"><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/a8ab73e854c108b4a638cfc8001fd61e.png" class="rich_pages wxw-img" data-ratio="0.41759259259259257" data-type="png" data-w="1080" 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="100044653"></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;"><span leaf="">各数据结构最佳实践:</span></p> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 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;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: block;flex-direction: unset;float: unset;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span data-cacheurl="" data-remoteid="" style="background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: 15px 15px;width: 15px;height: 15px;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;color: rgb(0, 0, 0);display: inline-block;font-size: 22px;font-weight: bold;flex-direction: unset;float: unset;justify-content: unset;letter-spacing: 0px;line-height: 1.5em;margin-top: 0px;margin-bottom: -2px;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: left;text-indent: 0em;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvlc3igibhkpkry9ewd7klamkieukfniau8jjjgtsqvsdnbaljsrfwcqlnsrgspxofoevpfd0icwvba 640?wx_fmt="png&from=appmsg");""></span><span style="display: none;"></span><span style="font-size: 16px;color: rgb(72, 179, 120);line-height: 1.5em;letter-spacing: 0em;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;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: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 8px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">1.String</span></span><span style="display: none;"></span></h3> <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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.opsForValue().increment(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"article:123:views"</span></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;"><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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.opsForValue().</span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">set</span></span><span leaf="">(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"lock:order:456"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"1"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"NX"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"EX"</span></span><span leaf="">, 30); </span><span leaf=""><br></span></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 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;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: block;flex-direction: unset;float: unset;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span data-cacheurl="" data-remoteid="" style="background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: 15px 15px;width: 15px;height: 15px;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;color: rgb(0, 0, 0);display: inline-block;font-size: 22px;font-weight: bold;flex-direction: unset;float: unset;justify-content: unset;letter-spacing: 0px;line-height: 1.5em;margin-top: 0px;margin-bottom: -2px;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: left;text-indent: 0em;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvlc3igibhkpkry9ewd7klamkieukfniau8jjjgtsqvsdnbaljsrfwcqlnsrgspxofoevpfd0icwvba 640?wx_fmt="png&from=appmsg");""></span><span style="display: none;"></span><span style="font-size: 16px;color: rgb(72, 179, 120);line-height: 1.5em;letter-spacing: 0em;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;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: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 8px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">2.Hash</span></span><span style="display: none;"></span></h3> <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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">Map <string, string> productMap = new HashMap<>(); </string,></span><span leaf=""><br></span><span leaf="">productMap.put(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"name"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"iPhone15"</span></span><span leaf="">); </span><span leaf=""><br></span><span leaf="">productMap.put(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"price"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"7999"</span></span><span leaf="">); </span><span leaf=""><br></span><span leaf="">redis.opsForHash().putAll(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"product:789"</span></span><span leaf="">, productMap); </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;"><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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.opsForHash().put(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"product:789"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"stock"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"100"</span></span><span leaf="">); </span><span leaf=""><br></span></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 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;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: block;flex-direction: unset;float: unset;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span data-cacheurl="" data-remoteid="" style="background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: 15px 15px;width: 15px;height: 15px;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;color: rgb(0, 0, 0);display: inline-block;font-size: 22px;font-weight: bold;flex-direction: unset;float: unset;justify-content: unset;letter-spacing: 0px;line-height: 1.5em;margin-top: 0px;margin-bottom: -2px;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: left;text-indent: 0em;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvlc3igibhkpkry9ewd7klamkieukfniau8jjjgtsqvsdnbaljsrfwcqlnsrgspxofoevpfd0icwvba 640?wx_fmt="png&from=appmsg");""></span><span style="display: none;"></span><span style="font-size: 16px;color: rgb(72, 179, 120);line-height: 1.5em;letter-spacing: 0em;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;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: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 8px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">3.List</span></span><span style="display: none;"></span></h3> <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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.opsForList().leftPush(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"queue:payment"</span></span><span leaf="">, orderJson); </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;"><span leaf="">最新N条记录</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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.opsForList().trim(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user:123:logs"</span></span><span leaf="">, 0, 99); </span><span leaf=""><br></span></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 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;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: block;flex-direction: unset;float: unset;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span data-cacheurl="" data-remoteid="" style="background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: 15px 15px;width: 15px;height: 15px;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;color: rgb(0, 0, 0);display: inline-block;font-size: 22px;font-weight: bold;flex-direction: unset;float: unset;justify-content: unset;letter-spacing: 0px;line-height: 1.5em;margin-top: 0px;margin-bottom: -2px;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: left;text-indent: 0em;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvlc3igibhkpkry9ewd7klamkieukfniau8jjjgtsqvsdnbaljsrfwcqlnsrgspxofoevpfd0icwvba 640?wx_fmt="png&from=appmsg");""></span><span style="display: none;"></span><span style="font-size: 16px;color: rgb(72, 179, 120);line-height: 1.5em;letter-spacing: 0em;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;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: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 8px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">4.Set</span></span><span style="display: none;"></span></h3> <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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.opsForSet().add(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"article:123:tags"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"科技"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"数码"</span></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;"><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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.opsForSet().intersect(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user:123:friends"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"user:456:friends"</span></span><span leaf="">); </span><span leaf=""><br></span></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 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;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: block;flex-direction: unset;float: unset;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span data-cacheurl="" data-remoteid="" style="background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: 15px 15px;width: 15px;height: 15px;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;color: rgb(0, 0, 0);display: inline-block;font-size: 22px;font-weight: bold;flex-direction: unset;float: unset;justify-content: unset;letter-spacing: 0px;line-height: 1.5em;margin-top: 0px;margin-bottom: -2px;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: left;text-indent: 0em;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvlc3igibhkpkry9ewd7klamkieukfniau8jjjgtsqvsdnbaljsrfwcqlnsrgspxofoevpfd0icwvba 640?wx_fmt="png&from=appmsg");""></span><span style="display: none;"></span><span style="font-size: 16px;color: rgb(72, 179, 120);line-height: 1.5em;letter-spacing: 0em;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;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: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 8px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">5.ZSet</span></span><span style="display: none;"></span></h3> <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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.opsForZSet().add(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"leaderboard"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"player1"</span></span><span leaf="">, 2500); </span><span leaf=""><br></span><span leaf="">redis.opsForZSet().reverseRange(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"leaderboard"</span></span><span leaf="">, 0, 9); </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;"><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 wzjhlvpsrd1bfxruh2q6poibbupiadsicoh8mc7nf1iaibe3icsaltt0kyyvgtvcwnfrfnxkwvdp9pjz7unwicfazb8cuylmpedzsaf 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="">redis.opsForZSet().add(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"delay:queue"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"task1"</span></span><span leaf="">, System.currentTimeMillis() + 5000); </span><span leaf=""><br></span></code></pre> <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 ibjzvicc7nz5jvlc3igibhkpkry9ewd7klanic6i98lwsibofutfpiibbg63niclzpy94u7jmp0vgvicwwaokabojtlzlg 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> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 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;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: block;flex-direction: unset;float: unset;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span data-cacheurl="" data-remoteid="" style="background-attachment: scroll;background-clip: border-box;background-color: transparent;background-origin: padding-box;background-position-x: 0%;background-position-y: 0%;background-repeat: no-repeat;background-size: 15px 15px;width: 15px;height: 15px;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;color: rgb(0, 0, 0);display: inline-block;font-size: 22px;font-weight: bold;flex-direction: unset;float: unset;justify-content: unset;letter-spacing: 0px;line-height: 1.5em;margin-top: 0px;margin-bottom: -2px;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: left;text-indent: 0em;text-shadow: none;transform: none;-webkit-box-reflect: unset;background-image: url(" https: mmbiz.qpic.cn sz_mmbiz_png ibjzvicc7nz5jvlc3igibhkpkry9ewd7klamkieukfniau8jjjgtsqvsdnbaljsrfwcqlnsrgspxofoevpfd0icwvba 640?wx_fmt="png&from=appmsg");""></span><span style="display: none;"></span><span style="font-size: 16px;color: rgb(72, 179, 120);line-height: 1.5em;letter-spacing: 0em;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;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: inline-block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 8px;margin-right: 0px;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">缓存治理黄金法则</span></span><span style="display: none;"></span></h3> <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> </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="">Redisson BloomFilter</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="">缓存雪崩</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="">随机TTL+熔断降级</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="">Hystrix/Sentinel</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="">缓存击穿</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="">Redisson Lock</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="">数据一致性</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="">Canal+RocketMQ</span> </section></td> </tr> </tbody> </table> </section> <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/d276f22933dd8aef76666839d6f414c4.png" class="rich_pages wxw-img" data-ratio="0.8157407407407408" data-type="png" data-w="1080" 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="100044654"></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> <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> <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="">真的需要缓存吗?</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> <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> </ol> </section>
作者:微信小助手
<section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; data-pm-slice="0 0 []" nodeleaf=""> <img src="/upload/c694565a4ab6d43f74dd219e960af616.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.42592592592592593" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009149"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">暑假要来了,我的教培业务也要开始进入旺季。小红书、公众号上都要开始做暑假相关的内容</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">但内容生产又成了老大难问题。</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">怎么才能写出不空洞、有垂直业务经验的文章吸引目标客户呢?</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">答案是</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">借助RAG:用行业经验文章形成知识库,每次写文章前都先到知识库搜一下相关内容,再基于这些内容来生产,能最大程度上解决AI幻觉、内容空间等问题。</span></span></p> <section class="mp_profile_iframe_wrp" nodeleaf=""> <mp-common-profile class="js_uneditable custom_select_card mp_profile_iframe" data-pluginname="mpprofile" data-nickname="饼干哥哥AGI" data-alias="BingGanGeGeData" data-from="0" data-headimg="http://mmbiz.qpic.cn/mmbiz_png/RVqfiaDPokvtvAI83ogWKibFMKVghWkyKDyKyfribz2gvQwIz7Y9ibU207DLiaZU9WnBAXoUajibzMxeBviboLDhcVJvg/0?wx_fmt=png" data-signature="数据分析师,分享 AI在实际业务中落地的应用经验。" data-id="MjM5NDI4MTY3NA==" data-is_biz_ban="0" data-service_type="1" data-verify_status="0"></mp-common-profile> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf=""><a class="normal_text_link" target="_blank" style="" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492792&idx=1&sn=8cf5d254b40344ffe569dae83a90280d&scene=21#wechat_redirect" textvalue="昨天文章" data-itemshowtype="0" linktype="text" data-linktype="2">昨天文章</a>也提到,我所有业务工作流都放到了n8n里,但n8n并没有很好的知识库能力。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf=""><a class="normal_text_link" target="_blank" style="" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492544&idx=1&sn=aae5026cdfff3459ca0b6575c08054d0&scene=21#wechat_redirect" textvalue="之前文章" data-itemshowtype="0" linktype="text" data-linktype="2">之前文章</a>有讲到,目前最适合个人或者中小团队用的知识库是Fastgpt,而它最近升级的MCP Server能供外部工作流调用。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">解决方案不就来了吗:</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">把FastGPT上的知识库打包成MCP Server,供n8n在生产内容的时候调用。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">目前效果是这样的:n8n里的AI Agent会通过MCP调用FastGPT里的知识库工作流。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/cfb788202c80d2e8102dd8e8a6f08f8b.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.6421052631578947" data-type="png" data-w="1045" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009145"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span leaf=""><br></span></p> <h2 style="font-style: normal;font-variant-ligatures: normal;font-variant-caps: 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;font-weight: bold;color: rgb(31, 35, 41);font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;letter-spacing: 0.578px;margin-top: 0px;margin-bottom: 8px;font-size: 22px;padding-bottom: 12px;><span style="color: rgb(31, 35, 41);"><span leaf="">一、Fastgpt MCP Server</span></span></h2> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">FastGPT可以通过docker-compose的方式安装,但如果已经安装了,就需要升级到最新版,目前是4.9.11</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf=""><span textstyle="" style="color: rgb(0, 82, 255);text-decoration: underline;">https://github.com/labring/FastGPT/pkgs/container/fastgpt</span></span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/bb709556a7ec20c5c38cfcae388110f4.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.6703703703703704" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009146"> </section> <h3 style="font-style: normal;font-variant-ligatures: normal;font-variant-caps: 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;font-weight: bold;color: rgb(31, 35, 41);font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;letter-spacing: 0.578px;margin-top: 0px;margin-bottom: 8px;font-size: 20px;padding-bottom: 12px;><span style="color: rgb(31, 35, 41);"><span leaf="">升级FastGPT</span></span></h3> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">以宝塔面板为例,打开docker-容器编排</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">如图的位置就是docker-compose的内容,把它复制出来备份好。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/76f19c6aa9d3f8026f3d3812af82758d.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.55" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009148"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">进这里获得最新的docker-compose文件:</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf=""><span textstyle="" style="color: rgb(0, 82, 255);text-decoration: underline;">https://github.com/labring/FastGPT/blob/main/deploy/docker/docker-compose-pgvector.yml</span></span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">如果还没安装的同学,直接用这个来安装即可。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span leaf=""><br></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">这里可以用cursor来</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">对比两个文件的差异,确保我们自定义的部分也同步到新的文件里。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">例如我设置了默认root密码,这个在新的yml文件里也要设置。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/f146e33a7bb1106d74975441f0760319.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.4398148148148148" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009147"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span leaf=""><br></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">接着把改好的docker-compose文件复制黏贴进去如图位置。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">再点「跳转目录」,</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;"><span leaf="">接下来要设置</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">config.json</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/4a5b44df3ea7a15518a5b19e7b42c92f.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.8222523744911805" data-type="png" data-w="737" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009151"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">在这里下载:</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf=""><span textstyle="" style="color: rgb(0, 82, 255);text-decoration: underline;">https://raw.githubusercontent.com/labring/FastGPT/refs/heads/main/projects/app/data/config.json</span></span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">修改图中</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">mpcServerProxyEndpoint</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">,改成你的ip,这是后面n8n工作流需要调用的地址</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/e3b25c533e0c06645cb800088f2147a2.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.39814814814814814" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009152"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">注意,这里暴露的是3005接口,要在宝塔面板添加相关的端口开放权限,确保外部能正常访问才行。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/6e2805032ae23dba946e6f51154dad66.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.5796296296296296" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009154"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">然后把修改好的config.json放到跟前面FastGPT的docker-compose文件同一个目录里。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">也就是前面的「跳转目录」后打开的路径。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/23a904b5c45f09a65a908e613b18ea9b.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.48518518518518516" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009153"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">最后,回到docker面板点停止-更新镜像,即可。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/902566609a129ee70397e21d14df5814.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.17777777777777778" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009150"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">此时打开Fastgpt,就能看到是最新版本了。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/ad241a4412d13e75b7a1c095946d5fe1.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.8833333333333333" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009157"> </section> <h3 style="font-style: normal;font-variant-ligatures: normal;font-variant-caps: 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;font-weight: bold;color: rgb(31, 35, 41);font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;letter-spacing: 0.578px;margin-top: 0px;margin-bottom: 8px;font-size: 20px;padding-bottom: 12px;><span style="color: rgb(31, 35, 41);"><span leaf="">搭建知识库工作流</span></span></h3> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">注意这里不能直接用知识库应用,否则会是经过AI处理后的结果。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">我们</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">要的是原汁原味知识库里匹配到的精准相关内容,就要通过工作流的形式把</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">知识库引用</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">返回。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">如图:</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/c8881cf2953932321338551213c6d7d7.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.43333333333333335" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009159"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">设置好后一定要点</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">保存并发布</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">,如果不发布的话亲测是返回不了结果的。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/35abec0b06e5e79c40ab388be3817a94.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.6837606837606838" data-type="png" data-w="468" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009156"> </section> <h3 style="font-style: normal;font-variant-ligatures: normal;font-variant-caps: 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;font-weight: bold;color: rgb(31, 35, 41);font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;letter-spacing: 0.578px;margin-top: 0px;margin-bottom: 8px;font-size: 20px;padding-bottom: 12px;><span style="color: rgb(31, 35, 41);"><span leaf="">创建MCP服务</span></span></h3> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">接下来,在工作台,点开</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">MCP服务</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">-新建服务</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">这里有一个要点:</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">名字要是英文的</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">,因为n8n是纯国外平台,加上AI大模型,本身对中文就不是很敏感,很容易调用失败。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/4c49efe93a438227854f68ce4a3ca389.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.30462962962962964" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009160"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">新建好后,点</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">开始使用</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">,切换到</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">SSE</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);font-weight: bold;"><span leaf="">这里的</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">接入地址</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;"><span leaf="">就是我们要用的。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/eeae9e38f12eb48cddf410f48435a3ab.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.49537037037037035" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009158"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span leaf=""><br></span></p> <h2 style="font-style: normal;font-variant-ligatures: normal;font-variant-caps: 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;font-weight: bold;color: rgb(31, 35, 41);font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;letter-spacing: 0.578px;margin-top: 0px;margin-bottom: 8px;font-size: 22px;padding-bottom: 12px;><span style="color: rgb(31, 35, 41);"><span leaf="">二、n8n工作流调用</span></span></h2> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">此时回到n8n工作流</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">这是我的小红书模板工作流:</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">先生成多个方向的选题标题,然后根据标题生成内容,后面再根据内容生成多张图片,最终全部保存到飞书多维表格,再调用矩阵工具读取飞书表格进行批量发布。<img src="/upload/ed3189fc38f96d5681df231926827efb.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.4070189592577652" data-type="png" data-w="2479" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009165"></span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">今天我们要解决的是</span></span><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">生成正文这里,通过接入知识库作为参考让AI生成内容效果更佳。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">(预告一下,后面</span></span><span style="font-weight: bold;color: rgb(216, 57, 49);"><span leaf="">如何把内容批量生成图片的流程明天也会分享,欢迎关注催更。</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">)</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf=""><br></span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">在AI Agent的</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">Tool</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">,搜索MCP,找到</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">MCP Client Tool</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">同时要注意n8n的版本确保在1.94.1或以上才有MCP能力</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/0290c9e4eff64d4ee81053478a09c658.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.49722222222222223" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009163"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">接着,在</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">SSE Endpoint</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">输入前面在FastGPT准备好的调用网址。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/e5ffed4c1c86f3dfdefec7c10ea0a817.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.6793893129770993" data-type="png" data-w="786" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009161"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">点</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">Execute step</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">测试一下</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">随便输入一个内容标题</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/07065ba0fc19e4b293b685718928e1ad.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.8518518518518519" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009162"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">看到能正确返回内容了。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);font-weight: bold;"><span leaf="">这里每个业务对于返回内容是否精准的判断都不同,所以我这里就隐去了。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);font-weight: bold;"><span leaf="">具体返回效果如果,可以直接到FastGPT里处理好即可。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/754dc02841ecee7ec13111375dc9d8e4.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.462037037037037" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009164"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">接着,回到AI Agent节点,测试大模型回答</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">注意这里的要点有两个:</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);font-weight: bold;"><span leaf="">1是大模型要有调工具的能力</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">,这里我用的是魔塔社区里的API,</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">Deepseek R1 0528</span></span><span style="color: rgb(31, 35, 41);"><span leaf="">虽然强但无工具调用能力,遗憾不能用。我用的是</span></span><span style="color: rgb(31, 35, 41);padding: 1px 2px;background-color: rgb(245, 246, 247);border: 1px solid rgb(222, 224, 227);border-radius: 4px;margin: 0px 3px;"><span leaf="">Qwen3-235B-A22B</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/3a21e0e7021ebd0b5abab315795f223b.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.7207678883071553" data-type="png" data-w="573" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009167"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);font-weight: bold;text-decoration: underline;"><span leaf="">2是提示词中要明确让AI去掉用MCP工具来获取参考内容</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">除非把MCP名字和简介写的很好,跟当前内容匹配,否则大部分模型不会主动去调用的。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/8d1c8fb5385ef16d3397ccd8941567ff.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.5018518518518519" data-type="png" data-w="1080" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009169"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">最后我们能正常看到大模型有调用mcp即可。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/cfb788202c80d2e8102dd8e8a6f08f8b.png" alt="Image" class="rich_pages wxw-img" data-ratio="0.6421052631578947" data-type="png" data-w="1045" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009166"> </section> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span leaf=""><br></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">至此我们就把FastGPT通过MCP Server的形式整合到了n8n工作流里面。</span></span></p> <p style="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;font-size: 15px;line-height: 2em;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;color: rgb(31, 35, 41);margin: 0px 4px;word-break: break-all;min-height: 20px;><span style="color: rgb(31, 35, 41);"><span leaf="">原本就好用的n8n,补全了它知识库短板,又全面了。。</span></span></p> <section style="color: rgb(0, 0, 0);font-family: " microsoft yahei;font-size: medium;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;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;text-align: center;margin-bottom: 12px; nodeleaf=""> <img src="/upload/381566e72c1f6074d222afa78b909b73.png" alt="Image" class="rich_pages wxw-img" data-ratio="1.0849056603773586" data-type="png" data-w="742" style="display: inline-block;max-width: 100%;height: auto;border-radius: 12px;" data-imgfileid="110009168"> </section> <section data-pm-slice="0 0 []" style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 4px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;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;background-color: rgb(255, 255, 255);letter-spacing: normal;text-align: start;font-size: 15px;line-height: 2em;color: rgb(31, 35, 41);word-break: break-all;min-height: 20px;> <span 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 leaf="" data-pm-slice="1 1 [" para,{tagname:p,attributes:{data-pm-slice:0 0 [],style:-webkit-tap-highlight-color: transparent; margin: 0px 4px; padding: 0px; outline: max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word clear: both; min-height: 20px; font-style: normal; font-variant-ligatures: font-variant-caps: font-weight: 400; letter-spacing: orphans: 2; text-indent: text-transform: none; widows: word-spacing: -webkit-text-stroke-width: white-space: text-decoration-thickness: initial; text-decoration-style: text-decoration-color: font-family: \pingfang sc\, system-ui, -apple-system, blinkmacsystemfont, \helvetica neue\, \hiragino sans gb\, \microsoft yahei ui\, yahei\, arial, sans-serif; background-color: rgb(255, 255, 255); text-align: start; font-size: 15px; line-height: 2em; color: rgb(31, 35, 41); word-break: break-all;},namespaceuri:http: www.w3.org 1999 xhtml},node,{tagname:span,attributes:{style:-webkit-tap-highlight-color: bold;},namespaceuri:http: xhtml}] 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: rgb(31, 35, 41);">以上就是今天分享的全部内容,如果对你有帮助,还请点「推荐」支持</span></span> </section> <section class="mp_profile_iframe_wrp" nodeleaf="" style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);> <mp-common-profile class="custom_select_card mp_profile_iframe js_wx_tap_highlight" data-pluginname="mpprofile" data-nickname="饼干哥哥AGI" data-alias="BingGanGeGeData" data-index="1" data-from="2" data-headimg="http://mmbiz.qpic.cn/mmbiz_png/RVqfiaDPokvtvAI83ogWKibFMKVghWkyKDyKyfribz2gvQwIz7Y9ibU207DLiaZU9WnBAXoUajibzMxeBviboLDhcVJvg/300?wx_fmt=png&wxfrom=19" data-signature="数据分析师,分享 AI在实际业务中落地的应用经验。" data-id="MjM5NDI4MTY3NA==" data-is_biz_ban="0" data-origin_num="283" data-biz_account_status="0" data-service_type="1" data-verify_status="0"></mp-common-profile> </section> <p data-pm-slice="0 0 []" style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 4px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;clear: both;min-height: 20px;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;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;letter-spacing: normal;background-color: rgb(255, 255, 255);text-align: start;font-size: 15px;line-height: 2em;color: rgb(31, 35, 41);word-break: break-all;><span 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: rgb(31, 35, 41);font-weight: bold;"><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: normal;text-decoration: none;">为了帮助大家减少AI信息差,饼干哥哥拉了个AI交流群,围绕着</span><span textstyle="" style="font-weight: bold;text-decoration: underline;">AI数据分析、AI编程、AI工作流、AI Agent</span><span textstyle="" style="font-weight: normal;text-decoration: none;">等进行讨论。</span></span></span></p> <p data-pm-slice="0 0 []" style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 4px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;clear: both;min-height: 20px;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;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;letter-spacing: normal;background-color: rgb(255, 255, 255);text-align: start;font-size: 15px;line-height: 2em;color: rgb(31, 35, 41);word-break: break-all;><span 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: rgb(31, 35, 41);font-weight: bold;"><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: normal;text-decoration: none;">感兴趣的可以关注公众号「饼干哥哥AGI」,</span><span textstyle="" style="font-weight: bold;text-decoration: underline;">后台回复「AI交流群」</span></span></span></p> <p data-pm-slice="0 0 []" style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;clear: both;min-height: 1em;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);><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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><br></span></p> <p data-pm-slice="0 0 []" style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;clear: both;min-height: 1em;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);><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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><span textstyle="" style="font-size: 16px;font-weight: bold;">AI工作流相关阅读:</span></span></p> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);> <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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><span textstyle="" style="font-size: 16px;font-weight: bold;">n8n</span></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);> <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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><a class="normal_text_link" target="_blank" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);margin: 0px;padding: 0px;outline: 0px;color: rgb(87, 107, 149);text-decoration: none;-webkit-user-drag: none;cursor: default;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257491840&idx=1&sn=a6e106f90d221f3dfa042082e797082d&scene=21#wechat_redirect" textvalue="还在手动搭建AI工作流?DeepWiki已经可以自动生成了,附实操教程:生成n8n工作流" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">还在手动搭建AI工作流?DeepWiki已经可以自动生成了,附实操教程:生成n8n工作流</span></a></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);> <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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><a class="normal_text_link" target="_blank" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);margin: 0px;padding: 0px;outline: 0px;color: rgb(87, 107, 149);text-decoration: none;-webkit-user-drag: none;cursor: default;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257491635&idx=1&sn=1844523e1d882a63df13f788ea9a3d82&scene=21#wechat_redirect" textvalue="保姆级教程|用n8n打造一个24小时监控AI博主的工作流【免费下载】" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">保姆级教程|用n8n打造一个24小时监控AI博主的工作流【免费下载】</span></a></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);> <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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><a class="normal_text_link" target="_blank" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);margin: 0px;padding: 0px;outline: 0px;color: rgb(87, 107, 149);text-decoration: none;-webkit-user-drag: none;cursor: default;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257491635&idx=2&sn=9dc221d8f5b86e1cf945b4a87c62fb0f&scene=21#wechat_redirect" textvalue="DeepSeek+开源n8n打造24h推特(X)热点监控Workflow,太绝了!" data-itemshowtype="11" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">DeepSeek+开源n8n打造24h推特(X)热点监控Workflow,太绝了!</span></a></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);> <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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><a class="normal_text_link" target="_blank" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);margin: 0px;padding: 0px;outline: 0px;color: rgb(87, 107, 149);text-decoration: none;-webkit-user-drag: none;cursor: default;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492503&idx=1&sn=3a7df03d5336136b251ac5ef06c820ed&scene=21#wechat_redirect" textvalue="用n8n做AI工作流驱动网站出海赚美金1:连接Supabase数据库" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">用n8n做AI工作流驱动网站出海赚美金1:连接Supabase数据库</span></a></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);> <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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><a class="normal_text_link" target="_blank" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);margin: 0px;padding: 0px;outline: 0px;color: rgb(87, 107, 149);text-decoration: none;-webkit-user-drag: none;cursor: default;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492588&idx=1&sn=1e8d70fffdf4d6f44655fdf70af3324d&scene=21#wechat_redirect" textvalue="用n8n做AI工作流驱动网站出海赚美金2:网站截图与写 SEO友好的介绍" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">用n8n做AI工作流驱动网站出海赚美金2:网站截图与写 SEO友好的介绍</span></a></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;> <span leaf="" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;><a class="normal_text_link" target="_blank" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);margin: 0px;padding: 0px;outline: 0px;color: rgb(87, 107, 149);text-decoration: none;-webkit-user-drag: none;cursor: default;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492766&idx=1&sn=5a3ba8c827fd1711ebaeee7ae657ddd0&scene=21#wechat_redirect" textvalue="出海赚美金:用n8n搭建「Reddit商机搜索与洞察」 AI Agent自动化寻找蓝海市场,发现真实痛点" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">出海赚美金:用n8n搭建「Reddit商机搜索与洞察」 AI Agent自动化寻找蓝海市场,发现真实痛点</span></a></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;> <span leaf="" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;><a class="normal_text_link" target="_blank" style="" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492792&idx=1&sn=8cf5d254b40344ffe569dae83a90280d&scene=21#wechat_redirect" textvalue="数据安全无小事,免费用Github定时备份n8n工作流" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">数据安全无小事,免费用Github定时备份n8n工作流</span></a></span> </section> <section 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.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);> <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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><br></span> </section> <p data-pm-slice="2 2 []" style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 4px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;clear: both;min-height: 20px;font-family: " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;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;background-color: rgb(255, 255, 255);letter-spacing: normal;text-align: start;font-size: 15px;line-height: 2em;color: rgb(31, 35, 41);word-break: break-all;><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;">Dify</span></span></p> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);> <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;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;><a class="normal_text_link" target="_blank" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);margin: 0px;padding: 0px;outline: 0px;color: rgb(87, 107, 149);text-decoration: none;-webkit-user-drag: none;cursor: default;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492166&idx=1&sn=21e5875be172263727868d3ff0f7e893&scene=21#wechat_redirect" textvalue="我用Dify把飞书表格的「AI提示词库」打包成了MCP Server给AI使用和管理" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">我用Dify把飞书表格的「AI提示词库」打包成了MCP Server给AI使用和管理</span></a></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;> <span leaf="" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;><a class="normal_text_link" target="_blank" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);margin: 0px;padding: 0px;outline: 0px;color: rgb(87, 107, 149);text-decoration: none;-webkit-user-drag: none;cursor: default;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492045&idx=1&sn=d9c00336d8297a2bf5213af22c6f83dd&scene=21#wechat_redirect" textvalue="5000字教程:用AI实时查询数据库,自动生成可视化图表 | Dify工作流" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">5000字教程:用AI实时查询数据库,自动生成可视化图表 | Dify工作流</span></a></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;> <span leaf="" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;><a class="normal_text_link" target="_blank" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);margin: 0px;padding: 0px;outline: 0px;color: rgb(87, 107, 149);text-decoration: none;-webkit-user-drag: none;cursor: default;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492252&idx=1&sn=6057e987439e3b354dfe2f96752e1686&scene=21#wechat_redirect" textvalue="Dify工作流:用爬虫批量把公众号文章存到AI知识库 | 保姆级教程" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">Dify工作流:用爬虫批量把公众号文章存到AI知识库 | 保姆级教程</span></a></span> </section> <section style="-webkit-tap-highlight-color: transparent;margin: 0px 0px 24px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: 0.544px;orphans: 2;text-align: justify;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;font-family: " pingfang sc, system-ui, -apple-system, system-ui, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;> <span leaf="" style="-webkit-tap-highlight-color: transparent;margin: 0px;padding: 0px;outline: 0px;max-width: 100%;color: rgba(0, 0, 0, 0.9);font-size: 17px;font-family: mp-quote, " pingfang sc, system-ui, -apple-system, blinkmacsystemfont, helvetica neue, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height: 1.6;letter-spacing: 0.034em;font-style: normal;font-weight: normal;box-sizing: border-box !important;overflow-wrap: break-word !important;><a class="normal_text_link" target="_blank" style="" href="https://mp.weixin.qq.com/s?__biz=MjM5NDI4MTY3NA==&mid=2257492544&idx=1&sn=aae5026cdfff3459ca0b6575c08054d0&scene=21#wechat_redirect" textvalue="一文看懂 AI 工作流平台怎么选? 从使用场景对比 Dify、n8n、Coze、Fastgpt、Ragflow" data-itemshowtype="0" linktype="text" data-linktype="2"><span textstyle="" style="font-size: 16px;">一文看懂 AI 工作流平台怎么选? 从使用场景对比 Dify、n8n、Coze、Fastgpt、Ragflow</span></a></span> </section> <p style="display: none;"> <mp-style-type data-value="3"></mp-style-type></p>
作者:微信小助手
<p data-line="1" style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; data-pm-slice="0 0 []"><span leaf="">想象一下这个场景:用户正愉快地使用着你的 Web 应用,而你刚刚在服务器上部署了一个重要的新版本,修复了 Bug、带来了炫酷的新功能。用户对此毫不知情,仍在旧版本上操作,这可能会导致数据错乱、遇到已修复的 Bug,或者错过了你精心准备的新体验。</span></p> <p data-line="3" style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">那么,前端如何能够自动检测到代码已经更新,并友好地提示用户刷新页面呢?这不仅能提升用户体验,还能确保用户尽快使用到最新、最稳定的版本。</span></p> <p data-line="5" style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">今天分享几种主流的前端自动检测代码更新的策略及其实现思路。</span></p> <h3 data-line="7" style="box-sizing: border-box;margin-top: 1.2em;margin-bottom: 16px;font-weight: 500;line-height: 1.2;color: rgb(0, 0, 0);font-size: 1.331em;font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, sans-serif;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(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">为什么需要自动检测更新?</span></h3> <ol style="box-sizing: border-box;padding-left: 2rem;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: 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;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">及时修复 Bug</span></strong><span leaf="">:新版本通常修复了旧版本的已知问题,让用户尽快更新能减少他们遇到 Bug 的概率。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">推广新功能</span></strong><span leaf="">:用户能第一时间体验到新功能,提升产品价值。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">保持一致性</span></strong><span leaf="">:尤其在前后端分离架构下,前端的旧版本可能与后端新 API 不兼容,及时更新能避免潜在错误。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">避免用户困惑</span></strong><span leaf="">:如果用户通过其他渠道得知有新版,却发现自己仍在旧版,可能会感到困惑。</span></span></li> </ol> <h3 data-line="14" style="box-sizing: border-box;margin-top: 1.2em;margin-bottom: 16px;font-weight: 500;line-height: 1.2;color: rgb(0, 0, 0);font-size: 1.331em;font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, sans-serif;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(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">主流检测策略</span></h3> <h4 data-line="16" style="box-sizing: border-box;margin-top: 1.2em;margin-bottom: 16px;font-weight: 600;line-height: 1.2;color: rgb(0, 0, 0);font-size: 1.21em;font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, sans-serif;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(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">1. 轮询特定文件/API (Polling)</span></h4> <p data-line="18" style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">这是最简单直观的方法。</span></p> <ul style="box-sizing: border-box;padding-left: 2rem;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: 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;"><span style="box-sizing: border-box;"><p style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">原理</span></strong><span leaf="">:</span></p></span></li> <ol style="box-sizing: border-box;padding-left: 2rem;margin-top: 0px;margin-bottom: 0px;" class="list-paddingleft-1"> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><span leaf="">在项目构建/部署时,生成一个包含版本信息的文件(如 </span><code style="box-sizing: border-box;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;font-size: 13.6px;color: rgb(214, 51, 132);overflow-wrap: break-word;padding: 0.2em 0.4em;margin: 0px;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;><span leaf="">version.json</span></code><span leaf=""> 或 </span><code style="box-sizing: border-box;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;font-size: 13.6px;color: rgb(214, 51, 132);overflow-wrap: break-word;padding: 0.2em 0.4em;margin: 0px;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;><span leaf="">manifest.json</span></code><span leaf="">),内容可以是版本号、构建时间戳或 Git commit hash。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><span leaf="">前端应用启动后,定期(如每隔5分钟、30分钟)通过 </span><code style="box-sizing: border-box;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;font-size: 13.6px;color: rgb(214, 51, 132);overflow-wrap: break-word;padding: 0.2em 0.4em;margin: 0px;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;><span leaf="">fetch</span></code><span leaf=""> 请求这个版本文件。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><span leaf="">比较获取到的版本信息与当前页面加载时的版本信息(通常可以在首次加载时获取并存储在内存或 </span><code style="box-sizing: border-box;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;font-size: 13.6px;color: rgb(214, 51, 132);overflow-wrap: break-word;padding: 0.2em 0.4em;margin: 0px;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;><span leaf="">localStorage</span></code><span leaf=""> 中)。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><span leaf="">如果版本信息不一致,则表明有新版本,可以提示用户更新。</span></span></li> </ol> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><p style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">实现简例</span></strong><span leaf="">:</span></p><span leaf=""><img src="/upload/bd098ece6a8b0c53181b308174ae2f52.png" class="rich_pages wxw-img" data-ratio="0.9287037037037037" data-type="png" data-w="1080" style="box-sizing: border-box;vertical-align: middle;max-width: 100%;" data-imgfileid="504023053"></span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><p style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">优点</span></strong><span leaf="">:实现简单,对服务器端要求低。</span></p></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><p style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">缺点</span></strong><span leaf="">:</span></p></span></li> <ul style="box-sizing: border-box;padding-left: 2rem;margin-top: 0px;margin-bottom: 0px;" class="list-paddingleft-1"> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><span leaf="">有延迟,用户不会立即知道更新。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><span leaf="">轮询会产生额外的网络请求,尽管 </span><code style="box-sizing: border-box;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;font-size: 13.6px;color: rgb(214, 51, 132);overflow-wrap: break-word;padding: 0.2em 0.4em;margin: 0px;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;><span leaf="">version.json</span></code><span leaf=""> 文件通常很小。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><span leaf="">需要处理好缓存问题,确保每次都能拿到最新的 </span><code style="box-sizing: border-box;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;font-size: 13.6px;color: rgb(214, 51, 132);overflow-wrap: break-word;padding: 0.2em 0.4em;margin: 0px;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;><span leaf="">version.json</span></code><span leaf="">。</span></span></li> </ul> </ul> <h4 data-line="79" style="box-sizing: border-box;margin-top: 1.2em;margin-bottom: 16px;font-weight: 600;line-height: 1.2;color: rgb(0, 0, 0);font-size: 1.21em;font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, sans-serif;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(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">2. 服务器推送 (Server-Sent Events / WebSockets)</span></h4> <p data-line="81" style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">如果希望实现更实时的通知,可以使用服务器推送技术。</span></p> <ul style="box-sizing: border-box;padding-left: 2rem;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: 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;"><span style="box-sizing: border-box;"><p style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">Server-Sent Events (SSE)</span></strong><span leaf="">:</span></p></span></li> <ul style="box-sizing: border-box;padding-left: 2rem;margin-top: 0px;margin-bottom: 0px;" class="list-paddingleft-1"> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">原理</span></strong><span leaf="">:客户端与服务器建立一个单向的持久连接,服务器可以在任何时候向客户端推送消息。当有新版本部署时,服务器可以主动推送一个“更新”事件给所有连接的客户端。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">优点</span></strong><span leaf="">:比 WebSockets 轻量,API 简单,适合这种单向通知场景。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">缺点</span></strong><span leaf="">:单向通信;需要服务器端支持。</span></span></li> </ul> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><p style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">WebSockets</span></strong><span leaf="">:</span></p></span></li> <ul style="box-sizing: border-box;padding-left: 2rem;margin-top: 0px;margin-bottom: 0px;" class="list-paddingleft-1"> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">原理</span></strong><span leaf="">:客户端与服务器建立一个双向的持久连接。同样,服务器可以在部署新版后通过 WebSocket 连接通知客户端。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">优点</span></strong><span leaf="">:双向通信,功能强大。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">缺点</span></strong><span leaf="">:比 SSE 重,实现和维护成本更高;对于仅更新通知的场景可能有点“大材小用”。</span></span></li> </ul> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><p style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">实现简例 (SSE)</span></strong><span leaf="">:</span></p><span leaf=""><img src="/upload/12d89b0cee528874872b070c8193a65b.png" class="rich_pages wxw-img" data-ratio="0.55" data-type="png" data-w="1080" style="box-sizing: border-box;vertical-align: middle;max-width: 100%;" data-imgfileid="504023052"></span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><p style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">优点</span></strong><span leaf="">:实时性高。</span></p></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><p style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">缺点</span></strong><span leaf="">:对服务器端有额外要求,需要维护长连接,可能增加服务器压力。</span></p></span></li> </ul> <h3 data-line="120" style="box-sizing: border-box;margin-top: 1.2em;margin-bottom: 16px;font-weight: 500;line-height: 1.2;color: rgb(0, 0, 0);font-size: 1.331em;font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, sans-serif;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(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">用户体验考量</span></h3> <p data-line="122" style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">无论选择哪种技术,用户体验都是关键:</span></p> <ol style="box-sizing: border-box;padding-left: 2rem;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: 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;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">非侵入式提示</span></strong><span leaf="">:避免使用 </span><code style="box-sizing: border-box;font-family: SFMono-Regular, Consolas, " liberation mono, menlo, courier, monospace;font-size: 13.6px;color: rgb(214, 51, 132);overflow-wrap: break-word;padding: 0.2em 0.4em;margin: 0px;background-color: rgba(27, 31, 35, 0.05);border-radius: 3px;><span leaf="">alert()</span></code><span leaf=""> 这种阻塞式对话框。优先考虑 Toast、Snackbar、应用内小红点或不显眼的横幅通知。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">给予用户选择</span></strong><span leaf="">:通常应允许用户选择“立即更新”或“稍后再说”。对于关键更新(如安全补丁),可以采取更强制的策略。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">清晰的说明</span></strong><span leaf="">:告知用户更新的好处(如“新功能上线!”或“修复了已知问题”)。</span></span></li> <li style="box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">避免频繁打扰</span></strong><span leaf="">:如果用户选择“稍后”,不要在短时间内重复提示。轮询机制也应设置合理的间隔。</span></span></li> </ol> <p data-line="129" style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">对于大多数现代 Web 应用,结合构建工具(如 Webpack、Vite)自动生成版本信息,并使用 </span><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">SSE</span></strong><span leaf=""> 或 </span><strong style="box-sizing: border-box;font-weight: bolder;"><span leaf="">轮询版本文件</span></strong><span leaf=""> 的策略是比较常见和推荐的做法。</span></p> <p data-line="131" style="box-sizing: border-box;margin-top: 0px;margin-bottom: 1rem;color: rgb(51, 51, 51);font-family: " helvetica neue, helvetica, segoe ui, arial, freesans, 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: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;><span leaf="">自动检测前端代码更新并友好提示用户,是提升现代 Web 应用质量和用户体验的重要一环。开发者应根据项目需求、团队技术栈和对用户体验的追求,选择最合适的策略。记住,目标是让用户在不知不觉中或在愉快的引导下,用上最新、最好的应用版本。</span></p> <section class="mp_profile_iframe_wrp" nodeleaf=""> <mp-common-profile class="js_uneditable custom_select_card mp_profile_iframe" data-pluginname="mpprofile" data-nickname="JavaScript" data-alias="FedJavaScript" data-from="0" data-headimg="http://mmbiz.qpic.cn/mmbiz_png/btsCOHx9LAO55RFZ2rpHxp8JCdibf2zroiae9jOtwgicS0DIZM6II8CkDDY1icAQ2QakuFr6pkRJgIIdyicDM4FRic2w/0?wx_fmt=png" data-signature="为 JavaScript 爱好人员提供:Web 前端相关技术教程、JavaScript、Node.js、Deno、Vue.js、React、Angular、HTML5、CSS3 等一系列教程和经验分享" data-id="MzAwNjI5MTYyMw==" data-is_biz_ban="0" data-service_type="1" data-verify_status="0"></mp-common-profile> </section> <p style="display: none;"> <mp-style-type data-value="3"></mp-style-type></p>
作者:微信小助手
<section data-tool="markdown编辑器" data-website="https://markdown.com.cn/editor" style="font-size: 16px;padding: 25px 30px;word-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;margin-top: -10px;line-height: 1.75;color: rgb(89, 89, 89);font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%);background-size: 20px 20px;background-position: center center;" data-pm-slice="0 0 []"> <p data-tool="markdown.com.cn编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><span leaf="">在前端开发中,实现图片防盗链通常涉及到与后端服务器的交互,因为防盗链机制主要是在服务器端实现的。然而,前端也可以采取一些措施来增强图片保护,并与服务器端的防盗链策略配合使用。以下是前端可以采用的一些方法:</span></p> <p data-tool="markdown.com.cn编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><span leaf=""><img src="/upload/933632b44a3a795c64308e8f197212ed.png" alt="image.png" class="rich_pages wxw-img" data-ratio="1.0215924426450742" data-type="other" data-w="741" data-imgfileid="100060053"></span></p> <h3 data-tool="markdown.com.cn编辑器" style="margin-top: 30px;margin-bottom: 15px;color: black;font-size: 16px;font-weight: bold;"><span style="display: none;"></span><span style="border-bottom: 2px solid rgb(222, 198, 251);color: rgb(89, 89, 89);"><span leaf="">一、使用 Token 保护图片资源</span></span><span style="display: none;"></span></h3> <ol style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;list-style-type: decimal;font-size: 15px;color: rgb(89, 89, 89);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「动态生成 Token」</span></strong></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><span leaf="">在用户请求图片时,可以在前端生成一个包含时间戳的 token,然后将其附加到图片 URL 中。这个 token 可以在服务器端验证。</span></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「前端代码示例(使用 JavaScript):」</span></strong></p> <pre style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;background: rgba(27, 31, 35, 0.05);display: -webkit-box;font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span style="color: rgb(0, 116, 0);line-height: 26px;"><span leaf="">// 生成当前时间戳作为 token</span></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">function</span></span><span leaf=""> </span><span style="color: rgb(28, 0, 207);line-height: 26px;"><span leaf="">generateToken</span></span><span leaf="">(</span><span style="color: rgb(92, 38, 153);line-height: 26px;"></span><span leaf="">) </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">return</span></span><span leaf=""> </span><span style="color: rgb(92, 38, 153);line-height: 26px;"><span leaf="">Date</span></span><span leaf="">.now();</span><span leaf=""><br></span><span leaf="">}</span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(0, 116, 0);line-height: 26px;"><span leaf="">// 获取图片 URL</span></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">function</span></span><span leaf=""> </span><span style="color: rgb(28, 0, 207);line-height: 26px;"><span leaf="">getImageUrl</span></span><span leaf="">(</span><span style="color: rgb(92, 38, 153);line-height: 26px;"></span><span leaf="">) </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">const</span></span><span leaf=""> token = generateToken();</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">return</span></span><span leaf=""> </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">`https://example.com/images/photo.jpg?token=</span><span style="color: rgb(0, 0, 0);line-height: 26px;"><span leaf="">${token}</span></span><span leaf="">`</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf="">}</span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(0, 116, 0);line-height: 26px;"><span leaf="">// 设置图片 src</span></span><span leaf=""><br></span><span style="color: rgb(92, 38, 153);line-height: 26px;"><span leaf="">document</span></span><span leaf="">.getElementById(</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'image'</span></span><span leaf="">).src = getImageUrl();</span><span leaf=""><br></span></code></pre> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「解释:」</span></strong></p> </section></li> <ul style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;color: rgb(89, 89, 89);list-style-type: circle;" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;background-color: rgba(27, 31, 35, 0.05);font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span leaf="">generateToken()</span></code><span leaf=""> 函数生成一个时间戳作为 token。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;background-color: rgba(27, 31, 35, 0.05);font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span leaf="">getImageUrl()</span></code><span leaf=""> 函数将 token 附加到图片 URL 中,以便进行验证。</span> </section></li> </ul> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「在图片请求中使用 Token」</span></strong></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><span leaf="">在图片加载时,确保 URL 中包含有效的 token。前端可以在页面加载时动态设置图片 URL。</span></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「前端代码示例(使用 Vue.js):」</span></strong></p> <pre style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;background: rgba(27, 31, 35, 0.05);display: -webkit-box;font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><</span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">template</span></span><span leaf="">></span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><</span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">img</span></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">:src</span></span><span leaf="">=</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">"imageUrl"</span></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">alt</span></span><span leaf="">=</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">"Protected Image"</span></span><span leaf=""> /></span></span><span leaf=""><br></span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><!--/</span--><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">template</span></span><span leaf="">></span></span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><</span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">script</span></span><span leaf="">></span></span><span style="line-height: 26px;"><span leaf=""><br></span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">export</span></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">default</span></span><span leaf=""> {</span><span leaf=""><br></span><span leaf=""> data() {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">return</span></span><span leaf=""> {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">imageUrl</span></span><span leaf="">: </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">''</span></span><span leaf=""><br></span><span leaf=""> };</span><span leaf=""><br></span><span leaf=""> },</span><span leaf=""><br></span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">methods</span></span><span leaf="">: {</span><span leaf=""><br></span><span leaf=""> generateToken() {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">return</span></span><span style="color: rgb(92, 38, 153);line-height: 26px;"><span leaf="">Date</span></span><span leaf="">.now(); </span><span style="color: rgb(0, 116, 0);line-height: 26px;"><span leaf="">// 或使用其他方法生成 token</span></span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""> },</span><span leaf=""><br></span><span leaf=""> created() {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">const</span></span><span leaf=""> token = </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">this</span></span><span leaf="">.generateToken();</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">this</span></span><span leaf="">.imageUrl = </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">`https://example.com/images/photo.jpg?token=</span><span style="color: rgb(0, 0, 0);line-height: 26px;"><span leaf="">${token}</span></span><span leaf="">`</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf="">};</span><span leaf=""><br></span></span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><!--/</span--><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">script</span></span><span leaf="">></span></span><span leaf=""><br></span></span></span></code></pre> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「解释:」</span></strong></p> </section></li> <ul style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;color: rgb(89, 89, 89);list-style-type: circle;" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <span leaf="">使用 Vue 的生命周期钩子 </span><code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;background-color: rgba(27, 31, 35, 0.05);font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span leaf="">created</span></code><span leaf=""> 来生成 token 并设置图片 URL。</span> </section></li> </ul> </ol> <h3 data-tool="markdown.com.cn编辑器" style="margin-top: 30px;margin-bottom: 15px;color: black;font-size: 16px;font-weight: bold;"><span style="display: none;"></span><span style="border-bottom: 2px solid rgb(222, 198, 251);color: rgb(89, 89, 89);"><span leaf="">二、设置图片加载控制</span></span><span style="display: none;"></span></h3> <ol style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;list-style-type: decimal;font-size: 15px;color: rgb(89, 89, 89);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「防止右键下载」</span></strong></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><span leaf="">在前端,你可以通过 CSS 或 JavaScript 来禁用图片的右键菜单,从而防止用户通过右键菜单下载图片。</span></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「前端代码示例(使用 CSS):」</span></strong></p> <pre style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;background: rgba(27, 31, 35, 0.05);display: -webkit-box;font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><</span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">style</span></span><span leaf="">></span></span><span style="line-height: 26px;"><span leaf=""><br></span><span style="color: rgb(155, 112, 63);line-height: 26px;"><span leaf="">.no-right-click</span></span><span leaf=""> {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">pointer-events</span></span><span leaf="">: none;</span><span leaf=""><br></span><span leaf="">}</span><span leaf=""><br></span></span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><!--/</span--><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">style</span></span><span leaf="">></span></span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><</span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">img</span></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">class</span></span><span leaf="">=</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">"no-right-click"</span></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">src</span></span><span leaf="">=</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">"https://example.com/images/photo.jpg"</span></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">alt</span></span><span leaf="">=</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">"Protected Image"</span></span><span leaf=""> /></span></span><span leaf=""><br></span></span></code></pre> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「前端代码示例(使用 JavaScript):」</span></strong></p> <pre style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;background: rgba(27, 31, 35, 0.05);display: -webkit-box;font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span style="color: rgb(92, 38, 153);line-height: 26px;"><span leaf="">document</span></span><span leaf="">.addEventListener(</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'contextmenu'</span></span><span leaf="">, </span><span style="line-height: 26px;"><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">function</span></span><span leaf=""> (</span><span style="color: rgb(92, 38, 153);line-height: 26px;"><span leaf="">e</span></span><span leaf="">) </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">if</span></span><span leaf=""> (e.target.tagName === </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'IMG'</span></span><span leaf="">) {</span><span leaf=""><br></span><span leaf=""> e.preventDefault();</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf="">});</span><span leaf=""><br></span></code></pre> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「解释:」</span></strong></p> </section></li> <ul style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;color: rgb(89, 89, 89);list-style-type: circle;" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <span leaf="">使用 CSS 属性 </span><code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;background-color: rgba(27, 31, 35, 0.05);font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span leaf="">pointer-events: none</span></code><span leaf=""> 来禁用右键菜单。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <span leaf="">使用 JavaScript 事件监听器来阻止右键菜单弹出。</span> </section></li> </ul> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「使用水印」</span></strong></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><span leaf="">在图片上添加水印是另一种保护图片的方式。前端可以通过 Canvas 绘制水印,但通常这在图片生成或处理阶段进行更为合适。</span></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「前端代码示例(使用 Canvas):」</span></strong></p> <pre style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;background: rgba(27, 31, 35, 0.05);display: -webkit-box;font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><</span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">canvas</span></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">id</span></span><span leaf="">=</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">"myCanvas"</span></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">width</span></span><span leaf="">=</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">"600"</span></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">height</span></span><span leaf="">=</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">"400"</span></span><span leaf="">></span></span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><!--/</span--><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">canvas</span></span><span leaf="">></span></span><span leaf=""><br></span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><</span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">script</span></span><span leaf="">></span></span><span style="line-height: 26px;"><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">const</span></span><span leaf=""> canvas = </span><span style="color: rgb(92, 38, 153);line-height: 26px;"><span leaf="">document</span></span><span leaf="">.getElementById(</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'myCanvas'</span></span><span leaf="">);</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">const</span></span><span leaf=""> ctx = canvas.getContext(</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'2d'</span></span><span leaf="">);</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">const</span></span><span leaf=""> img = </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">new</span></span><span leaf=""> Image();</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> img.src = </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'https://example.com/images/photo.jpg'</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf=""> img.onload = </span><span style="line-height: 26px;"><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">function</span></span><span leaf="">(</span><span style="color: rgb(92, 38, 153);line-height: 26px;"></span><span leaf="">) </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> ctx.drawImage(img, </span><span style="color: rgb(28, 0, 207);line-height: 26px;"><span leaf="">0</span></span><span leaf="">, </span><span style="color: rgb(28, 0, 207);line-height: 26px;"><span leaf="">0</span></span><span leaf="">);</span><span leaf=""><br></span><span leaf=""> ctx.font = </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'30px Arial'</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf=""> ctx.fillStyle = </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'red'</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf=""> ctx.fillText(</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'Watermark'</span></span><span leaf="">, </span><span style="color: rgb(28, 0, 207);line-height: 26px;"><span leaf="">10</span></span><span leaf="">, </span><span style="color: rgb(28, 0, 207);line-height: 26px;"><span leaf="">50</span></span><span leaf="">);</span><span leaf=""><br></span><span leaf=""> };</span><span leaf=""><br></span></span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf=""><!--/</span--><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">script</span></span><span leaf="">></span></span><span leaf=""><br></span></span></span></code></pre> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「解释:」</span></strong></p> </section></li> <ul style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;color: rgb(89, 89, 89);list-style-type: circle;" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <span leaf="">使用 Canvas 绘制图片并添加水印文本。</span> </section></li> </ul> </ol> <h3 data-tool="markdown.com.cn编辑器" style="margin-top: 30px;margin-bottom: 15px;color: black;font-size: 16px;font-weight: bold;"><span style="display: none;"></span><span style="border-bottom: 2px solid rgb(222, 198, 251);color: rgb(89, 89, 89);"><span leaf="">三、与服务器端防盗链机制配合</span></span><span style="display: none;"></span></h3> <ol style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;list-style-type: decimal;font-size: 15px;color: rgb(89, 89, 89);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「验证 Referer」</span></strong></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><span leaf="">在前端代码中,可以通过设置 </span><code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;background-color: rgba(27, 31, 35, 0.05);font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span leaf="">Referer</span></code><span leaf=""> 头(这通常由浏览器自动处理)来帮助服务器验证请求来源。</span></p> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「前端代码示例(使用 Fetch API):」</span></strong></p> <pre style="margin-top: 10px;margin-bottom: 10px;"><code style="overflow-x: auto;background: rgba(27, 31, 35, 0.05);display: -webkit-box;font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span leaf="">fetch(</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'https://example.com/images/photo.jpg'</span></span><span leaf="">, {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">method</span></span><span leaf="">: </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'GET'</span></span><span leaf="">,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(131, 108, 40);line-height: 26px;"><span leaf="">headers</span></span><span leaf="">: {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'Referer'</span></span><span leaf="">: </span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'https://yourwebsite.com'</span></span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf="">}).then(</span><span style="line-height: 26px;"><span style="color: rgb(92, 38, 153);line-height: 26px;"><span leaf="">response</span></span><span leaf=""> =></span></span><span leaf=""> response.blob())</span><span leaf=""><br></span><span leaf=""> .then(</span><span style="line-height: 26px;"><span style="color: rgb(92, 38, 153);line-height: 26px;"><span leaf="">blob</span></span><span leaf=""> =></span></span><span leaf=""> {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(170, 13, 145);line-height: 26px;"><span leaf="">const</span></span><span leaf=""> url = URL.createObjectURL(blob);</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(92, 38, 153);line-height: 26px;"><span leaf="">document</span></span><span leaf="">.getElementById(</span><span style="color: rgb(196, 26, 22);line-height: 26px;"><span leaf="">'image'</span></span><span leaf="">).src = url;</span><span leaf=""><br></span><span leaf=""> });</span><span leaf=""><br></span></code></pre> <p style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><strong style="color: rgb(89, 89, 89);font-weight: bold;"><span leaf="">「解释:」</span></strong></p> </section></li> <ul style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;color: rgb(89, 89, 89);list-style-type: circle;" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;line-height: 26px;font-size: 14px;font-weight: normal;color: rgb(89, 89, 89);"> <span leaf="">使用 </span><code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;background-color: rgba(27, 31, 35, 0.05);font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span leaf="">fetch</span></code><span leaf=""> 请求图片,手动设置 </span><code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0px 2px;background-color: rgba(27, 31, 35, 0.05);font-family: " operator mono, consolas, monaco, menlo, monospace;word-break: break-all;color: rgb(89, 89, 89);><span leaf="">Referer</span></code><span leaf=""> 头部(尽管大多数浏览器自动设置)。</span> </section></li> </ul> </ol> <h3 data-tool="markdown.com.cn编辑器" style="margin-top: 30px;margin-bottom: 15px;color: black;font-size: 16px;font-weight: bold;"><span style="display: none;"></span><span style="border-bottom: 2px solid rgb(222, 198, 251);color: rgb(89, 89, 89);"><span leaf="">总结</span></span><span style="display: none;"></span></h3> <p data-tool="markdown.com.cn编辑器" style="padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(89, 89, 89);margin: 10px 0px;letter-spacing: 2px;font-size: 14px;word-spacing: 2px;"><span leaf="">前端在实现图片防盗链方面,主要通过动态生成 Token、设置图片加载控制(如禁用右键菜单和添加水印)以及与服务器端防盗链机制配合来保护图片资源。虽然真正的防盗链逻辑通常是在服务器端实现,但前端可以采取这些措施来增强保护效果。结合前端和后端的策略,可以有效地防止未经授权的图片访问和盗用。</span></p> </section>