作者:微信小助手
<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style=""> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">自从发了 <a style="" href="https://mp.weixin.qq.com/s?__biz=MjM5NzQxMTAyNw==&mid=2247485510&idx=1&sn=22eef6a6bddd360cb851e06566178ec5&scene=21#wechat_redirect" textvalue="DeepSeek+dify 本地知识库:真的太香了" data-itemshowtype="0" target="_blank" linktype="text" data-linktype="2">DeepSeek+dify 本地知识库:真的太香了</a>这篇以后,一直有小伙伴介绍在问我,怎么让在个ai应用客户端直接连接数据库查询。dify官方没有现成的组件可以直接用。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">当时我想的是两种方式,一种是基于代码执行模块直接查询数据库,一种是基于Http请求,调用自己封装接口来查询数据库。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">历史文章</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><a style="" href="https://mp.weixin.qq.com/s?__biz=MjM5NzQxMTAyNw==&mid=2247485510&idx=1&sn=22eef6a6bddd360cb851e06566178ec5&scene=21#wechat_redirect" textvalue="DeepSeek+dify 本地知识库:真的太香了" data-itemshowtype="0" target="_blank" linktype="text" data-linktype="2">DeepSeek+dify 本地知识库:真的太香了</a></span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><a style="" href="https://mp.weixin.qq.com/s?__biz=MjM5NzQxMTAyNw==&mid=2247485614&idx=1&sn=6edd8860da578d145bc05f158678dbe5&scene=21#wechat_redirect" textvalue="Deepseek+Dify本地知识库相关问题汇总" data-itemshowtype="0" target="_blank" linktype="text" data-linktype="2">Deepseek+Dify本地知识库相关问题汇总</a></span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><a style="" href="https://mp.weixin.qq.com/s?__biz=MjM5NzQxMTAyNw==&mid=2247485677&idx=1&sn=8977dea15592f5cd67565298b403b5ea&scene=21#wechat_redirect" textvalue="DeepSeek+dify 本地知识库:高级应用Agent+工作流" data-itemshowtype="0" target="_blank" linktype="text" data-linktype="2">DeepSeek+dify 本地知识库:高级应用Agent+工作流</a></span></p> <h2 data-tool="mdnice编辑器" style="border-bottom-color: rgb(239, 112, 96);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: unset;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: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-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;height: auto;justify-content: unset;line-height: 1.1em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"><span leaf=""><br></span></span><span style="font-size: 22px;color: rgb(255, 255, 255);background-color: rgb(239, 112, 96);line-height: 1.5em;letter-spacing: 0em;align-items: unset;background-attachment: scroll;background-clip: border-box;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: 3px;border-top-right-radius: 3px;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: 0px;margin-right: 5px;overflow-x: unset;overflow-y: unset;padding-top: 3px;padding-bottom: 1px;padding-left: 10px;padding-right: 10px;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 leaf=""><br></span></span><span style="border-bottom-color: rgb(239, 235, 233);align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-left-style: none;border-right-style: solid;border-top-width: 1px;border-bottom-width: 36px;border-left-width: 1px;border-right-width: 20px;border-top-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: transparent;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: 16px;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;letter-spacing: 0px;line-height: 1.1em;margin-top: 0px;margin-bottom: 0px;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;width: auto;-webkit-box-reflect: unset;"><span leaf=""> </span></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">想干这事之前先梳理下流程<img src="/upload/f14f8af3ff704439675af0cc83662f62.png" class="rich_pages wxw-img" data-ratio="0.2797297297297297" data-type="png" data-w="740" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;" data-imgfileid="100002046"></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(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">用户输入问题,根据用户的问题提出关键词</span> </section></li> <li> <section style="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="">通过http调用外部服务接口,根据关键词查询数据库</span> </section></li> <li> <section style="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="">返回200,调用大模型,将用户问题和知识进行梳理</span> </section></li> <li> <section style="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> <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;display: block;"><span style="display: none;"><span leaf=""><br></span></span><span style="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><span style="display: none;"><span leaf=""><br></span></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><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(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">有一个python环境</span> </section></li> <li> <section style="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="">安装pymysq和flask 组件</span><code style=""><span leaf="">python -m pip install pymysql flask </span></code> </section></li> <li> <section style="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="">有一个mysql,或其他的数据库,我有mysql直接用了</span> </section></li> </ul> <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;display: block;"><span style="display: none;"><span leaf=""><br></span></span><span style="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><span style="display: none;"><span leaf=""><br></span></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">让kimi给我生成一个文章表,并且插入10条数据,我们可以告诉kimi,文章长度多大,这样内容可以丰富些。<img src="/upload/1485b0ce44349293e53242f36e6ce6f0.png" class="rich_pages wxw-img" data-ratio="0.99836867862969" data-type="png" data-w="613" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;" data-imgfileid="100002045">直接让kimi生成一个暴露接口查数据库的服务,有简单的优化了下,将下面的内容放入到</span><code style=""><span leaf="">server.py</span></code><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 k0ue4mipavick8hqialiakg2tb1ebnwq3bs1gdsusaaoialugirysdnk19v5ftbvraq0mgzeeyoukk6rprqxtrmqfohj0o9toqm8 640?wx_fmt="svg&from=appmsg");""><span leaf=""><br></span></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: #c678dd;line-height: 26px;"><span leaf="">from</span></span><span leaf=""> flask </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">import</span></span><span leaf=""> Flask, request, jsonify</span><span leaf=""><br></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">import</span></span><span leaf=""> pymysql</span><span leaf=""><br></span><span leaf=""><br></span><span leaf="">app = Flask(__name__)</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 leaf="">DATABASE_CONFIG = {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'host'</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">''</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=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'user'</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">''</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=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'password'</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">''</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=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'db'</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'demo'</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=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'charset'</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'utf8mb4'</span></span><span leaf="">,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'cursorclass'</span></span><span leaf="">: pymysql.cursors.DictCursor</span><span leaf=""><br></span><span leaf="">}</span><span leaf=""><br></span><span leaf=""><br></span><span style="color: #61aeee;line-height: 26px;"><span leaf="">@app.route('/query', methods=['POST'])</span></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">query_database</span></span><span style="line-height: 26px;"><span leaf="">()</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><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=""># 获取关键字</span></span><span leaf=""><br></span><span leaf=""> keyword = request.json.get(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'keyword'</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"keyword为:"</span></span><span leaf="">+keyword)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">not</span></span><span leaf=""> keyword:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> jsonify({</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"error"</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Keyword is required"</span></span><span leaf="">}), </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">400</span></span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 参数化查询,避免 SQL 注入,修改成自己的库</span></span><span leaf=""><br></span><span leaf=""> query = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"SELECT * FROM articles WHERE content LIKE %s"</span></span><span leaf=""><br></span><span leaf=""> params = (</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'%'</span></span><span leaf=""> + keyword + </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'%'</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="">try</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 建立数据库连接</span></span><span leaf=""><br></span><span leaf=""> connection = pymysql.connect(**DATABASE_CONFIG)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">with</span></span><span leaf=""> connection.cursor() </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">as</span></span><span leaf=""> cursor:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 执行查询</span></span><span leaf=""><br></span><span leaf=""> cursor.execute(query, params)</span><span leaf=""><br></span><span leaf=""> result = cursor.fetchall()</span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> connection.commit()</span><span leaf=""><br></span><span leaf=""> connection.close()</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">not</span></span><span leaf=""> result:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">"未查询到有效数据"</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">400</span></span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 生成 Markdown 表格</span></span><span leaf=""><br></span><span leaf=""> markdown_table = generate_markdown_table(result)</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=""> markdown_table, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">200</span></span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">except</span></span><span leaf=""> Exception </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">as</span></span><span leaf=""> e:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> str(e), </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">500</span></span><span leaf=""><br></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">generate_markdown_table</span></span><span style="line-height: 26px;"><span leaf="">(results)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">""" 生成 Markdown 表格 """</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">not</span></span><span leaf=""> results:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">""</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 获取列名</span></span><span leaf=""><br></span><span leaf=""> columns = results[</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">].keys()</span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 表头</span></span><span leaf=""><br></span><span leaf=""> table_md = </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="">.join([col </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> col </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> columns]) + </span><span style="color: #98c379;line-height: 26px;"><span leaf="">" |\n"</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 分隔线</span></span><span leaf=""><br></span><span leaf=""> table_md += </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=""> * len(columns) + </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"\n"</span></span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> </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="">for</span></span><span leaf=""> row </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> results:</span><span leaf=""><br></span><span leaf=""> table_md += </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="">.join([str(cell) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> cell </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> row.values()]) + </span><span style="color: #98c379;line-height: 26px;"><span leaf="">" |\n"</span></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=""> table_md</span><span leaf=""><br></span><span leaf=""><br></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> __name__ == </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'__main__'</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 注意这里绑定本机的内容ip,省事点,就0.0.0.0即可。不要绑定127.0.0.1,docke内访问不到</span></span><span leaf=""><br></span><span leaf=""> app.run(host=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'10.1.0.65'</span></span><span leaf="">, port=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">8000</span></span><span leaf="">)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;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 k0ue4mipavick8hqialiakg2tb1ebnwq3bs1gdsusaaoialugirysdnk19v5ftbvraq0mgzeeyoukk6rprqxtrmqfohj0o9toqm8 640?wx_fmt="svg&from=appmsg");""><span leaf=""><br></span></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=""> python .\server.py</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;display: block;"><span style="display: none;"><span leaf=""><br></span></span><span style="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><span style="display: none;"><span leaf=""><br></span></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img src="/upload/923b700177ae8b0752d84e89617bf7bf.png" class="rich_pages wxw-img" data-ratio="0.9504950495049505" data-type="png" data-w="707" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;" data-imgfileid="100002048">创建一个空白应用。<img src="/upload/fd9b4b79247c5fbc6bc44d60bb43e4dc.png" class="rich_pages wxw-img" data-ratio="0.5529891304347826" data-type="png" data-w="736" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;" data-imgfileid="100002047">在开始节点添加一个输入字段</span><code style=""><span leaf="">context</span></code></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/3be38746c11a7a648e28e0890f437996.png" class="rich_pages wxw-img" data-ratio="0.5629139072847682" data-type="png" data-w="906" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100002044"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">添加一个LLM,把开始节点设置的</span><code style=""><span leaf="">context</span></code><span leaf="">字段作为上下文传入,并设置提示词提取关键词。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img src="/upload/51768755dc6a49f2048a3c143df0b4bb.png" class="rich_pages wxw-img" data-ratio="1.0582386363636365" data-type="png" data-w="704" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;" data-imgfileid="100002053">添加一个http请求节点,把我们在接口开发里的地址和接口名填写进去</span><code style=""><span leaf="">2</span></code><span leaf="">,然后把大模型的输出作为关键词填写到请求body里</span><code style=""><span leaf="">3</span></code><span leaf="">,我们关闭重试机制</span><code style=""><span leaf="">4</span></code><span leaf="">。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这里要注意下:json的引号是中文的,最好在外面写好校验过了再放进去。<img class="rich_pages wxw-img" data-imgfileid="100002050" data-ratio="1.3667481662591687" src="/upload/7f537acb1dda6cca9df886aa8929d5ca.png" data-type="png" data-w="409" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;">在HTTP请求的输出变量里,我们只关注status_code 响应状态码和响应内容即可。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100002051" data-ratio="0.8265582655826558" src="/upload/0ff7e2629fe8319a89b011d1ce8eab66.png" data-type="png" data-w="738" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;">添加一个条件分支</span><code style=""><span leaf="">1</span></code><span leaf="">,然后设置HTTP响应码为200的时候,连接到大模型。其他直接结束。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100002052" data-ratio="0.6038216560509554" src="/upload/80d9eece29233dbd693e6b9b7610de2e.png" data-type="png" data-w="785" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;">添加大模型,将HTTP请求的响应体作为上下文给大模型,输入提示词,让大模型根据知识,验证,并进行合理性的验证,最后结构化返回。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img src="/upload/d17d7dccece7ede85381421e060c891e.png" class="rich_pages wxw-img" data-ratio="0.5221674876847291" data-type="png" data-w="406" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;" data-imgfileid="100002049">在结束节点中,我们把大模型整理的内容输出。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100002056" data-ratio="1.1198830409356726" src="/upload/a5dc66ecf29422ecd0f0343e405adbe3.png" data-type="png" data-w="684" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;">试运行效果。</span></p> <h2 data-tool="mdnice编辑器" style="border-bottom-color: rgb(239, 112, 96);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: unset;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: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-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;height: auto;justify-content: unset;line-height: 1.1em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"><span leaf=""><br></span></span><span style="font-size: 22px;color: rgb(255, 255, 255);background-color: rgb(239, 112, 96);line-height: 1.5em;letter-spacing: 0em;align-items: unset;background-attachment: scroll;background-clip: border-box;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: 3px;border-top-right-radius: 3px;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: 0px;margin-right: 5px;overflow-x: unset;overflow-y: unset;padding-top: 3px;padding-bottom: 1px;padding-left: 10px;padding-right: 10px;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 leaf=""><br></span></span><span style="border-bottom-color: rgb(239, 235, 233);align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-left-style: none;border-right-style: solid;border-top-width: 1px;border-bottom-width: 36px;border-left-width: 1px;border-right-width: 20px;border-top-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: transparent;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: 16px;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;letter-spacing: 0px;line-height: 1.1em;margin-top: 0px;margin-bottom: 0px;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;width: auto;-webkit-box-reflect: unset;"><span leaf=""> </span></span></h2> <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 class="rich_pages wxw-img" data-imgfileid="100002055" data-ratio="0.17966903073286053" src="/upload/3e3b0aa39d3fdb7bd14ab5e02cb9fc5d.png" data-type="png" data-w="846" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">由于difysandbox的安全限制</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(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">不能访问文件系统</span> </section></li> <li> <section style="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> <li> <section style="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="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">官方也有了对应的说明,见文档。 https://github.com/langgenius/dify-sandbox/blob/main/FAQ.mdss</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 class="rich_pages wxw-img" data-imgfileid="100002057" data-ratio="0.4185185185185185" src="/upload/1a50c7c801f257ca0805ba96e007008e.png" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;"></span> </figure> <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(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">官方已经告诉我们沙箱里添加了哪些权限</span> </section></li> <li> <section style="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> <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;display: block;"><span style="display: none;"><span leaf=""><br></span></span><span style="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="">difysandbox源码修改</span></span><span style="display: none;"><span leaf=""><br></span></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><code style=""><span leaf="">一定要使用linux环境</span></code><span leaf="">、</span><code style=""><span leaf="">一定要使用linux环境</span></code><code style=""><span leaf="">一定要使用linux环境</span></code></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">我从github上拉下代码以后,搜索``syscalls_amd64.go</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100002054" data-ratio="1.1728045325779037" src="/upload/daff2892cc7a06c7c513c8d74d09ad65.png" data-type="png" data-w="353" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;">一共有4个文件,</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(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <span leaf="">nodejs的系统调用,有amd和arm平台</span> </section></li> <li> <section style="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="">python的系统,也是有amd和arm平台</span> </section></li> </ul> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">我用python,不是arm架构的,镜像都是linux的。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">我们直接问kimi即可。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100002058" data-ratio="0.9722955145118733" src="/upload/5c3707bbcf520ed422d030fe7119f5fd.png" data-type="png" data-w="758" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;">ps:这个问题丢给了ds和chatgpt都是瞎回答</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img src="/upload/265a37396bf1b9dd73e3ba77eedb923c.png" class="rich_pages wxw-img" data-ratio="0.9399477806788512" data-type="png" data-w="766" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;" data-imgfileid="100002061">一步步的问kimi,最后告诉我要添加哪些。整理以后添加到代码里。</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 k0ue4mipavick8hqialiakg2tb1ebnwq3bs1gdsusaaoialugirysdnk19v5ftbvraq0mgzeeyoukk6rprqxtrmqfohj0o9toqm8 640?wx_fmt="svg&from=appmsg");""><span leaf=""><br></span></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: #c678dd;line-height: 26px;"><span leaf="">var</span></span><span leaf=""> ALLOW_SYSCALLS = []</span><span style="color: #c678dd;line-height: 26px;"><span leaf="">int</span></span><span leaf="">{ </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// file io </span></span><span leaf=""><br></span><span leaf=""> syscall.SYS_NEWFSTATAT, syscall.SYS_IOCTL, syscall.SYS_LSEEK, syscall.SYS_GETDENTS64, </span><span leaf=""><br></span><span leaf=""> syscall.SYS_WRITE, syscall.SYS_CLOSE, syscall.SYS_OPENAT, syscall.SYS_READ, </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// thread </span></span><span leaf=""><br></span><span leaf=""> syscall.SYS_FUTEX, </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// memory </span></span><span leaf=""><br></span><span leaf=""> syscall.SYS_MMAP, syscall.SYS_BRK, syscall.SYS_MPROTECT, syscall.SYS_MUNMAP, syscall.SYS_RT_SIGRETURN, </span><span leaf=""><br></span><span leaf=""> syscall.SYS_MREMAP, </span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// user/group </span></span><span leaf=""><br></span><span leaf=""> syscall.SYS_SETUID, syscall.SYS_SETGID, syscall.SYS_GETUID, </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// process </span></span><span leaf=""><br></span><span leaf=""> syscall.SYS_GETPID, syscall.SYS_GETPPID, syscall.SYS_GETTID, </span><span leaf=""><br></span><span leaf=""> syscall.SYS_EXIT, syscall.SYS_EXIT_GROUP, </span><span leaf=""><br></span><span leaf=""> syscall.SYS_TGKILL, syscall.SYS_RT_SIGACTION, syscall.SYS_IOCTL, </span><span leaf=""><br></span><span leaf=""> syscall.SYS_SCHED_YIELD, </span><span leaf=""><br></span><span leaf=""> syscall.SYS_SET_ROBUST_LIST, syscall.SYS_GET_ROBUST_LIST, SYS_RSEQ, </span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">// time </span></span><span leaf=""><br></span><span leaf=""> syscall.SYS_CLOCK_GETTIME, syscall.SYS_GETTIMEOFDAY, syscall.SYS_NANOSLEEP, </span><span leaf=""><br></span><span leaf=""> syscall.SYS_EPOLL_CREATE1, </span><span leaf=""><br></span><span leaf=""> syscall.SYS_EPOLL_CTL, syscall.SYS_CLOCK_NANOSLEEP, syscall.SYS_PSELECT6, </span><span leaf=""><br></span><span leaf=""> syscall.SYS_TIME, </span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> syscall.SYS_RT_SIGPROCMASK, syscall.SYS_SIGALTSTACK, SYS_GETRANDOM, </span><span leaf=""><br></span><span leaf=""> </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: #d19a66;line-height: 26px;"><span leaf="">5</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">6</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">7</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">21</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">41</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">42</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">44</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">45</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">51</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">54</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">55</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">107</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">137</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">204</span></span><span leaf="">, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">281</span></span><span leaf="">, </span><span leaf=""><br></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;display: block;"><span style="display: none;"><span leaf=""><br></span></span><span style="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="">预装mysql操作包</span></span><span style="display: none;"><span leaf=""><br></span></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">既然我们要操作在沙箱里操作mysql,那我们得在对应的环境中预装下mysql客户端。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf=""><img class="rich_pages wxw-img" data-imgfileid="100002064" data-ratio="0.706766917293233" src="/upload/601dcfc70abb6ade8782657731a4556a.png" data-type="png" data-w="1064" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;">在</span><code style=""><span leaf="">1</span></code><span leaf="">对应的文件中添加</span><code style=""><span leaf="">2</span></code><span leaf="">对应的</span><code style=""><span leaf="">pymysql==1.1.1</span></code><span leaf="">,我直接安装最新版。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在readme中有操作步骤</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 k0ue4mipavick8hqialiakg2tb1ebnwq3bs1gdsusaaoialugirysdnk19v5ftbvraq0mgzeeyoukk6rprqxtrmqfohj0o9toqm8 640?wx_fmt="svg&from=appmsg");""><span leaf=""><br></span></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: #e06c75;line-height: 26px;"><span leaf="">### Steps</span></span><span leaf=""><br></span><span style="color: #61aeee;line-height: 26px;"><span leaf=""><br></span><span leaf="">1. </span></span><span leaf="">Clone the repository using </span><span style="line-height: 26px;"><span leaf="">`git clone https://github.com/langgenius/dify-sandbox`</span></span><span leaf=""> and navigate to the project directory.</span><span leaf=""><br></span><span style="color: #61aeee;line-height: 26px;"><span leaf="">2. </span></span><span leaf="">Run ./install.sh to install the necessary dependencies.</span><span leaf=""><br></span><span style="color: #61aeee;line-height: 26px;"><span leaf="">3. </span></span><span leaf="">Run ./build/build_[amd64|arm64].sh to build the sandbox binary.</span><span leaf=""><br></span><span style="color: #61aeee;line-height: 26px;"><span leaf="">4. </span></span><span leaf="">Run ./main to start the server.</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">编译成功以后,打包镜像。因为我没有环境,直接模拟了下</span><code style=""><span leaf="">创建了一个main和env</span></code><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 class="rich_pages wxw-img" data-imgfileid="100002063" data-ratio="0.25092592592592594" src="/upload/2c6c9fc318eb9835e7b75c0cb353ec6e.png" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;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 k0ue4mipavick8hqialiakg2tb1ebnwq3bs1gdsusaaoialugirysdnk19v5ftbvraq0mgzeeyoukk6rprqxtrmqfohj0o9toqm8 640?wx_fmt="svg&from=appmsg");""><span leaf=""><br></span></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="">docker build -f docker/amd64/dockerfile -t dify-sandbox:local .</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">我在win上打包报了一堆错,都扔给kimi,一步步的解决。最后成功。</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/80a1f735e6cb139395c0b044856d9281.png" class="rich_pages wxw-img" data-ratio="0.1616052060737527" data-type="png" data-w="922" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100002062"></span> </figure> <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;display: block;"><span style="display: none;"><span leaf=""><br></span></span><span style="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><span style="display: none;"><span leaf=""><br></span></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在我们的安装dify的的时候,有个</span><code style=""><span leaf="">dify/docker/ssrf_proxy</span></code><span leaf="">目录,找到</span><code style=""><span leaf="">squid.conf.template</span></code></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 class="rich_pages wxw-img" data-imgfileid="100002060" data-ratio="0.3333333333333333" src="/upload/b7238683d106b749dc7b5c347c23293f.png" data-type="png" data-w="537" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在这里,你可以设置允许访问的网络,允许访问的端口,</span><code style=""><span leaf="">生产一定要最小权限</span></code></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 k0ue4mipavick8hqialiakg2tb1ebnwq3bs1gdsusaaoialugirysdnk19v5ftbvraq0mgzeeyoukk6rprqxtrmqfohj0o9toqm8 640?wx_fmt="svg&from=appmsg");""><span leaf=""><br></span></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="">acl devnet src 10.1.0.0/24</span><span leaf=""><br></span><span leaf="">acl devnet src 10.255.200.0/24</span><span leaf=""><br></span><span leaf=""><br></span><span leaf="">acl Safe_ports port 3306 # MySQL</span><span leaf=""><br></span><span leaf="">acl Safe_ports port 5432 # Postgres</span><span leaf=""><br></span><span leaf="">acl Safe_ports port 27017 # MongoDB</span><span leaf=""><br></span><span leaf="">acl Safe_ports port 6379 # Redis</span><span leaf=""><br></span><span leaf=""><br></span><span leaf="">http_access allow devnet</span><span leaf=""><br></span></code></pre> <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(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <code style=""><span leaf="">devnet</span></code><span leaf=""> 为定义的规则集名称,后面跟自己的ip段设置,表示:</span><code style=""><span leaf="">10.255.200.1</span></code><span leaf=""> 到 </span><code style=""><span leaf="">10.255.200.254</span></code><span leaf="">-</span><code style=""><span leaf="">acl Safe_ports port</span></code><span leaf=""> 允许访问的端口</span> </section></li> <li> <section style="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;"> <code style=""><span leaf="">http_access allow devnet</span></code><span leaf=""> 允许访问的规则集</span> </section></li> </ul> <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;display: block;"><span style="display: none;"><span leaf=""><br></span></span><span style="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="">重新部署dify</span></span><span style="display: none;"><span leaf=""><br></span></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在dify的的docker目录中修改</span><code style=""><span leaf="">docker-compose.yaml</span></code><span leaf="">文件sandbox使用本地镜像。</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 k0ue4mipavick8hqialiakg2tb1ebnwq3bs1gdsusaaoialugirysdnk19v5ftbvraq0mgzeeyoukk6rprqxtrmqfohj0o9toqm8 640?wx_fmt="svg&from=appmsg");""><span leaf=""><br></span></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=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">sandbox:</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf="">#image: langgenius/dify-sandbox:0.2.10</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">image:</span></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">dify-sandbox:local</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">restart:</span></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">always</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">environment:</span></span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">将</span><code style=""><span leaf="">image</span></code><span leaf="">由</span><code style=""><span leaf="">langgenius/dify-sandbox:0.2.10</span></code><span leaf=""> 改为了</span><code style=""><span leaf="">dify-sandbox:local</span></code></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在docker目录下执行以下命令</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 k0ue4mipavick8hqialiakg2tb1ebnwq3bs1gdsusaaoialugirysdnk19v5ftbvraq0mgzeeyoukk6rprqxtrmqfohj0o9toqm8 640?wx_fmt="svg&from=appmsg");""><span leaf=""><br></span></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="">#</span></span><span style="line-height: 26px;"><span leaf=""> 销毁</span></span><span leaf=""><br></span><span leaf="">docker compose down</span><span leaf=""><br></span><span style="color: #61aeee;line-height: 26px;"><span leaf="">#</span></span><span style="line-height: 26px;"><span leaf=""> 重新部署</span></span><span leaf=""><br></span><span leaf="">docker compose up -d</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;display: block;"><span style="display: none;"><span leaf=""><br></span></span><span style="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><span style="display: none;"><span leaf=""><br></span></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">使用kimi生成了一个python代码</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 k0ue4mipavick8hqialiakg2tb1ebnwq3bs1gdsusaaoialugirysdnk19v5ftbvraq0mgzeeyoukk6rprqxtrmqfohj0o9toqm8 640?wx_fmt="svg&from=appmsg");""><span leaf=""><br></span></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: #c678dd;line-height: 26px;"><span leaf="">import</span></span><span leaf=""> sys</span><span leaf=""><br></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">import</span></span><span leaf=""> pymysql</span><span leaf=""><br></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">import</span></span><span leaf=""> os</span><span leaf=""><br></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">connect_to_database</span></span><span style="line-height: 26px;"><span leaf="">()</span></span><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: #c678dd;line-height: 26px;"><span leaf="">try</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 从环境变量或配置文件中获取数据库参数</span></span><span leaf=""><br></span><span leaf=""> host = os.getenv(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"DB_HOST"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"localhost"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> user = os.getenv(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"DB_USER"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"root"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> password = os.getenv(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"DB_PASSWORD"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"password"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> database = os.getenv(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"DB_NAME"</span></span><span leaf="">, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"database_name"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> conn = pymysql.connect(</span><span leaf=""><br></span><span leaf=""> host=host,</span><span leaf=""><br></span><span leaf=""> user=user,</span><span leaf=""><br></span><span leaf=""> password=password,</span><span leaf=""><br></span><span leaf=""> database=database,</span><span leaf=""><br></span><span leaf=""> charset=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'utf8mb4'</span></span><span leaf="">,</span><span leaf=""><br></span><span leaf=""> cursorclass=pymysql.cursors.DictCursor </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><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> conn</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">except</span></span><span leaf=""> pymysql.MySQLError </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">as</span></span><span leaf=""> err:</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"Error connecting to database: </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{err}</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 style="color: #56b6c2;line-height: 26px;"><span leaf="">None</span></span><span leaf=""><br></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">execute_query</span></span><span style="line-height: 26px;"><span leaf="">(conn, query, params=None)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">""" 执行 SQL 查询,并支持参数化查询 """</span></span><span leaf=""><br></span><span leaf=""> cursor = conn.cursor()</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">try</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=""> params:</span><span leaf=""><br></span><span leaf=""> cursor.execute(query, params)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">else</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> cursor.execute(query)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> cursor.fetchall()</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">except</span></span><span leaf=""> pymysql.MySQLError </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">as</span></span><span leaf=""> err:</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"Error executing query: </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{err}</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 style="color: #56b6c2;line-height: 26px;"><span leaf="">None</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">finally</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> cursor.close()</span><span leaf=""><br></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">generate_markdown_table</span></span><span style="line-height: 26px;"><span leaf="">(results)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">""" 生成 Markdown 表格 """</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">not</span></span><span leaf=""> results:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span style="color: #98c379;line-height: 26px;"><span leaf="">""</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 获取列名</span></span><span leaf=""><br></span><span leaf=""> columns = results[</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">].keys()</span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 表头</span></span><span leaf=""><br></span><span leaf=""> table_md = </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="">.join([col </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> col </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> columns]) + </span><span style="color: #98c379;line-height: 26px;"><span leaf="">" |\n"</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 分隔线</span></span><span leaf=""><br></span><span leaf=""> table_md += </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=""> * len(columns) + </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"\n"</span></span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> </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="">for</span></span><span leaf=""> row </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> results:</span><span leaf=""><br></span><span leaf=""> table_md += </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="">.join([str(cell) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> cell </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> row.values()]) + </span><span style="color: #98c379;line-height: 26px;"><span leaf="">" |\n"</span></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=""> table_md</span><span leaf=""><br></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">main</span></span><span style="line-height: 26px;"><span leaf="">(arg1: str)</span></span><span leaf=""> -> dict:</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 参数化查询,避免 SQL 注入</span></span><span leaf=""><br></span><span leaf=""> query = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"SELECT * FROM table_name WHERE column LIKE %s"</span></span><span leaf=""><br></span><span leaf=""> params = (</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'%'</span></span><span leaf=""> + arg1 + </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'%'</span></span><span leaf="">,)</span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 连接到数据库</span></span><span leaf=""><br></span><span leaf=""> conn = connect_to_database()</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">not</span></span><span leaf=""> conn:</span><span leaf=""><br></span><span leaf=""> sys.exit(</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</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="">try</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 执行查询</span></span><span leaf=""><br></span><span leaf=""> result = execute_query(conn, query, params)</span><span leaf=""><br></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=""> result </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">is</span></span><span style="color: #56b6c2;line-height: 26px;"><span leaf="">None</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: #98c379;line-height: 26px;"><span leaf="">"result"</span></span><span leaf="">: [], </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"markdown"</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">""</span></span><span leaf="">}</span><span leaf=""><br></span><span leaf=""> </span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 生成 Markdown 表格</span></span><span leaf=""><br></span><span leaf=""> markdown_table = generate_markdown_table(result)</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=""> {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"result"</span></span><span leaf="">: result,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"markdown"</span></span><span leaf="">: markdown_table</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">except</span></span><span leaf=""> Exception </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">as</span></span><span leaf=""> e:</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"Unexpected error: </span><span style="color: #e06c75;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: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> {</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"result"</span></span><span leaf="">: [], </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"markdown"</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">""</span></span><span leaf="">}</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">finally</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 确保数据库连接关闭</span></span><span leaf=""><br></span><span leaf=""> conn.close()</span><span leaf=""><br></span></code></pre> <h2 data-tool="mdnice编辑器" style="border-bottom-color: rgb(239, 112, 96);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: unset;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: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-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;height: auto;justify-content: unset;line-height: 1.1em;overflow-x: unset;overflow-y: unset;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"><span leaf=""><br></span></span><span style="font-size: 22px;color: rgb(255, 255, 255);background-color: rgb(239, 112, 96);line-height: 1.5em;letter-spacing: 0em;align-items: unset;background-attachment: scroll;background-clip: border-box;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: 3px;border-top-right-radius: 3px;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: 0px;margin-right: 5px;overflow-x: unset;overflow-y: unset;padding-top: 3px;padding-bottom: 1px;padding-left: 10px;padding-right: 10px;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 leaf=""><br></span></span><span style="border-bottom-color: rgb(239, 235, 233);align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-left-style: none;border-right-style: solid;border-top-width: 1px;border-bottom-width: 36px;border-left-width: 1px;border-right-width: 20px;border-top-color: rgb(0, 0, 0);border-left-color: rgb(0, 0, 0);border-right-color: transparent;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: 16px;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;letter-spacing: 0px;line-height: 1.1em;margin-top: 0px;margin-bottom: 0px;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;width: auto;-webkit-box-reflect: unset;"><span leaf=""> </span></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这两种方式,不管哪种都能实现查询数据库,但是有个问题,数据量小的时候性能还行,数据量大了,你查询一次就得耗时好久。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">如果知识固定,也可以前置设置一个知识库把关键词和文章映射出来,这样大模型整理的时候,尽量的去往对应的关键词上靠。</span></p> </section>
作者:微信小助手
<h1 data-track="2" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">了解ReRank模型前先回顾一下RAG的流程</span></h1> <h1 data-track="2" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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=""><img src="/upload/d47a84c048271ead6f70f7d5e5f5b49f.png" alt="在这里插入图片描述" class="rich_pages wxw-img" data-ratio="0.6324074074074074" data-type="png" data-w="1080" data-imgfileid="100001567"></span></h1> <h1 data-track="2" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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=""><span textstyle="" style="font-size: 18px;">什么是Rerank模型?</span></span></h1> <p data-track="3" style="box-sizing: border-box;margin: 20px 0px;padding: 0px;border: 0px;color: rgb(34, 34, 34);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-size: 18px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: justify;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 style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;"> Rerank模型是一种用于优化信息检索结果排序的机器学习模型,通过精细化评估文档与查询的相关性,提升最终结果的准确性和语义匹配度。以下是其核心要点:</span></span></span></p> <section> <strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;">定义与定位</span></span></span></strong><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><br></span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><br></span></span> </section> <section> <span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;"> 属于重排序算法,作用于初步检索(如关键词匹配或向量相似度检索)之后,对候选文档进行二次筛选和排序。</span></span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;">在RAG(检索增强生成)流程中,与Embedding模型配合使用,形成“粗筛+精排”的协同机制。</span></span></span> </section> <section> <strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;">核心作用</span></span></span></strong> </section> <ul style="list-style-type: disc;" class="list-paddingleft-1"> <li> <section> <span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf="" data-pm-slice="1 1 [" para,null,node,{tagname:span,attributes:{style:box-sizing: border-box; margin: 0px; padding: border: color: rgb(51, 51, 51); --tt-darkmode-color: #a3a3a3;},namespaceuri:http: www.w3.org 1999 xhtml}]><span textstyle="" style="font-size: 18px;font-weight: bold;">解决初步检索的局限性</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;font-weight: bold;">:</span><span textstyle="" style="font-size: 18px;">弥补传统检索方法(如倒排索引或Embedding相似度计算)在语义理解深度上的不足。</span></span></span></span></span> </section></li> <li> <section> <span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf="" data-pm-slice="1 1 [" para,null,node,{tagname:span,attributes:{style:box-sizing: border-box; margin: 0px; padding: border: color: rgb(51, 51, 51); --tt-darkmode-color: #a3a3a3;},namespaceuri:http: www.w3.org 1999 xhtml}]><span textstyle="" style="font-size: 18px;font-weight: bold;">提升结果质量</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;font-weight: bold;">:</span><span textstyle="" style="font-size: 18px;">通过多维度评估(如语义一致性、上下文关联性)对文档重新打分,确保高相关性的内容优先展示。</span></span></span></span> </section> <section> <span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><br></span></span></span> </section></li> </ul> <section> <strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;">工作原理</span></span></span></strong> </section> <ul style="list-style-type: disc;" class="list-paddingleft-1"> <li> <section> <span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf="" data-pm-slice="1 1 [" para,null,node,{tagname:span,attributes:{style:box-sizing: border-box; margin: 0px; padding: border: color: rgb(51, 51, 51); --tt-darkmode-color: #a3a3a3;},namespaceuri:http: www.w3.org 1999 xhtml}]><span textstyle="" style="font-size: 18px;font-weight: bold;">监督学习训练</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;font-weight: bold;">:</span><span textstyle="" style="font-size: 18px;">基于大量正确与不正确的查询-文档对,模型学习最大化正确对的分数、最小化错误对的分数。</span></span></span></span> </section></li> <li> <section> <span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf="" data-pm-slice="1 1 [" para,null,node,{tagname:span,attributes:{style:box-sizing: border-box; margin: 0px; padding: border: color: rgb(51, 51, 51); --tt-darkmode-color: #a3a3a3;},namespaceuri:http: www.w3.org 1999 xhtml}]><span textstyle="" style="font-size: 18px;font-weight: bold;">相关性评分</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;font-weight: bold;">:</span><span textstyle="" style="font-size: 18px;">输入查询和文档,直接输出两者的匹配分数,并依此排序。</span></span></span></span> </section> <section> <span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><br></span></span></span> </section></li> </ul> <section> <strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;">典型应用场景</span></span></span></strong> </section> <ul style="list-style-type: disc;" class="list-paddingleft-1"> <li> <section> <strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;">RAG系统</span></span></span></strong><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;">:优化检索文档的排序,提升大模型生成回答的准确性。</span></span></span> </section></li> <li> <section> <span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;font-weight: bold;">搜索引擎/推荐系统</span></span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(51, 51, 51);"><span leaf=""><span textstyle="" style="font-size: 18px;font-weight: bold;">:</span><span textstyle="" style="font-size: 18px;">精细化调整结果顺序,增强用户满意度。</span></span></span> </section></li> </ul> <h1 data-track="279" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">排序的关键维度</span></h1> <h1 data-track="280" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">语义相关性</span></h1> <pre style="box-sizing: border-box;font-family: Monaco;font-size: 18px;margin: 20px 0px;padding: 15px;border: 0px;background: rgb(250, 250, 250);white-space: pre-wrap;word-break: break-all;display: block;overflow-x: auto;border-radius: 3px;text-align: left;color: rgb(34, 34, 34);box-shadow: rgba(216, 216, 216, 0.5) 0px 0px 0px 1px inset;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;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="white-space:pre-wrap;box-sizing: border-box;font-family: inherit;font-size: 14px;margin: 0px;padding: 0px;border: 0px;overflow-wrap: normal;word-break: normal;overflow-x: auto;line-height: 24px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">#</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;"><span leaf=""> 用户问题:</span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">"糖尿病患者的饮食禁忌有哪些?"</span></span></span><span leaf=""><br></span><span leaf="">候选文档1:详细列举12种糖尿病饮食禁忌(相关度高)</span><span leaf=""><br></span><span leaf="">候选文档2:讲解胰岛素注射方法(相关度低)</span></code></pre> <h1 data-track="282" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">时效性权重</span></h1> <pre style="box-sizing: border-box;font-family: Monaco;font-size: 18px;margin: 20px 0px;padding: 15px;border: 0px;background: rgb(250, 250, 250);white-space: pre-wrap;word-break: break-all;display: block;overflow-x: auto;border-radius: 3px;text-align: left;color: rgb(34, 34, 34);box-shadow: rgba(216, 216, 216, 0.5) 0px 0px 0px 1px inset;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;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="white-space:pre-wrap;box-sizing: border-box;font-family: inherit;font-size: 14px;margin: 0px;padding: 0px;border: 0px;overflow-wrap: normal;word-break: normal;overflow-x: auto;line-height: 24px;"><span leaf="">文档A:2023年《中国糖尿病防治指南》(权重+20%)</span><span leaf=""><br></span><span leaf="">文档B:2010年某医院内部资料(权重-30%)</span></code></pre> <h1 data-track="286" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">多样性控制</span></h1> <pre style="box-sizing: border-box;font-family: Monaco;font-size: 18px;margin: 20px 0px;padding: 15px;border: 0px;background: rgb(250, 250, 250);white-space: pre-wrap;word-break: break-all;display: block;overflow-x: auto;border-radius: 3px;text-align: left;color: rgb(34, 34, 34);box-shadow: rgba(216, 216, 216, 0.5) 0px 0px 0px 1px inset;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;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="white-space:pre-wrap;box-sizing: border-box;font-family: inherit;font-size: 14px;margin: 0px;padding: 0px;border: 0px;overflow-wrap: normal;word-break: normal;overflow-x: auto;line-height: 24px;"><span leaf="">避免返回3篇都讲</span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">"糖分控制"</span></span><span leaf="">的文章</span><span leaf=""><br></span><span leaf="">保留1篇</span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">"运动管理"</span></span><span leaf="">的补充内容</span></code></pre> <h1 data-track="119" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">排序面临的挑战</span></h1> <section> <span leaf=""><img src="/upload/8577432d63a64c2377780254be5599e7.jpg" class="rich_pages wxw-img" data-ratio="0.8481481481481481" data-type="jpeg" data-w="1080" data-imgfileid="100001565"></span> </section> <p><span leaf=""><span textstyle="" style="font-size: 18px;font-weight: bold;">长尾问题</span></span></p> <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=""><code><span leaf="">用户提问:“如何训练导盲犬AI机器人?” </span></code><code><span leaf="">检索结果: 前10篇:通用机器人训练方法(未命中) </span></code><code><span leaf=""> 仅1篇:《基于多模态感知的导盲犬机器人训练指南》(命中但排名靠后)</span></code></pre> </section> <p><span leaf=""><span textstyle="" style="font-size: 18px;font-weight: bold;">解决策略:</span></span></p> <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">"导盲犬+机器人"</span>的伪数据微调模型</span></code><code><span leaf="">混合检索:结合关键词(“导盲犬”+“<span class="code-snippet__variable">AI</span>”)与语义检索</span></code><code><span leaf="">主动学习:标注低置信度结果,迭代优化模型</span></code></pre> </section> <h1 data-track="290" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">语义鸿沟</span></h1> <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="makefile"><code><span leaf=""><span class="code-snippet__section">用户问:“手机发热严重怎么降温?</span></span></code><code><span leaf="">检索结果:《移动设备SoC功耗管理与散热优化方案》(语义相关)</span></code><code><span leaf=""> 《智能手机电池保养技巧》(字面相关但非核心)</span></code></pre> </section> <h1 data-track="290" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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=""><span textstyle="" style="font-size: 18px;font-weight: bold;">解决策略:</span></span></h1> <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__number">1.</span> 查询扩展:用<span class="code-snippet__variable">LLM</span>生成同义表述(如<span class="code-snippet__string">"发热"</span>→<span class="code-snippet__string">"散热"</span>、“降温<span class="code-snippet__string">"→"</span>温度控制”) </span></code><code><span leaf=""><span class="code-snippet__number">2.</span> 上下文增强:提取文档中<span class="code-snippet__string">"发热"</span>相关段落提升权重 </span></code><code><span leaf=""><span class="code-snippet__number">3.</span> 用户反馈:记录用户最终点击的文档,反向优化模型</span></code></pre> </section> <section> <span data-lark-record-data="{" rootid:mqlddkkfaoarumxq5ljcpyi6nuf,text:{initialattributedtexts:{text:{0:文档标题: ◦ 《移动设备soc功耗管理与散热优化方案》(语义相关) 《智能手机电池保养技巧》(字面相关但非核心)},attribs:{0:*0+1n}},apool:{numtoattrib:{0:[author,7480500817733943298]},nextnum:1}},type:text,referencerecordmap:{},extra:{channel:saas,isequalblockselection:false,pasterandomid:ff8946af-a32f-44e1-8702-5831e87eca76,mention_page_title:{},external_mention_url:{}},iskeepquotecontainer:false,isfromcode:false,selection:[{id:69,type:text,selection:{start:477,end:536},recordid:rddldkhonovtizxkww7cmlhunvh}],payloadmap:{lingoclipboardpayload:{spacesubextrainfo:[{spacesubid:rddldkhonovtizxkww7cmlhunvh,word:soc}],spaceid:mqlddkkfaoarumxq5ljcpyi6nuf,spacetype:1}},iscut:false} data-lark-record-format="docx/text"></span> </section> <h1 data-track="292" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">多语言混合</span></h1> <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=""><code><span leaf="">中文提问:“量子纠缠的实际应用有哪些?</span></code><code><span leaf="">检索结果: 中文文档:《里子通信技术白皮书》(匹配度一般)</span></code><code><span leaf=""> 英文论文:《Quantum Entanglement inCommercial Systems》(Nature 2023,高相关)</span></code></pre> </section> <p data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [" para,{tagname:p,attributes:{data-pm-slice:0 0 []},namespaceuri:http: www.w3.org 1999 xhtml}]><span textstyle="" style="font-size: 18px;font-weight: bold;">解决策略:</span></span></p> <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="markdown"><code><span leaf=""><span class="code-snippet__bullet">1.</span> 实时翻译对齐:将英文论文摘要翻译后参与排序 </span></code><code><span leaf=""><span class="code-snippet__bullet">2.</span> 跨语言模型:使用mBERT等模型直接计算中英文相似度 </span></code><code><span leaf=""><span class="code-snippet__bullet">3.</span> 多语言标签:为文档添加语言/领域元数据辅助过滤</span></code></pre> </section> <section> <span data-lark-record-data="{" rootid:mqlddkkfaoarumxq5ljcpyi6nuf,text:{initialattributedtexts:{text:{0: 知识库内容: ◦ 中文文档:《量子通信技术白皮书》(匹配度一般) 英文论文:《quantum entanglement in commercial systems》(nature 2023, 高相关)},attribs:{0:*0+2v}},apool:{numtoattrib:{0:[author,7480500817733943298]},nextnum:1}},type:text,referencerecordmap:{},extra:{channel:saas,isequalblockselection:false,pasterandomid:d6132f08-ab71-4830-b5f9-0d88539e73b9,mention_page_title:{},external_mention_url:{}},iskeepquotecontainer:false,isfromcode:false,selection:[{id:69,type:text,selection:{start:676,end:779},recordid:rddldkhonovtizxkww7cmlhunvh}],payloadmap:{},iscut:false} data-lark-record-format="docx/text"></span> </section> <h1 data-track="294" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">计算效率</span></h1> <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__number">100</span>万篇医疗文献库</span></code><code><span leaf="">查询需求:实时返回<span class="code-snippet__string">"阿尔茨海默症新药研发进展"</span><span class="code-snippet__title">Top5</span>结果(<500ms)</span></code></pre> </section> <h1 data-track="294" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="" data-pm-slice="1 1 [" para,{tagname:p,attributes:{data-pm-slice:0 0 []},namespaceuri:http: www.w3.org 1999 xhtml}]><span textstyle="" style="font-size: 18px;font-weight: bold;">解决策略:</span></span></h1> <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="markdown"><code><span leaf=""><span class="code-snippet__bullet">1.</span> 两阶段排序: </span></code><code><span leaf=""> 第一阶段:BM25快速筛选1000篇(耗时50ms) </span></code><code><span leaf=""> 第二阶段:Reranker精排Top100(耗时400ms) </span></code><code><span leaf=""><span class="code-snippet__bullet">2.</span> 模型蒸馏:将BERT-large蒸馏为Tiny版,速度提升5倍 </span></code><code><span leaf=""><span class="code-snippet__bullet">3.</span> 硬件加速:使用TensorRT部署模型,GPU推理吞吐量提升10倍</span></code></pre> </section> <section> <span data-lark-record-data="{" rootid:mqlddkkfaoarumxq5ljcpyi6nuf,text:{initialattributedtexts:{text:{0:数据规模:100万篇医疗文献库 • 查询需求:实时返回\阿尔茨海默症新药研发进展\top5结果(<500ms)},attribs:{0:*0+1j}},apool:{numtoattrib:{0:[author,7480500817733943298]},nextnum:1}},type:text,referencerecordmap:{},extra:{channel:saas,isequalblockselection:false,pasterandomid:632f18ae-3ccb-4633-b8dd-75d5b07a7de9,mention_page_title:{},external_mention_url:{}},iskeepquotecontainer:false,isfromcode:false,selection:[{id:69,type:text,selection:{start:881,end:936},recordid:rddldkhonovtizxkww7cmlhunvh}],payloadmap:{lingoclipboardpayload:{spacesubextrainfo:[{spacesubid:rddldkhonovtizxkww7cmlhunvh,word:ms}],spaceid:mqlddkkfaoarumxq5ljcpyi6nuf,spacetype:1}},iscut:false} data-lark-record-format="docx/text"></span> </section> <h1 data-track="119" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">主流模型选型</span></h1> <table style="box-sizing: border-box;margin: 0px auto;padding: 0px;border-collapse: collapse;border-spacing: 0px;border: 0px;table-layout: fixed;word-break: normal;color: rgb(34, 34, 34);min-width: 168px;"> <tbody> <tr style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;"> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="120" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;"><span leaf="">模型</span></p></td> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="121" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;"><span leaf="">特点</span></p></td> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="122" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;"><span leaf="">性能优势</span></p></td> </tr> <tr style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;"> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="123" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;text-align: left;"><strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span leaf="">BGE ReRanker</span></strong></p></td> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="124" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;"><span leaf="">支持多语言</span></p></td> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="125" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;"><span leaf="">多语言场景、高精度需求</span></p></td> </tr> <tr style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;"> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="126" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;text-align: left;"><strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span leaf="">Jina Reranker</span></strong></p></td> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="127" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;"><span leaf="">8k上下文支持</span></p></td> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="128" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;"><span leaf="">长文本排序、低延迟场景</span></p></td> </tr> <tr style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;"> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="129" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;text-align: left;"><strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span leaf="">BCE-Reranker</span></strong></p></td> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="130" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;"><span leaf="">网易有道开源,中英跨语言优化</span></p></td> <td style="box-sizing: border-box;margin: 0px;padding: 8px 12px;border: 1px solid rgb(232, 232, 232);vertical-align: top;font-weight: 400;text-align: left;font-size: 16px;line-height: 28px;min-height: 44px;"><p data-track="131" style="box-sizing: border-box;margin-top: 0px !important;margin-right: 0px;margin-bottom: 0px !important;margin-left: 0px;padding: 0px;border: 0px;"><span leaf="">中英混合场景、高召回率需求</span></p></td> </tr> </tbody> </table> <h1 data-track="232" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">完整排序流程示例</span></h1> <p data-track="240" style="box-sizing: border-box;margin: 20px 0px;padding: 0px;border: 0px;color: rgb(34, 34, 34);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-size: 18px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: justify;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;><strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span leaf="">用户问题</span></strong><span leaf="">:"美联储加息对A股的影响"</span></p> <ol style="box-sizing: border-box;margin: 20px 30px;padding: 0px;border: 0px;counter-reset: ol_list 0;color: rgb(34, 34, 34);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-size: 18px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: justify;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;margin: 0px;padding: 0px;list-style: decimal;border: 0px;"> <section> <span leaf="">初步检索(Retriever):</span> </section></li> </ol> <pre style="box-sizing: border-box;font-family: Monaco;font-size: 18px;margin: 20px 0px;padding: 15px;border: 0px;background: rgb(250, 250, 250);white-space: pre-wrap;word-break: break-all;display: block;overflow-x: auto;border-radius: 3px;text-align: left;color: rgb(34, 34, 34);box-shadow: rgba(216, 216, 216, 0.5) 0px 0px 0px 1px inset;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;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="white-space:pre-wrap;box-sizing: border-box;font-family: inherit;font-size: 14px;margin: 0px;padding: 0px;border: 0px;overflow-wrap: normal;word-break: normal;overflow-x: auto;line-height: 24px;"><span leaf="">返回50篇文档:</span><span leaf=""><br></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(168, 46, 46);"><span leaf="">- 10篇关于美国货币政策</span></span><span leaf=""><br></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(168, 46, 46);"><span leaf="">- 15篇A股市场分析</span></span><span leaf=""><br></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(168, 46, 46);"><span leaf="">- 20篇历史加息案例</span></span><span leaf=""><br></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(168, 46, 46);"><span leaf="">- 5篇无关内容</span></span><span leaf=""><br></span></code></pre> <section> <span leaf="">2. Reranker工作流:</span> </section> <pre style="box-sizing: border-box;font-family: Monaco;font-size: 18px;margin: 20px 0px;padding: 15px;border: 0px;background: rgb(250, 250, 250);white-space: pre-wrap;word-break: break-all;display: block;overflow-x: auto;border-radius: 3px;text-align: left;color: rgb(34, 34, 34);box-shadow: rgba(216, 216, 216, 0.5) 0px 0px 0px 1px inset;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;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="white-space:pre-wrap;box-sizing: border-box;font-family: inherit;font-size: 14px;margin: 0px;padding: 0px;border: 0px;overflow-wrap: normal;word-break: normal;overflow-x: auto;line-height: 24px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">for</span></span><span leaf=""> </span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">文档</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">in</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(168, 46, 46);"><span leaf="">50</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">篇:</span></span><span leaf=""><br></span><span leaf=""> </span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">计算语义相关性(BERT模型)→</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">得分0.6-0.95</span></span><span leaf=""><br></span><span leaf=""> </span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">叠加时效性权重(2023年文档×1.2)</span></span><span leaf=""><br></span><span leaf=""> </span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">扣除低权威惩罚(自媒体文章×0.7)</span></span><span leaf=""><br></span><span leaf=""> </span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">最终得分</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">=</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">语义分×时效权重×权威系数</span></span><span leaf=""><br></span><span leaf=""><br></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">排序后Top3:</span></span><span leaf=""><br></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(168, 46, 46);"><span leaf="">1</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">.</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">《2023年美联储政策与新兴市场联动分析》(0.94)</span></span><span leaf=""><br></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(168, 46, 46);"><span leaf="">2</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">.</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">《跨境资本流动对A股的影响机制》(0.91)</span></span><span leaf=""><br></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(168, 46, 46);"><span leaf="">3</span></span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">.</span></span><span leaf=""> </span><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(0, 117, 59);"><span leaf="">《历史六轮加息周期中的板块表现》(0.89)</span></span></code></pre> <h1 data-track="107" style="box-sizing: border-box;font-size: 1.056em;margin: 20px 0px;padding: 0px;font-weight: 700;border: 0px;line-height: 1.579;color: rgb(0, 0, 0);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: justify;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="">Reranker本质</span></h1> <p data-track="107" style="box-sizing: border-box;margin: 20px 0px;padding: 0px;border: 0px;color: rgb(34, 34, 34);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-size: 18px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: justify;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=""> Reranker是知识库的"</span><strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(26, 116, 255);"><span leaf="">智能质检员</span></span></strong><span leaf="">",假设你在图书馆找书,先用关键词检索到100本书,但需要找出</span><strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(26, 116, 255);"><span leaf="">最相关</span></span></strong><span leaf="">的3本才行。</span></p> <p data-track="278" style="box-sizing: border-box;margin: 20px 0px;padding: 0px;border: 0px;color: rgb(34, 34, 34);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-size: 18px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: justify;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="" data-pm-slice="1 1 [" para,{tagname:p,attributes:{data-track:107,style:box-sizing: border-box; margin: 20px 0px; padding: border: color: rgb(34, 34, 34); font-family: \pingfang sc\, \hiragino sans gb\, \microsoft yahei\, \wenquanyi micro hei\, \helvetica neue\, arial, sans-serif; font-size: 18px; font-style: normal; font-variant-ligatures: font-variant-caps: font-weight: 400; letter-spacing: orphans: 2; text-align: justify; text-indent: text-transform: none; widows: word-spacing: -webkit-text-stroke-width: white-space: background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: text-decoration-color: initial;},namespaceuri:http: www.w3.org 1999 xhtml}]> 图书管理员</span><span leaf="">(Reranker)会综合评估书籍内容、出版时间、作者权威性等维度进行二次筛选。</span></p> <p data-track="277" style="box-sizing: border-box;margin: 20px 0px;padding: 0px;border: 0px;color: rgb(34, 34, 34);font-family: " pingfang sc, hiragino sans gb, microsoft yahei, wenquanyi micro hei, helvetica neue, arial, sans-serif;font-size: 18px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: justify;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="" data-pm-slice="1 1 [" para,{tagname:p,attributes:{data-track:107,style:box-sizing: border-box; margin: 20px 0px; padding: border: color: rgb(34, 34, 34); font-family: \pingfang sc\, \hiragino sans gb\, \microsoft yahei\, \wenquanyi micro hei\, \helvetica neue\, arial, sans-serif; font-size: 18px; font-style: normal; font-variant-ligatures: font-variant-caps: font-weight: 400; letter-spacing: orphans: 2; text-align: justify; text-indent: text-transform: none; widows: word-spacing: -webkit-text-stroke-width: white-space: background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: text-decoration-color: initial;},namespaceuri:http: www.w3.org 1999 xhtml}]> 将检索到的候选文档(如100条)按照与问题的</span><strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(26, 116, 255);"><span leaf="">相关度</span></span></strong><span leaf="">重新排序,把</span><strong style="box-sizing: border-box;font-weight: 700;margin: 0px;padding: 0px;border: 0px;"><span style="box-sizing: border-box;margin: 0px;padding: 0px;border: 0px;color: rgb(26, 116, 255);"><span leaf="">最匹配</span></span></strong><span leaf="">的结果提升到Top位置。</span></p> <p><span leaf=""><span textstyle="" style="font-size: 18px;"> Reranker模型是RAG系统中的智能排序引擎, 在知识库检索流程中承担着关键的优化角色。它通过多维度智能分析,对初步检索结果进行精细化处理,将最符合用户真实需求的信息精准呈现在前列。</span></span></p> <p><span leaf=""><span textstyle="" style="font-size: 18px;"> 不同于初检阶段的粗粒度筛选,Reranker会综合评估语义相关度(如问题与内容的深层匹配)、时效性(优先最新资料)、权威性(区分专家论述与普通观点)以及内容完整性(覆盖关键要素的程度)等多个核心维度,通过算法加权计算出每个结果的最终排序得分。</span></span></p> <p><span leaf=""><span textstyle="" style="font-size: 18px;"> 在企业级应用中, 这种智能排序机制有效解决了传统检索中面临的长尾问题、语义鸿沟等挑战,大幅提升了知识库的可用性和准确性,是确保专业用户获得高价值信息的关键技术保障。</span></span></p>
作者:微信小助手
<section style="text-indent: 0em;text-align: center;" data-mpa-powered-by="yiban.io"> <span style="font-size: 18px;">在人工智能飞速发展的当下</span> </section> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;">对于广大学生和科研工作者而言</span> </section> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;">一个关键问题随之而来</span> </section> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;"><strong><span style="color: rgb(0, 122, 170);">借助这些前沿大模型写论文</span></strong></span> </section> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;"><strong><span style="color: rgb(0, 122, 170);">真的靠谱吗?</span></strong></span> </section> <p style="text-indent: 2em;"><span style="font-size: 18px;"><br></span></p> <p><img class="rich_pages wxw-img" data-backh="201.822086" data-backw="576.822086" data-galleryid="" data-imgfileid="519447756" data-ratio="0.3490740740740741" data-s="300,640" src="/upload/18c314b057cbbcf79ac9bd0cb3164057.jpg" data-type="png" data-w="1080" style="letter-spacing: 0.578px;text-align: center;border-style: solid;border-width: 1px;border-color: rgb(0, 0, 0);width: 100%;height: auto;"></p> <p><br></p> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;">不久前</span> </section> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;">#防止DeepSeek乱编文献的方法#</span> </section> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;">冲上热搜</span> </section> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;">记者注意到</span> </section> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;"><strong><span style="color: rgb(0, 122, 170);">用AI工具写论文“被坑”的经历</span></strong></span> </section> <section style="text-indent: 0em;text-align: center;"> <span style="font-size: 18px;"><strong><span style="color: rgb(0, 122, 170);">并非鲜见</span></strong></span> </section> <p style="text-indent: 2em;"><br></p> <section> <img class="rich_pages wxw-img" data-backh="841.822086" data-backw="576.822086" data-galleryid="" data-imgfileid="519447759" data-ratio="1.4592592592592593" data-s="300,640" src="/upload/375e4cd9ddb8235e63259f7f968e97a5.jpg" data-type="png" data-w="1080" style="letter-spacing: 0.578px;text-align: center;border-style: solid;border-width: 1px;width: 100%;height: auto;"> </section> <section> <br> </section> <section style="text-align: center;"> <span style="font-size: 18px;">有网友列出了自己的亲身经历</span> </section> <section style="text-align: center;"> <span style="font-size: 18px;">除了编造论文文献</span> </section> <section style="text-align: center;"> <span style="font-size: 18px;">AI还会编造法律条文<br></span> </section> <section style="text-align: center;"> <strong><span style="font-size: 18px;color: rgb(0, 122, 170);">甚至教人做菜还跑偏了</span></strong> </section> <section> <br> </section> <section style="font-size: 16px;color: rgb(62, 62, 62);"> <section style="margin-top: 10px;margin-bottom: 10px;display: inline-block;width: 100%;border-width: 1px;border-style: solid;border-color: rgb(192, 200, 209);padding: 10px;background-color: rgb(250, 250, 239);box-shadow: rgb(170, 170, 170) 0px 0px 10px;"> <section style="color: rgb(51, 51, 51);width: 100%;"> <section style="margin-bottom: 0px;letter-spacing: 0.578px;"> <img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="519447758" data-ratio="0.20925925925925926" data-s="300,640" src="/upload/3e3c5f62eef8a402a54b413fceb9f768.png" data-type="png" data-w="1080" style="letter-spacing: 0.578px;text-align: center;"> </section> <p style="margin-bottom: 0px;letter-spacing: 0.578px;text-align: center;"><img class="rich_pages wxw-img" data-galleryid="" data-imgfileid="519447755" data-ratio="0.29074074074074074" data-s="300,640" src="/upload/4e778de885d4869e6a3968e1e9c0f17a.png" data-type="png" data-w="1080"></p> </section> </section> </section> <p style="text-align: center;"><br></p> <p style="text-indent: 2em;"><span style="font-size: 18px;">问AI一个问题,它给了你一个特别详细、丰富,看上去好有逻辑的答案。但当我们去核实时,却发现这些信息完全是虚构的。<strong><span style="color: rgb(0, 122, 170);">这就是著名的“AI幻觉”现象。</span></strong></span></p> <p style="text-indent: 2em;"><span style="font-size: 18px;"><br></span></p> <p style="text-indent: 2em;"><span style="font-size: 18px;">“AI幻觉”指的是AI会生成看似合理但实际确实错误的信息,最常见的表现就是会编造一些不存在的事实或者细节。</span></p> <section> <br> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">造成“AI幻觉”的成因很多,例如:基于统计关系的预测;训练数据的局限性;过拟合问题,即因为记住了太多错误或者无关紧要的东西,从而让AI对训练数据中的噪声过于敏感;有限的上下文窗口;生成流畅回答的设计等等。</span> </section> <section style="text-indent: 2em;"> <br> </section> <p style="text-align: center;"><img class="rich_pages wxw-img" data-backh="962.822086" data-backw="576.822086" data-galleryid="" data-imgfileid="519447757" data-ratio="1.6685185185185185" data-s="300,640" src="/upload/fea8a81fcc7c90b756be23742fcb4f79.jpg" data-type="png" data-w="1080" style="letter-spacing: 0.578px;border-style: solid;border-width: 1px;width: 100%;height: auto;"></p> <section> <br> </section> <p style="text-indent: 2em;"><strong><span style="font-size: 18px;color: rgb(0, 122, 170);">那么,当AI会说谎,大家如何避免被“带偏”?</span></strong><strong><span style="font-size: 18px;text-indent: 2em;letter-spacing: 0.034em;color: rgb(0, 122, 170);">技术浪潮中,我们如何守护自己的思辨能力?</span></strong></p> <p style="text-indent: 2em;"><span style="font-size: 18px;"><br></span></p> <p style="text-indent: 2em;"><span style="font-size: 18px;">中国人民大学新闻学院教授卢家银指出,在知识建构上,AI生成的虚假学术成果,可能扭曲青年对科学方法论的理解,削弱其“假设-验证”的科研逻辑训练。在思维发展上,AI谣言通过算法推荐的“信息茧房”形成逻辑闭环,不利于批判性思维的培养。</span></p> <section style="text-indent: 2em;"> <br> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">北京师范大学教育学部教授、教育技术学北京市重点实验室副主任李艳燕建议,<strong><span style="color: rgb(0, 122, 170);">可以把AI看作一位平等对话的智者</span></strong>,通过引导与AI的对话互动,促进个体思维链的形成,并校准认知偏差。这种去权威化的思辨训练,可以帮助我们在与AI的对话中保持独立判断,实现认知跃迁。</span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;"><br></span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">北京邮电大学马克思主义学院副教授宋林泽认为,<strong><span style="color: rgb(0, 122, 170);">AI输出的内容只是一个认知起点,而不是终点</span></strong>。大学生需要主动去验证它的内容,比如查阅权威来源、对比不同观点,甚至直接与领域专家交流。这种验证过程,不仅能帮助我们更全面地理解问题,还能让我们在面对复杂信息时更有判断力。</span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;"><br></span> </section> <p style="text-align: center;"><img class="rich_pages wxw-img js_insertlocalimg" data-backh="434" data-backw="578" data-imgfileid="519447761" data-ratio="0.75" data-s="300,640" src="/upload/1a997f17f14940fde233cec9b3bfb2eb.jpg" data-type="jpeg" data-w="1080" style="width: 100%;height: auto;"></p> <section style="text-indent: 2em;"> <span style="font-size: 18px;"><br></span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">如何应对AI幻觉呢?</span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;"><br></span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">AI工具研究者田威提到,<strong><span style="color: rgb(0, 122, 170);">想要获得准确答案,提问方式很关键。</span></strong>与AI交流也需要明确和具体,避免模糊或开放性的问题,提问越具体、清晰,AI的回答越准确。</span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;"><br></span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">总结成提示词技巧就是下面四种问法:</span> </section> <section> <br> </section> <section data-mpa-template="t" mpa-from-tpl="t"> <section> <section data-style-type="2" data-tools="新媒体排版" data-id="9155" style="color: rgb(51, 51, 51);letter-spacing: 0.544px;" mpa-from-tpl="t"> <section powered-by="xiumi.us" mpa-from-tpl="t"> <section style="margin-top: 0.5em;margin-bottom: 0.5em;text-align: center;" mpa-from-tpl="t"> <section style="padding: 10px;border-width: 3px;border-style: solid;border-color: rgb(204, 204, 204);box-shadow: rgb(102, 102, 102) 2.82843px 2.82843px 7px;" mpa-from-tpl="t"> <section powered-by="xiumi.us" mpa-from-tpl="t"> <section mpa-from-tpl="t"> <section style="text-align: left;" mpa-from-tpl="t"> <section style="text-align: justify;text-indent: 2em;"> <strong><span style="font-size: 18px;letter-spacing: 0.578px;color: rgb(0, 122, 170);">1.设定边界</span></strong><span style="color: rgb(0, 0, 0);font-size: 18px;letter-spacing: 0.578px;">:“请严格限定在xx年xx期刊发表的研究范围内”;</span> </section> <section style="text-align: center;text-indent: 2em;"> <br> </section> </section> </section> </section> <section style="letter-spacing: 0.578px;text-align: justify;margin-bottom: 24px;text-indent: 2em;"> <span style="color: rgb(0, 0, 0);font-size: 18px;">示例:“介绍ChatGPT的发展历程”→“请仅基于OpenAI官方2022-2023年的公开文档,介绍ChatGPT的发展历程”</span><o:p></o:p> </section> <section style="letter-spacing: 0.578px;text-align: justify;margin-bottom: 24px;text-indent: 2em;"> <strong><span style="font-size: 18px;color: rgb(0, 122, 170);">2.标注不确定</span></strong><span style="color: rgb(0, 0, 0);font-size: 18px;">:“对于模糊信息,需要标注‘此处为推测内容’”;</span><o:p></o:p> </section> <section style="letter-spacing: 0.578px;text-align: justify;margin-bottom: 24px;text-indent: 2em;"> <span style="color: rgb(0, 0, 0);font-size: 18px;">示例:“分析特斯拉2025年的市场份额”→“分析特斯拉2025年的市场份额,对于非官方数据或预测性内容,请标注[推测内容]”</span><o:p></o:p> </section> <section style="letter-spacing: 0.578px;text-align: justify;margin-bottom: 24px;text-indent: 2em;"> <strong><span style="font-size: 18px;color: rgb(0, 122, 170);">3.步骤拆解</span></strong><span style="color: rgb(0, 0, 0);font-size: 18px;">:“第一步列举确定的事实依据,第二步展开详细分析”;</span><o:p></o:p> </section> <section style="letter-spacing: 0.578px;text-align: justify;margin-bottom: 24px;text-indent: 2em;"> <span style="color: rgb(0, 0, 0);font-size: 18px;">示例:“评估人工智能对就业的影响”→“请分两步评估AI对就业的影响:</span><o:p></o:p> </section> <section style="letter-spacing: 0.578px;text-align: justify;margin-bottom: 24px;text-indent: 2em;"> <span style="color: rgb(0, 0, 0);font-size: 18px;">1)先列出目前已发生的具体影响案例;</span><o:p></o:p> </section> <section style="letter-spacing: 0.578px;text-align: justify;margin-bottom: 24px;text-indent: 2em;"> <span style="color: rgb(0, 0, 0);font-size: 18px;">2)基于这些案例进行未来趋势分析”。</span><o:p></o:p> </section> <section style="letter-spacing: 0.578px;text-align: justify;margin-bottom: 24px;text-indent: 2em;"> <strong><span style="font-size: 18px;color: rgb(0, 122, 170);">4.明确约束</span></strong><span style="color: rgb(0, 0, 0);font-size: 18px;">:明确告诉AI要基于已有事实回答,不要进行推测。</span><o:p></o:p> </section> <p style="letter-spacing: 0.578px;text-align: justify;text-indent: 2em;margin-bottom: 0px;"><span style="color: rgb(0, 0, 0);font-size: 18px;">示例:“预测2025年房地产市场走势”→“请仅基于2024年的实际房地产数据和已出台的相关政策进行分析,不要加入任何推测性内容”。</span></p> </section> </section> </section> </section> </section> </section> <section data-mpa-template="t" mpa-from-tpl="t"> <section> <section style="text-indent: 2em;"> <span style="font-size: 18px;"><br></span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">针对如何获得准确答案,AI自己的答案是,可以通过指令约束、工具验证和人工审核三重保障,大幅降低AI虚构文献的风险。值得注意的是,<strong><span style="color: rgb(0, 122, 170);">“人工审核”被AI自己认为是“最后防线”</span></strong>。</span> </section> <section style="text-indent: 2em;"> <br> </section> <section> <img class="rich_pages wxw-img" data-backh="391.822086" data-backw="576.822086" data-galleryid="" data-imgfileid="519447760" data-ratio="0.6791277258566978" data-s="300,640" src="/upload/6517d97da6c3f98887fcd51bb40f4741.png" data-type="png" data-w="642" style="border-style: solid;border-width: 1px;width: 100%;height: auto;"> </section> <section style="text-indent: 2em;"> <br> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">专家提醒,“AI幻觉”并非没有好处,有时候与其把它当成缺陷,<span style="color: rgb(0, 122, 170);"><strong>不如把它看作创意的源泉</strong></span>。在写作、艺术创作或头脑风暴时,这些“跳跃性思维”反而可能帮我们打开新世界的大门。</span> </section> <p><br></p> </section> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">“AI幻觉”的本质是,AI在知识的迷雾中,有时会创造出看似真实,实则虚幻的“影子”。但就像任何工具一样,关键在于如何使用。</span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;"><br></span> </section> <section style="text-indent: 2em;"> <span style="font-size: 18px;">归根结底,在这个AI与人类共同进步的时代,<strong><span style="color: rgb(0, 122, 170);">重要的不是责备AI的不完美,而是学会与之更好地协作。</span></strong></span> </section>
作者:微信小助手
<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="margin-bottom: 0px;padding-left: 10px;padding-right: 10px;background-attachment: scroll;background-clip: border-box;background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 0%, rgba(0, 0, 0, 0) 6.76%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 0%, rgba(249, 247, 252, 0) 9.46%);background-origin: padding-box;background-position: 0% 0%;background-repeat: repeat, repeat;background-size: 20px 20px, 20px 20px;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;text-align: left; data-pm-slice="0 0 []"> <section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="padding-left: 3px;padding-right: 3px;background-attachment: scroll;background-clip: border-box;background-image: none;background-origin: padding-box;background-position: 0% 0%;background-repeat: no-repeat;background-size: auto;width: auto;font-family: PingFangSC-regular, sans-serif;line-height: 1.5em;word-spacing: 0em;letter-spacing: 0em;word-break: break-word;"> <figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><br></span> </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: 3px;padding-right: 3px;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: PingFangSC-regular, sans-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 []"> <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/92669e7a0436457d32c945ea1130081d.png" class="rich_pages wxw-img" data-ratio="0.6" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006382"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在当今信息爆炸的时代,如何从海量数据中快速准确地获取所需信息,是人工智能领域的一大挑战。Retrieval-Augmented Generation(RAG,检索增强生成)技术应运而生,它结合了检索和生成的优势,通过从大量文档中检索相关信息,再利用这些信息生成高质量的回答。然而,RAG 的实现方式多种多样,不同的技术路径有着不同的优势和局限。今天,我们就来深入探讨一下这些 RAG 技术,看看谁才是真正的“最佳选手”。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">1. Simple RAG:基础而不失经典</span></span><span style="display: none;"></span></h2> <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/eb4ffebdfc5ca69ff8685c64fea880a4.png" class="rich_pages wxw-img" data-ratio="0.33714285714285713" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006381"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在探索各种复杂的 RAG 技术之前,我们先从最简单的 RAG 方法说起。**简单 RAG **的工作流程非常直观:从 PDF 文档中提取文本,将其分割成小块(chunks),将这些文本块转换为数值化的嵌入向量(embeddings),根据查询(query)搜索最相关的文本块,最后利用检索到的文本块生成回答。</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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=""># 定义 PDF 文件路径</span></span><span leaf=""><br></span><span leaf="">pdf_path = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"data/AI_information.pdf"</span></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 leaf="">extracted_text = extract_text_from_pdf(pdf_path)</span><span leaf=""><br></span><span leaf="">text_chunks = chunk_text(extracted_text, chunk_size=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1000</span></span><span leaf="">, overlap=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">200</span></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 leaf="">print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Number of text chunks:"</span></span><span leaf="">, len(text_chunks))</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法虽然简单,但却为后续更复杂的技术奠定了基础。它就像是一个“新手村”,让我们能够初步了解 RAG 的工作原理。然而,简单 RAG 也有它的局限性。由于文本块是按照固定大小分割的,可能会导致一些句子被拆分开,或者将不相关的句子组合在一起,从而影响检索的准确性。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">2. Semantic Chunking语义分块:让文本块更有意义</span></span><span style="display: none;"></span></h2> <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/257fc429af0834315b95bc9b4a4412f7.png" class="rich_pages wxw-img" data-ratio="0.3842857142857143" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006380"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">为了解决简单 RAG 中文本块分割不够合理的问题,</span><strong style="color: rgb(239, 112, 96);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="">语义分块(Semantic Chunking)</span></strong><span leaf="">应运而生。与简单 RAG 不同,语义分块不再是按照固定大小来分割文本,而是尝试根据文本的语义来划分,将语义相关的句子组合在一起形成文本块。</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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 leaf="">sentences = extracted_text.split(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">". "</span></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 leaf="">embeddings = [get_embedding(sentence) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> sentence </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> sentences]</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 leaf="">similarities = [cosine_similarity(embeddings[i], embeddings[i + </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</span></span><span leaf="">]) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> i </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> range(len(embeddings) - </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</span></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 leaf="">breakpoints = compute_breakpoints(similarities, method=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"percentile"</span></span><span leaf="">, threshold=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">90</span></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 leaf="">text_chunks = split_into_chunks(sentences, breakpoints)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法听起来很完美,但在实际测试中,它的表现却不尽如人意。语义分块的评分甚至低于简单 RAG,这说明仅仅改变文本块的分割策略,并不能保证检索效果的提升。这也提醒我们,技术的改进并非一蹴而就,需要更多的思考和尝试。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;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> <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/d3fb570dca54bcbfc3060bc62cee0e05.png" class="rich_pages wxw-img" data-ratio="0.2985714285714286" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006379"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">既然语义分块没有达到预期的效果,我们不妨换个思路。简单 RAG 的问题在于文本块过于孤立,缺乏上下文信息。那么,如果我们能够为每个文本块添加一些上下文信息,是不是就能提高检索的准确性呢?</span><strong style="color: rgb(239, 112, 96);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="">上下文增强检索(Context Enriched Retrieval)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">context_enriched_search</span></span><span style="line-height: 26px;"><span leaf="">(query, text_chunks, embeddings, k=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</span></span><span leaf="">, context_size=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</span></span><span leaf="">)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> query_embedding = create_embeddings(query).data[</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">].embedding</span><span leaf=""><br></span><span leaf=""> similarity_scores = []</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> i, chunk_embedding </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> enumerate(embeddings):</span><span leaf=""><br></span><span leaf=""> similarity_score = cosine_similarity(np.array(query_embedding), np.array(chunk_embedding.embedding))</span><span leaf=""><br></span><span leaf=""> similarity_scores.append((i, similarity_score))</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> similarity_scores.sort(key=</span><span style="color: #c678dd;line-height: 26px;"><span leaf="">lambda</span></span><span leaf=""> x: x[</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</span></span><span leaf="">], reverse=</span><span style="color: #56b6c2;line-height: 26px;"><span leaf="">True</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> top_index = similarity_scores[</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">][</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">]</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> start = max(</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">, top_index - context_size)</span><span leaf=""><br></span><span leaf=""> end = min(len(text_chunks), top_index + context_size + </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> [text_chunks[i] </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> i </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> range(start, end)]</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在上下文增强检索中,我们不仅检索与查询最相关的文本块,还会检索其周围的文本块作为上下文信息。这些“邻居”文本块能够为检索提供更多的背景信息,帮助生成更准确的回答。经过测试,上下文增强检索的评分达到了 0.6,相较于简单 RAG 和语义分块有了显著的提升。这表明,上下文信息在检索过程中确实起到了关键作用。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;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> <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/60342a9ccdaae79f804d5568a2fcf27a.png" class="rich_pages wxw-img" data-ratio="0.24285714285714285" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006378"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">上下文增强检索虽然有效,但仍然存在一个问题:即使有了上下文信息,文本块本身可能仍然缺乏足够的语义信息。例如,一个文档可能包含多个主题,每个主题都对应着不同的文本块。在这种情况下,如何快速准确地找到与查询最相关的文本块呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">上下文块头(Contextual Chunk Headers)</span></strong><span leaf="">技术为我们提供了一个解决方案。它在每个文本块的前面添加了一个描述性的标题(header),这个标题就像是一个“标签”,能够概括文本块的主要内容。</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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 leaf="">text_chunks_with_headers = chunk_text_with_headers(extracted_text, chunk_size=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1000</span></span><span leaf="">, overlap=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">200</span></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 leaf="">print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Sample Chunk with Header:"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf="">print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Header:"</span></span><span leaf="">, text_chunks_with_headers[</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'header'</span></span><span leaf="">])</span><span leaf=""><br></span><span leaf="">print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Content:"</span></span><span leaf="">, text_chunks_with_headers[</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'text'</span></span><span leaf="">])</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在检索过程中,系统不仅会考虑文本块的内容,还会参考其标题,从而更准确地找到与查询相关的文本块。经过测试,上下文块头的评分达到了 0.5,虽然没有上下文增强检索高,但也比简单 RAG 和语义分块有了明显的提升。这说明,通过给文本块添加标题,我们能够为检索提供更多的语义信息,从而提高检索的准确性。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;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> <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/882d116dc45be0b2f072b1f49aa1efd6.png" class="rich_pages wxw-img" data-ratio="0.33285714285714285" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006383"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">上下文块头虽然能够提供更多的语义信息,但仍然存在局限性。在某些情况下,文本块的内容可能过于复杂,难以用一个简单的标题来概括。那么,有没有一种方法能够让文本块更容易被检索到呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">文档增强(Document Augmentation)技术为我们提供了一个新的思路。它不仅将文本块转换为嵌入向量,还会为每个文本块生成一些相关的问题,并将这些问题也转换为嵌入向量。</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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 leaf="">text_chunks, vector_store = process_document(</span><span leaf=""><br></span><span leaf=""> pdf_path,</span><span leaf=""><br></span><span leaf=""> chunk_size=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1000</span></span><span leaf="">,</span><span leaf=""><br></span><span leaf=""> chunk_overlap=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">200</span></span><span leaf="">,</span><span leaf=""><br></span><span leaf=""> questions_per_chunk=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">3</span></span><span leaf=""><br></span><span leaf="">)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这样一来,在检索过程中,系统不仅能够匹配文本块的内容,还能够匹配与查询相关的问题,从而提高检索的准确性。经过测试,文档增强的评分达到了 0.8,这是一个非常高的分数,表明文档增强技术能够显著提高检索的准确性。这也说明,通过为文本块生成相关问题,我们能够为检索提供更多的入口,从而更容易找到与查询相关的文本块。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">6. 查询转换:让查询更“友好”</span></span><span style="display: none;"></span></h2> <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/c50e221d17087dce22c9aab59c41bbaa.png" class="rich_pages wxw-img" data-ratio="0.39571428571428574" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006385"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略。然而,我们忽略了一个重要的因素:用户提出的查询可能并不总是能够很好地匹配文档中的内容,这可能会导致检索结果不准确。那么,有没有一种方法能够让查询更“友好”,更容易被检索到呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">查询转换(Query Transformation)</span></strong><span leaf="">技术为我们提供了一个解决方案。它通过三种不同的方法来改进查询:查询重写(Query Rewriting)、后退提示(Step-back Prompting)和子查询分解(Sub-query Decomposition)。</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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 leaf="">rewritten_query = rewrite_query(query)</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 leaf="">step_back_query = generate_step_back_query(query)</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 leaf="">sub_queries = decompose_query(query, num_subqueries=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">4</span></span><span leaf="">)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">查询重写是将查询变得更加具体和详细;后退提示是创建一个更广泛的查询,以检索有用的背景信息;子查询分解则是将一个复杂的查询分解为多个简单的子查询。经过测试,查询转换的评分达到了 0.5。虽然这个分数并不高,但它仍然表明查询转换技术在某些情况下能够提高检索的准确性。这也提醒我们,在 RAG 系统中,不仅需要关注文本块的表示和检索策略,还需要关注查询的质量。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;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> <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/b1549b8b3df0dc7398cc23cc3ca35bf5.png" class="rich_pages wxw-img" data-ratio="0.2957142857142857" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006386"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量。然而,我们忽略了一个重要的环节:检索结果的排序。简单相似性搜索通常会返回一组相关性和不相关性混杂的结果,这可能会导致生成的回答不够准确。那么,有没有一种方法能够让检索结果更有条理,更容易被利用呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">重排序(Reranker)</span></strong><span leaf="">技术为我们提供了一个解决方案。它在初始检索的基础上,通过一个额外的步骤对检索结果进行重新排序,将最相关的文本块放在最前面。重排序可以使用不同的方法,例如基于关键词的重排序或基于 LLM 的重排序。</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">rag_with_reranking</span></span><span style="line-height: 26px;"><span leaf="">(query, vector_store, reranking_method=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"llm"</span></span><span leaf="">, top_n=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">3</span></span><span leaf="">, model=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"meta-llama/Llama-3.2-3B-Instruct"</span></span><span leaf="">)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> query_embedding = create_embeddings(query)</span><span leaf=""><br></span><span leaf=""> initial_results = vector_store.similarity_search(query_embedding, k=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">10</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> reranking_method == </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"llm"</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> reranked_results = rerank_with_llm(query, initial_results, top_n=top_n)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">else</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> reranked_results = initial_results[:top_n]</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> context = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"\n\n===\n\n"</span></span><span leaf="">.join([result[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"text"</span></span><span leaf="">] </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> result </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> reranked_results])</span><span leaf=""><br></span><span leaf=""> response = generate_response(query, context, model)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"query"</span></span><span leaf="">: query,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"reranking_method"</span></span><span leaf="">: reranking_method,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"initial_results"</span></span><span leaf="">: initial_results[:top_n],</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"reranked_results"</span></span><span leaf="">: reranked_results,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"context"</span></span><span leaf="">: context,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"response"</span></span><span leaf="">: response</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法的效果如何呢?经过测试,重排序的评分达到了 0.7。这个分数表明,重排序技术能够显著提高检索结果的质量,从而提高生成回答的准确性。这也说明,对检索结果进行重新排序是一个非常重要的步骤,能够帮助我们更好地利用检索到的信息。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">8. 相关段落提取(RSE):寻找连续的相关文本</span></span><span style="display: none;"></span></h2> <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/dbcb9c17b4b49d888e7ce87cef82bcd5.png" class="rich_pages wxw-img" data-ratio="0.26857142857142857" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006387"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序。然而,我们忽略了一个重要的问题:有时候,最佳的信息可能分散在多个连续的文本块中。那么,有没有一种方法能够让系统自动识别并提取这些连续的相关文本呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">相关段落提取(Relevant Segment Extraction,RSE)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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=""># 运行 RAG 并应用相关段落提取</span></span><span leaf=""><br></span><span leaf="">rse_result = rag_with_rse(pdf_path, query)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法能够为生成回答提供更连贯和完整的上下文信息,从而提高回答的质量。经过测试,相关段落提取的评分达到了 0.8。这个分数表明,相关段落提取技术能够显著提高检索结果的质量,从而提高生成回答的准确性。这也说明,识别并提取连续的相关文本是一个非常重要的步骤,能够帮助我们更好地利用检索到的信息。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;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> <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/43316efaee43bec113d5124d2034e0f8.png" class="rich_pages wxw-img" data-ratio="0.2957142857142857" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006384"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本。然而,我们忽略了一个重要的问题:有时候,检索到的信息可能过于冗长,包含了大量与查询不相关的内容。这不仅会浪费计算资源,还可能会影响生成回答的质量。那么,有没有一种方法能够让检索到的信息更精炼,只保留与查询最相关的内容呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">上下文压缩(Contextual Compression)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">rag_with_compression</span></span><span style="line-height: 26px;"><span leaf="">(pdf_path, query, k=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">10</span></span><span leaf="">, compression_type=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"selective"</span></span><span leaf="">, model=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"meta-llama/Llama-3.2-3B-Instruct"</span></span><span leaf="">)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> vector_store = process_document(pdf_path)</span><span leaf=""><br></span><span leaf=""> results = vector_store.similarity_search(create_embeddings(query), k=k)</span><span leaf=""><br></span><span leaf=""> retrieved_chunks = [r[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"text"</span></span><span leaf="">] </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> r </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> results]</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> compressed = batch_compress_chunks(retrieved_chunks, query, compression_type, model)</span><span leaf=""><br></span><span leaf=""> compressed_chunks, compression_ratios = zip([(c, r) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> c, r </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> compressed </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> c.strip()] </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">or</span></span><span leaf=""> [(chunk, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0.0</span></span><span leaf="">) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> chunk </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> retrieved_chunks])</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> context = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"\n\n---\n\n"</span></span><span leaf="">.join(compressed_chunks)</span><span leaf=""><br></span><span leaf=""> response = generate_response(query, context, model)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"query"</span></span><span leaf="">: query,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"original_chunks"</span></span><span leaf="">: retrieved_chunks,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"compressed_chunks"</span></span><span leaf="">: compressed_chunks,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"compression_ratios"</span></span><span leaf="">: compression_ratios,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"context_length_reduction"</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"</span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{sum(compression_ratios)/len(compression_ratios):</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">.2</span></span><span leaf="">f}</span></span><span leaf="">%"</span></span><span leaf="">,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"response"</span></span><span leaf="">: response</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法的效果如何呢?经过测试,上下文压缩的评分达到了 0.75。这个分数表明,上下文压缩技术能够显著提高检索结果的质量,从而提高生成回答的准确性。这也说明,对检索到的信息进行压缩是一个非常重要的步骤,能够帮助我们更好地利用检索到的信息。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;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> <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/0c26df49063e39b6616622fac3934d20.png" class="rich_pages wxw-img" data-ratio="0.3271428571428571" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006389"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本,以及如何对检索到的信息进行压缩。然而,我们忽略了一个重要的问题:这些改进都是基于预先设定的策略,系统无法根据实际的使用情况进行自我调整。那么,有没有一种方法能够让系统根据用户的反馈不断学习和调整呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">反馈循环(Feedback Loop)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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=""># 定义完整的 RAG 流程,包含反馈机制</span></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">full_rag_workflow</span></span><span style="line-height: 26px;"><span leaf="">(pdf_path, query, feedback_data=None, feedback_file=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"feedback_data.json"</span></span><span leaf="">, fine_tune=False)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> feedback_data </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">is</span></span><span style="color: #56b6c2;line-height: 26px;"><span leaf="">None</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> feedback_data = load_feedback_data(feedback_file)</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"Loaded </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{len(feedback_data)}</span></span><span leaf=""> feedback entries from </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{feedback_file}</span></span><span leaf="">"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> chunks, vector_store = process_document(pdf_path)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> fine_tune </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">and</span></span><span leaf=""> feedback_data:</span><span leaf=""><br></span><span leaf=""> vector_store = fine_tune_index(vector_store, chunks, feedback_data)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> result = rag_with_feedback_loop(query, vector_store, feedback_data)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"\n=== Would you like to provide feedback on this response? ==="</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Rate relevance (1-5, with 5 being most relevant):"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> relevance = input()</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Rate quality (1-5, with 5 being highest quality):"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> quality = input()</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Any comments? (optional, press Enter to skip)"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> comments = input()</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> feedback = get_user_feedback(</span><span leaf=""><br></span><span leaf=""> query=query,</span><span leaf=""><br></span><span leaf=""> response=result[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"response"</span></span><span leaf="">],</span><span leaf=""><br></span><span leaf=""> relevance=int(relevance),</span><span leaf=""><br></span><span leaf=""> quality=int(quality),</span><span leaf=""><br></span><span leaf=""> comments=comments</span><span leaf=""><br></span><span leaf=""> )</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> store_feedback(feedback, feedback_file)</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Feedback recorded. Thank you!"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> result</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法的效果如何呢?经过测试,反馈循环的评分达到了 0.7。虽然这个分数并不高,但它仍然表明反馈循环技术能够让系统不断学习和调整,从而提高检索结果的质量。这也说明,用户反馈是一个非常重要的资源,能够帮助系统更好地满足用户的需求。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">11. Adaptive RAG:智能选择检索策略</span></span><span style="display: none;"></span></h2> <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/a96661311c6fe3c024702551348dae9b.png" class="rich_pages wxw-img" data-ratio="0.58" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006391"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本,以及如何对检索到的信息进行压缩,以及如何根据用户的反馈不断学习和调整。然而,我们忽略了一个重要的问题:不同的查询可能需要不同的检索策略。那么,有没有一种方法能够让系统根据查询的类型自动选择最合适的检索策略呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">自适应 RAG(Adaptive RAG)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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=""># 定义自适应 RAG 函数</span></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">rag_with_adaptive_retrieval</span></span><span style="line-height: 26px;"><span leaf="">(pdf_path, query, k=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">4</span></span><span leaf="">, user_context=None)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> chunks, vector_store = process_document(pdf_path)</span><span leaf=""><br></span><span leaf=""> query_type = classify_query(query)</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"Query classified as: </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{query_type}</span></span><span leaf="">"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> retrieved_docs = adaptive_retrieval(query, vector_store, k, user_context)</span><span leaf=""><br></span><span leaf=""> response = generate_response(query, retrieved_docs, query_type)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"query"</span></span><span leaf="">: query,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"query_type"</span></span><span leaf="">: query_type,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"retrieved_documents"</span></span><span leaf="">: retrieved_docs,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"response"</span></span><span leaf="">: response</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法的效果如何呢?经过测试,自适应 RAG 的评分达到了 0.86,这是所有方法中最高的分数。这个分数表明,自适应 RAG 技术能够显著提高检索结果的质量,从而提高生成回答的准确性。这也说明,根据查询的类型自动选择检索策略是一个非常重要的步骤,能够帮助我们更好地利用检索到的信息。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">12. Self RAG:让系统自我反思</span></span><span style="display: none;"></span></h2> <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/5aa021b0cf568fc88dd4f1b6e216e697.png" class="rich_pages wxw-img" data-ratio="0.23857142857142857" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006390"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本,以及如何对检索到的信息进行压缩,以及如何根据用户的反馈不断学习和调整,以及如何根据查询的类型自动选择检索策略。然而,我们忽略了一个重要的问题:系统是否能够自我反思,判断是否需要检索,以及如何利用检索到的信息呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">自我 RAG(Self RAG)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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=""># 运行自我 RAG</span></span><span leaf=""><br></span><span leaf="">result = self_rag(query, vector_store)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法的效果如何呢?经过测试,自我 RAG 的评分达到了 0.65。虽然这个分数并不高,但它仍然表明自我 RAG 技术能够让系统更加智能和灵活。这也说明,自我反思是一个非常重要的能力,能够帮助系统更好地适应不同的查询需求。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">13. Knowledge Graph:构建知识网络</span></span><span style="display: none;"></span></h2> <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/dcdb4e989849cb304b701a82c1433dd3.png" class="rich_pages wxw-img" data-ratio="0.4442857142857143" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006388"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本,以及如何对检索到的信息进行压缩,以及如何根据用户的反馈不断学习和调整,以及如何根据查询的类型自动选择检索策略,以及如何让系统自我反思。然而,我们忽略了一个重要的问题:文档中的信息可能是相互关联的,如何构建一个知识网络,将这些信息有机地结合起来呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">知识图谱 RAG(Knowledge Graph RAG)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">build_knowledge_graph</span></span><span style="line-height: 26px;"><span leaf="">(chunks)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> graph, texts = nx.Graph(), [c[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"text"</span></span><span leaf="">] </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> c </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> chunks]</span><span leaf=""><br></span><span leaf=""> embeddings = create_embeddings(texts)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> i, (chunk, emb) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> enumerate(zip(chunks, embeddings)):</span><span leaf=""><br></span><span leaf=""> graph.add_node(i, text=chunk[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"text"</span></span><span leaf="">], concepts=extract_concepts(chunk[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"text"</span></span><span leaf="">]), embedding=emb)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> i, j </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> ((i, j) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> i </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> range(len(chunks)) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> j </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> range(i + </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</span></span><span leaf="">, len(chunks))):</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> shared_concepts := set(graph.nodes[i][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"concepts"</span></span><span leaf="">]) & set(graph.nodes[j][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"concepts"</span></span><span leaf="">]):</span><span leaf=""><br></span><span leaf=""> sim = np.dot(embeddings[i], embeddings[j]) / (np.linalg.norm(embeddings[i]) * np.linalg.norm(embeddings[j]))</span><span leaf=""><br></span><span leaf=""> weight = </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0.7</span></span><span leaf=""> * sim + </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0.3</span></span><span leaf=""> * (len(shared_concepts) / min(len(graph.nodes[i][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"concepts"</span></span><span leaf="">]), len(graph.nodes[j][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"concepts"</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=""> weight > </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0.6</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> graph.add_edge(i, j, weight=weight, similarity=sim, shared_concepts=list(shared_concepts))</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"Graph built: </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{graph.number_of_nodes()}</span></span><span leaf=""> nodes, </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{graph.number_of_edges()}</span></span><span leaf=""> edges"</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=""> graph, embeddings</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在检索过程中,系统不仅能够检索与查询直接相关的节点,还能够通过遍历知识图谱找到间接相关的节点,从而为生成回答提供更全面的上下文信息。经过测试,知识图谱 RAG 的评分达到了 0.78。这个分数表明,知识图谱 RAG 技术能够显著提高检索结果的质量,从而提高生成回答的准确性。这也说明,构建知识图谱是一个非常重要的步骤,能够帮助我们更好地利用文档中的信息。</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/a173c42435d8321bab493377c55697b3.png" class="rich_pages wxw-img" data-ratio="0.8314285714285714" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006392"></span> </figure> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">14. 层次化索引:平衡上下文和精确性</span></span><span style="display: none;"></span></h2> <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/42af1c2e6e43a1f7c493466c7727291b.png" class="rich_pages wxw-img" data-ratio="0.3314285714285714" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006395"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本,以及如何对检索到的信息进行压缩,以及如何根据用户的反馈不断学习和调整,以及如何根据查询的类型自动选择检索策略,以及如何让系统自我反思,以及如何构建知识图谱。然而,我们忽略了一个重要的问题:如何平衡上下文信息和检索的精确性呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">层次化索引(Hierarchical Indices)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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=""># 定义层次化 RAG 函数</span></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">hierarchical_rag</span></span><span style="line-height: 26px;"><span leaf="">(query, pdf_path, chunk_size=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1000</span></span><span leaf="">, chunk_overlap=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">200</span></span><span leaf="">, k_summaries=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">3</span></span><span leaf="">, k_chunks=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">5</span></span><span leaf="">, regenerate=False)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> summary_store_file = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"</span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{os.path.basename(pdf_path)}</span></span><span leaf="">_summary_store.pkl"</span></span><span leaf=""><br></span><span leaf=""> detailed_store_file = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"</span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{os.path.basename(pdf_path)}</span></span><span leaf="">_detailed_store.pkl"</span></span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> regenerate </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">or</span></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">not</span></span><span leaf=""> os.path.exists(summary_store_file) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">or</span></span><span style="color: #c678dd;line-height: 26px;"><span leaf="">not</span></span><span leaf=""> os.path.exists(detailed_store_file):</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Processing document and creating vector stores..."</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> summary_store, detailed_store = process_document_hierarchically(pdf_path, chunk_size, chunk_overlap)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">with</span></span><span leaf=""> open(summary_store_file, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'wb'</span></span><span leaf="">) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">as</span></span><span leaf=""> f:</span><span leaf=""><br></span><span leaf=""> pickle.dump(summary_store, f)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">with</span></span><span leaf=""> open(detailed_store_file, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'wb'</span></span><span leaf="">) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">as</span></span><span leaf=""> f:</span><span leaf=""><br></span><span leaf=""> pickle.dump(detailed_store, f)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">else</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Loading existing vector stores..."</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">with</span></span><span leaf=""> open(summary_store_file, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'rb'</span></span><span leaf="">) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">as</span></span><span leaf=""> f:</span><span leaf=""><br></span><span leaf=""> summary_store = pickle.load(f)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">with</span></span><span leaf=""> open(detailed_store_file, </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'rb'</span></span><span leaf="">) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">as</span></span><span leaf=""> f:</span><span leaf=""><br></span><span leaf=""> detailed_store = pickle.load(f)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> retrieved_chunks = retrieve_hierarchically(query, summary_store, detailed_store, k_summaries, k_chunks)</span><span leaf=""><br></span><span leaf=""> response = generate_response(query, retrieved_chunks)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"query"</span></span><span leaf="">: query,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"response"</span></span><span leaf="">: response,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"retrieved_chunks"</span></span><span leaf="">: retrieved_chunks,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"summary_count"</span></span><span leaf="">: len(summary_store.texts),</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"detailed_count"</span></span><span leaf="">: len(detailed_store.texts)</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法既保留了上下文信息,又提高了检索的精确性。经过测试,层次化索引的评分达到了 0.84。这个分数表明,层次化索引技术能够显著提高检索结果的质量,从而提高生成回答的准确性。这也说明,平衡上下文信息和检索精确性是一个非常重要的步骤,能够帮助我们更好地利用检索到的信息。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">15. HyDE:从假设文档出发</span></span><span style="display: none;"></span></h2> <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/3bc7dc98dbade013dad27c07d74d8d44.png" class="rich_pages wxw-img" data-ratio="0.29" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006396"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本,以及如何对检索到的信息进行压缩,以及如何根据用户的反馈不断学习和调整,以及如何根据查询的类型自动选择检索策略,以及如何让系统自我反思,以及如何构建知识图谱,以及如何平衡上下文信息和检索精确性。然而,我们忽略了一个重要的问题:如何更好地表示查询,以便更准确地检索到相关信息呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">HyDE(Hypothetical Document Embedding)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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=""># 定义 HyDE RAG 函数</span></span><span leaf=""><br></span><span style="line-height: 26px;"><span style="color: #c678dd;line-height: 26px;"><span leaf="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">hyde_rag</span></span><span style="line-height: 26px;"><span leaf="">(query, vector_store, k=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">5</span></span><span leaf="">, should_generate_response=True)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"\n=== Processing query with HyDE: </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{query}</span></span><span leaf=""> ===\n"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Generating hypothetical document..."</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> hypothetical_doc = generate_hypothetical_document(query)</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"Generated hypothetical document of </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{len(hypothetical_doc)}</span></span><span leaf=""> characters"</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Creating embedding for hypothetical document..."</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> hypothetical_embedding = create_embeddings([hypothetical_doc])[</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">]</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"Retrieving </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{k}</span></span><span leaf=""> most similar chunks..."</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> retrieved_chunks = vector_store.similarity_search(hypothetical_embedding, k=k)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> results = {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"query"</span></span><span leaf="">: query,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"hypothetical_document"</span></span><span leaf="">: hypothetical_doc,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"retrieved_chunks"</span></span><span leaf="">: retrieved_chunks</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> should_generate_response:</span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Generating final response..."</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> response = generate_response(query, retrieved_chunks)</span><span leaf=""><br></span><span leaf=""> results[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"response"</span></span><span leaf="">] = response</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> results</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法能够更好地捕捉查询的语义信息,从而提高检索的准确性。经过测试,HyDE 的评分达到了 0.5。虽然这个分数并不高,但它仍然表明 HyDE 技术在某些情况下能够提高检索的准确性。这也说明,从假设文档出发是一个非常有趣的思路,能够帮助我们更好地表示查询。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">16. 融合 RAG:结合多种检索方法</span></span><span style="display: none;"></span></h2> <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/fcb36af1fc6d0c0c5f3aeabfb154551a.png" class="rich_pages wxw-img" data-ratio="0.22" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006397"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本,以及如何对检索到的信息进行压缩,以及如何根据用户的反馈不断学习和调整,以及如何根据查询的类型自动选择检索策略,以及如何让系统自我反思,以及如何构建知识图谱,以及如何平衡上下文信息和检索精确性,以及如何从假设文档出发。然而,我们忽略了一个重要的问题:不同的检索方法有各自的优缺点,如何将它们结合起来,发挥各自的优点呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">融合 RAG(Fusion RAG)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">fusion_retrieval</span></span><span style="line-height: 26px;"><span leaf="">(query, chunks, vector_store, bm25_index, k=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">5</span></span><span leaf="">, alpha=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0.5</span></span><span leaf="">)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> query_embedding = create_embeddings(query)</span><span leaf=""><br></span><span leaf=""> vector_results = {r[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"metadata"</span></span><span leaf="">][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"index"</span></span><span leaf="">]: r[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"similarity"</span></span><span leaf="">] </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> r </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> vector_store.similarity_search_with_scores(query_embedding, len(chunks))}</span><span leaf=""><br></span><span leaf=""> bm25_results = {r[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"metadata"</span></span><span leaf="">][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"index"</span></span><span leaf="">]: r[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"bm25_score"</span></span><span leaf="">] </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> r </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> bm25_search(bm25_index, chunks, query, len(chunks))}</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> all_docs = vector_store.get_all_documents()</span><span leaf=""><br></span><span leaf=""> scores = [(i, alpha * vector_results.get(i, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">) + (</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</span></span><span leaf=""> - alpha) * bm25_results.get(i, </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">0</span></span><span leaf="">)) </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> i </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> range(len(all_docs))]</span><span leaf=""><br></span><span leaf=""> top_docs = sorted(scores, key=</span><span style="color: #c678dd;line-height: 26px;"><span leaf="">lambda</span></span><span leaf=""> x: x[</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1</span></span><span leaf="">], reverse=</span><span style="color: #56b6c2;line-height: 26px;"><span leaf="">True</span></span><span leaf="">)[:k]</span><span leaf=""><br></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: #98c379;line-height: 26px;"><span leaf="">"text"</span></span><span leaf="">: all_docs[i][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"text"</span></span><span leaf="">], </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"metadata"</span></span><span leaf="">: all_docs[i][</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"metadata"</span></span><span leaf="">], </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"score"</span></span><span leaf="">: s} </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> i, s </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> top_docs]</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法能够更好地满足不同查询的需求,提高检索的准确性。经过测试,融合 RAG 的评分达到了 0.83。这个分数表明,融合 RAG 技术能够显著提高检索结果的质量,从而提高生成回答的准确性。这也说明,结合多种检索方法是一个非常有效的策略,能够帮助我们更好地利用检索到的信息。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">17. 多模态RAG:解锁图像信息</span></span><span style="display: none;"></span></h2> <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/4d821ac017ec79184f47d21cee888cf4.png" class="rich_pages wxw-img" data-ratio="0.31142857142857144" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006394"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本,以及如何对检索到的信息进行压缩,以及如何根据用户的反馈不断学习和调整,以及如何根据查询的类型自动选择检索策略,以及如何让系统自我反思,以及如何构建知识图谱,以及如何平衡上下文信息和检索精确性,以及如何从假设文档出发,以及如何结合多种检索方法。然而,我们忽略了一个重要的问题:文档中的信息不仅包含文本,还可能包含图像、图表等其他形式的信息,如何将这些信息也纳入检索范围呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">多模态 RAG(Multi Model RAG)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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="">def</span></span><span leaf=""> </span><span style="color: #61aeee;line-height: 26px;"><span leaf="">process_document</span></span><span style="line-height: 26px;"><span leaf="">(pdf_path, chunk_size=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">1000</span></span><span leaf="">, chunk_overlap=</span><span style="color: #d19a66;line-height: 26px;"><span leaf="">200</span></span><span leaf="">)</span></span><span leaf="">:</span></span><span leaf=""><br></span><span leaf=""> image_dir = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"extracted_images"</span></span><span leaf=""><br></span><span leaf=""> os.makedirs(image_dir, exist_ok=</span><span style="color: #56b6c2;line-height: 26px;"><span leaf="">True</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> text_data, image_paths = extract_content_from_pdf(pdf_path, image_dir)</span><span leaf=""><br></span><span leaf=""> chunked_text = chunk_text(text_data, chunk_size, chunk_overlap)</span><span leaf=""><br></span><span leaf=""> image_data = process_images(image_paths)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> all_items = chunked_text + image_data</span><span leaf=""><br></span><span leaf=""> contents = [item[</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"content"</span></span><span leaf="">] </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">for</span></span><span leaf=""> item </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">in</span></span><span leaf=""> all_items]</span><span leaf=""><br></span><span leaf=""> embeddings = create_embeddings(contents)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> vector_store = MultiModalVectorStore()</span><span leaf=""><br></span><span leaf=""> vector_store.add_items(all_items, embeddings)</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> doc_info = {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"text_count"</span></span><span leaf="">: len(chunked_text),</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"image_count"</span></span><span leaf="">: len(image_data),</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"total_items"</span></span><span leaf="">: len(all_items),</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> print(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">f"Added </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{len(all_items)}</span></span><span leaf=""> items to vector store (</span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{len(chunked_text)}</span></span><span leaf=""> text chunks, </span><span style="color: #e06c75;line-height: 26px;"><span leaf="">{len(image_data)}</span></span><span leaf=""> image captions)"</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=""> vector_store, doc_info</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法能够更好地利用文档中的信息,提高检索的准确性。经过测试,多模态 RAG 的评分达到了 0.79。这个分数表明,多模态 RAG 技术能够显著提高检索结果的质量,从而提高生成回答的准确性。这也说明,将图像信息纳入检索范围是一个非常重要的步骤,能够帮助我们更好地利用文档中的信息。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">18. CRAG:动态调整检索策略</span></span><span style="display: none;"></span></h2> <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/133b7bd5cfbdd01cb059378d5497d935.png" class="rich_pages wxw-img" data-ratio="0.28714285714285714" data-type="png" data-w="700" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006398"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在前面的讨论中,我们主要关注了如何改进文本块的表示和检索策略,以及如何改进查询的质量和检索结果的排序,以及如何识别并提取连续的相关文本,以及如何对检索到的信息进行压缩,以及如何根据用户的反馈不断学习和调整,以及如何根据查询的类型自动选择检索策略,以及如何让系统自我反思,以及如何构建知识图谱,以及如何平衡上下文信息和检索精确性,以及如何从假设文档出发,以及如何结合多种检索方法,以及如何将图像信息纳入检索范围。然而,我们忽略了一个重要的问题:检索到的信息可能并不总是理想的,如何动态调整检索策略,以应对不同的情况呢?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">纠正性 RAG(Corrective RAG,CRAG)</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 ijdpq631cvfpzevp7c96gnruqn0u3fiancwzhdxoqs1pvknfalxbssriccrluvnayrvtcp9zwfopqiaotazjtnke4qtwezjoiczs 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=""># 运行纠正性 RAG</span></span><span leaf=""><br></span><span leaf="">crag_result = rag_with_compression(pdf_path, query, compression_type=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"selective"</span></span><span leaf="">)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这种方法能够更好地应对不同的情况,提高检索的准确性和可靠性。经过测试,纠正性 RAG 的评分达到了 0.824。这个分数表明,纠正性 RAG 技术能够显著提高检索结果的质量,从而提高生成回答的准确性。这也说明,动态调整检索策略是一个非常重要的步骤,能够帮助我们更好地利用检索到的信息。</span></p> <h2 data-tool="mdnice编辑器" style="background-color: rgb(251, 251, 251);margin-top: 50px;margin-bottom: 20px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 20px;color: rgb(255, 255, 255);background-color: rgb(33, 33, 34);line-height: 1.5em;letter-spacing: 0em;padding-top: 8px;padding-bottom: 8px;padding-left: 15px;padding-right: 30px;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: 40px;align-items: unset;background-attachment: scroll;background-clip: border-box;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: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">结论:选择最适合的 RAG 技术</span></span><span style="display: none;"></span></h2> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">通过上述对 18 种 RAG 技术的测试和分析,我们可以看到,不同的技术有各自的优缺点,适用于不同的场景和需求。简单 RAG 提供了一个基础的框架,但其检索效果有限;语义分块、上下文增强检索、上下文块头、文档增强等技术通过改进文本块的表示和检索策略,提高了检索的准确性;查询转换、重排序、相关段落提取、上下文压缩等技术通过改进查询的质量和检索结果的排序,进一步提高了检索的效果;反馈循环、自适应 RAG、自我 RAG 等技术通过引入反馈机制和动态调整检索策略,让系统能够更好地适应不同的查询需求;知识图谱 RAG、层次化索引、HyDE、融合 RAG、多模态 RAG、纠正性 RAG 等技术通过结合多种方法和信息源,显著提高了检索的准确性和可靠性。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在这些技术中,自适应 RAG 以 0.86 的评分脱颖而出,成为表现最佳的 RAG 技术。它通过根据查询的类型自动选择最合适的检索策略,能够更好地满足不同用户的需求,生成更准确的回答。然而,这并不意味着其他技术没有价值。实际上,不同的技术可以在不同的场景下发挥重要作用,关键在于根据具体的需求和场景选择最适合的技术。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">未来,随着人工智能技术的不断发展,RAG 技术也将不断进化。我们可以预见,结合多种技术的优点,开发出更加智能、高效、可靠的 RAG 系统,将为信息检索和自然语言处理领域带来更多的可能性和突破。</span></p> <hr 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;border-top-style: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;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: 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: 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: 1px;"> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">以上就是对 18 种 RAG 技术的详细分析和代码示例。希望这篇文章能够帮助你更好地了解 RAG 技术的多样性和潜力。如果你对某一种技术特别感兴趣,或者有其他问题,欢迎在评论区留言,我们一起探讨!</span></p> </section> </section> </section>
作者:微信小助手
<section style="text-indent: 2em;"> <span data-pm-slice="0 0 []"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal; data-pm-slice="1 1 [" para,{tagname:section,attributes:{},namespaceuri:},node,{tagname:span,attributes:{data-pm-slice:0 0 [],style:null},namespaceuri:http: www.w3.org 1999 xhtml}]><span textstyle="" style="font-size: 16px;">上周,百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。</span><span textstyle="" style="font-size: 16px;background-color: #fffb00;">目前提供的MCP工具列表包含8个核心API接口和MCP协议的对接, 涵盖逆地理编码、地点检索、路线规划等</span><span textstyle="" style="font-size: 16px;">。</span></span></span> </section> <section style="text-align: center;" nodeleaf=""> <img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100000799" data-ratio="0.937962962962963" data-s="300,640" src="/upload/7b5201b2f25366bd07b61d8b8e750d5d.png" data-type="png" data-w="1080" type="block"> </section> <section style="text-indent: 2em;"> <span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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;">我们来实践一下,怎么使用</span></span><span data-pm-slice="0 0 []"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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;">百度地图MCP Server。</span></span></span> </section> <section> <span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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;">一.在百度地图开放平台的控制台中创建一个服务端AK</span></span> </section> <section> <span leaf="" data-pm-slice="1 1 [" para,null] style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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;">通过AK你才能够调用百度地图API能力</span></span> </section> <section style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal; nodeleaf=""> <img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100000795" data-ratio="0.48333333333333334" data-s="300,640" src="/upload/9741e5eaef17186dd9df761341aad1d1.png" data-type="png" data-w="1080" type="block"> </section> <section> <span leaf="" data-pm-slice="1 1 [" para,null] style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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;">二.打开 windsurf编辑器</span></span> </section> <section style="text-indent: 2em;"> <span data-pm-slice="0 0 []"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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;">将以下配置添加到配置文件中,BAIDU_MAP_API_KEY 是访问百度地图开放平台API的AK。</span></span></span> </section> <section style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal; nodeleaf=""> <img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100000796" data-ratio="0.5712962962962963" data-s="300,640" src="/upload/888e4ec2ecf37542301a478f11e8d768.jpg" data-type="jpeg" data-w="1080" type="block"> </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="perl"><code><span leaf="">{</span></code><code><span leaf=""> <span class="code-snippet__string">"mcpServers"</span>: {</span></code><code><span leaf=""> <span class="code-snippet__string">"baidu-map"</span>: {</span></code><code><span leaf=""> <span class="code-snippet__string">"command"</span>: <span class="code-snippet__string">"npx"</span>,</span></code><code><span leaf=""> <span class="code-snippet__string">"args"</span>: [</span></code><code><span leaf=""> <span class="code-snippet__string">"-y"</span>,</span></code><code><span leaf=""> <span class="code-snippet__string">"@baidumap/mcp-server-baidu-map"</span></span></code><code><span leaf=""> ],</span></code><code><span leaf=""> <span class="code-snippet__string">"env"</span>: {</span></code><code><span leaf=""> <span class="code-snippet__string">"BAIDU_MAP_API_KEY"</span>: <span class="code-snippet__string">"xxx"</span></span></code><code><span leaf=""> }</span></code><code><span leaf=""> }</span></code><code><span leaf=""> }</span></code><code><span leaf="">}</span></code></pre> </section> <section style="text-indent: 2em;"> <span data-pm-slice="0 0 []"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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;">重启windsurf,此时设置面板已经成功加载了百度地图MCP Server。</span></span><span data-pm-slice="0 0 []"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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;">可以看到有8个可用的MCP工具,点击可以查看详情。</span></span></span></span> </section> <section style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal; nodeleaf=""> <img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100000797" data-ratio="1.102880658436214" data-s="300,640" src="/upload/e5bf23b9b2a67dfef710978b978c0273.png" data-type="png" data-w="972" type="block"> </section> <section style="text-indent: 2em;"> <span data-pm-slice="0 0 []"><span data-pm-slice="0 0 []"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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;">接下来就可以进行提问,验证一下,百度mcp的使用。</span></span></span></span> </section> <section style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal; nodeleaf=""> <img class="rich_pages wxw-img js_insertlocalimg" data-imgfileid="100000798" data-ratio="1.4346153846153846" data-s="300,640" src="/upload/10283fd450138b7ba04333db97713cb8.png" data-type="png" data-w="1040" type="block"> </section> <section> <span data-pm-slice="0 0 []"><span data-pm-slice="0 0 []"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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></span></span> </section> <p style="display: none;"> <mp-style-type data-value="3"></mp-style-type></p>
作者:微信小助手
<p cid="n0" mdtype="paragraph" style="margin-bottom: 24px;" data-pm-slice="0 0 []"><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x51biryow"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <user> users = ...; </user></span><span leaf=""><br></span><span leaf="">Map <long, ></long, ></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <order>> result = users.stream() </order></span><span leaf=""><br></span><span leaf=""> .filter(u -> u.getStatus() == UserStatus.ACTIVE)</span><span leaf=""><br></span><span leaf=""> .filter(u -> u.getAge() > </span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">18</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> .filter(u -> u.getOrders().size() > </span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 7px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">0</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> .flatMap(u -> u.getOrders().stream())</span><span leaf=""><br></span><span leaf=""> .collect(Collectors.groupingBy(Order::getUserId,</span><span leaf=""><br></span><span leaf=""> Collectors.mapping(Order::getId, Collectors.toList())));</span></code></pre> </section> <p cid="n3" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 0.8em 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">这段代码乍一看很“流式”,但仔细分析就会发现:</span></span></span></p> <ul style="box-sizing: border-box;margin: 0.8em 0px;padding-left: 30px;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, 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;white-space: normal;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial; class="list-paddingleft-1"> <li style="box-sizing: border-box;margin: 0px;"><p cid="n6" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">连续三个filter像俄罗斯套娃</span></span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n8" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">flatMap后的collect嵌套层数堪比俄罗斯方块</span></span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n10" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">最终结果类型Map>与实际需求完全不符 </span></span></span></p></li> </ul> <p cid="n10" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="background-color: transparent;"><span leaf=""><span textstyle="" style="font-size: 17px;">这让我想起最近流行的一句话:</span></span></span><span md-inline="strong" style="background-color: transparent;"><strong><span md-inline="plain"><span leaf=""><span textstyle="" style="font-size: 17px;">“Stream用得好是瑞士军刀,用不好就是小李飞刀——刀刀见血,但扎的是自己。”</span></span></span></strong></span></p> <section mpa-from-tpl="t" data-mpa-action-id="m8x4c4fm1p5w" data-pm-slice="0 0 []"> <span leaf=""><br></span> </section> <section data-mpa-template="t" mpa-from-tpl="t" data-mpa-action-id="m8x4c4fm17nt"> <section data-mpa-template="t" mpa-from-tpl="t"> <h4 data-tool="mdnice编辑器" style="margin-bottom: 15px;font-weight: 400;font-size: 16px;text-align: justify;outline: 0px;color: rgb(34, 34, 34);letter-spacing: 0.544px;caret-color: rgb(51, 51, 51);line-height: 2em;"><span style="font-size: 20px;"><strong mpa-from-tpl="t" style="outline: 0px;"><span mpa-is-content="t" style="font-size: 20px;outline: 0px;color: rgb(0, 122, 170);"><span leaf="">一、Stream变丑的四大“毁容级”操作</span></span></strong></span></h4> </section> </section> <h4 cid="n12" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">1. 链式调用七龙珠</span></span></span></h4> <p cid="n13" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 0.8em 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">有些同学对链式调用有一种迷之执着,恨不得把所有操作塞进一条流里:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x51twh1sdc"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <string> result = </string></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">list</span></span><span leaf="">.stream()</span><span leaf=""><br></span><span leaf=""> .filter(...).map(...).flatMap(...).distinct()</span><span leaf=""><br></span><span leaf=""> .sorted(...).limit(...).skip(...).collect(...);</span></code></pre> </section> <p cid="n15" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">危害</span></span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">:超过5个操作的链式调用会让代码可读性直线下降,调试时根本分不清问题出在哪一环。</span></span></span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><br></span></span></p> <p cid="n15" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">解药</span></span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x5279fkiw"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(153, 153, 136);background: rgba(0, 0, 0, 0);display: inline;width: 173px;text-decoration: none solid rgb(153, 153, 136);font-weight: 400;font-style: italic;font-family: none;"><span leaf="">// 分段处理,用中间变量过渡</span></span><span leaf=""><br></span><span leaf="">Stream<</span><span style="color: rgb(0, 134, 179);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(0, 134, 179);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">String</span></span><span leaf="">> filtered = list.stream().filter(...);</span><span leaf=""><br></span><span leaf="">Stream<</span><span style="color: rgb(0, 134, 179);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(0, 134, 179);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">String</span></span><span leaf="">> mapped = filtered.map(...);</span><span leaf=""><br></span><span leaf="">List<</span><span style="color: rgb(0, 134, 179);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(0, 134, 179);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">String</span></span><span leaf="">> result = mapped.collect(...);</span></code></pre> </section> <h4 cid="n17" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">2. 滥用Collectors.joining</span></span></span></h4> <p cid="n18" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在某个电商项目里,我见过这样的代码:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x52p7ejsj"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span leaf="">String skuIds = order.getItems().stream()</span><span leaf=""><br></span><span leaf=""> .</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">map</span></span><span leaf="">(Item::getSkuId)</span><span leaf=""><br></span><span leaf=""> .collect(Collectors.joining(</span><span style="color: rgb(221, 17, 68);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(221, 17, 68);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">","</span></span><span leaf="">));</span></code></pre> </section> <p cid="n20" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">问题</span></span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">:如果订单没有商品,会得到空字符串,而空字符串和null在业务逻辑中是不同的概念。</span></span></span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;"> </span></span></span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><br></span></span></strong></span></p> <p cid="n20" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">改进方案</span></span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x534jpknd"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span leaf="">Optional <string> skuIdsOpt = order.getItems().stream() </string></span><span leaf=""><br></span><span leaf=""> .map(Item::getSkuId)</span><span leaf=""><br></span><span leaf=""> .collect(Collectors.joining(</span><span style="color: rgb(221, 17, 68);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(221, 17, 68);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">","</span></span><span leaf="">))</span><span leaf=""><br></span><span leaf=""> .</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">empty</span></span><span leaf="">() ? Optional.</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">empty</span></span><span leaf="">() : Optional.of(skuIds);</span></code></pre> </section> <h4 cid="n22" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">3. 忽略性能的Collectors.toList()</span></span></span></h4> <p cid="n23" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">某支付系统的关键路径上有这样的代码:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x53rsq1oyw"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <transaction> transactions = db.query(...).stream() </transaction></span><span leaf=""><br></span><span leaf=""> .filter(t -> t.getAmount() > </span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">1000</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> .collect(Collectors.toList());</span></code></pre> </section> <p cid="n25" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">隐患</span></span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">:当数据量达到百万级时,toList()会导致内存溢出。</span></span></span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;"> </span></span></span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><br></span></span></strong></span></p> <p cid="n25" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">优化方法</span></span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;font-weight: normal;">:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x54akukwd"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(153, 153, 136);background: rgba(0, 0, 0, 0);display: inline;width: 141px;text-decoration: none solid rgb(153, 153, 136);font-weight: 400;font-style: italic;font-family: none;"><span leaf="">// 使用并行流+分批处理</span></span><span leaf=""><br></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <transaction> result = </transaction></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">new</span></span><span leaf=""> ArrayList<>();</span><span leaf=""><br></span><span leaf="">db.query(...).stream()</span><span leaf=""><br></span><span leaf=""> .parallel()</span><span leaf=""><br></span><span leaf=""> .filter(t -> t.getAmount() > </span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">1000</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> .forEachOrdered(result::add);</span></code></pre> </section> <h4 cid="n27" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">4. 错误使用boxed()</span></span></span></h4> <p cid="n28" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在某个金融计算场景中:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x54wkd1q5t"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span leaf="">double sum = numbers.stream()</span><span leaf=""><br></span><span leaf=""> .boxed()</span><span leaf=""><br></span><span leaf=""> .mapToDouble(Number::doubleValue)</span><span leaf=""><br></span><span leaf=""> .sum();</span></code></pre> </section> <p cid="n28" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-weight: bold;">误区</span></span></span><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, hiragino sans gb, microsoft yahei ui, yahei, arial, sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal;>:boxed()会将原始类型转换为包装类型,导致性能下降。</span></span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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></span><span md-inline="strong"><strong><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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></span></strong></span></p> <p cid="n30" mdtype="paragraph" style="margin-top: 24px;margin-bottom: 24px;"><span md-inline="strong"><strong><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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-weight: bold;">正确姿势</span></span></span></strong></span><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x55bgmyw8"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span leaf="">double sum = numbers.stream()</span><span leaf=""><br></span><span leaf=""> .mapToDouble(Number::doubleValue)</span><span leaf=""><br></span><span leaf=""> .sum();</span></code></pre> </section> <section mpa-from-tpl="t" data-mpa-action-id="m8x4exn21m7h" data-pm-slice="0 0 []"> <span leaf=""><br></span> </section> <section data-mpa-template="t" mpa-from-tpl="t" data-mpa-action-id="m8x4exn2hv4"> <section data-mpa-template="t" mpa-from-tpl="t"> <h4 data-tool="mdnice编辑器" style="margin-bottom: 15px;font-weight: 400;font-size: 16px;text-align: justify;outline: 0px;color: rgb(34, 34, 34);letter-spacing: 0.544px;caret-color: rgb(51, 51, 51);line-height: 2em;"><span style="font-size: 20px;"><strong mpa-from-tpl="t" style="outline: 0px;"><span mpa-is-content="t" style="font-size: 20px;outline: 0px;color: rgb(0, 122, 170);"><span leaf="">二、Stream优雅编程的五大黄金法则</span></span></strong></span></h4> </section> </section> <h4 cid="n33" mdtype="heading" style="margin-top: 24px;margin-bottom: 24px;line-height: 2em;"><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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-weight: bold;">1. 保持流操作的原子性</span></span></span></h4> <p cid="n34" mdtype="paragraph" style="margin-top: 24px;margin-bottom: 24px;line-height: 2em;"><span md-inline="strong"><strong><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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></span></strong></span><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4ml75yn6"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <product> products = productList.stream() </product></span><span leaf=""><br></span><span leaf=""> .filter(p -> p.getPrice() > </span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">100</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> .filter(p -> p.getStock() > </span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 7px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">0</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> .collect(Collectors.toList());</span></code></pre> </section> <p cid="n34" mdtype="paragraph" style="margin-top: 24px;margin-bottom: 24px;line-height: 2em;"><span md-inline="plain"><span leaf="" style="color:rgba(0, 0, 0, 0.9);font-size:17px;font-family:" mp-quote, -apple-system-font, blinkmacsystemfont, helvetica neue, pingfang sc, 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: 17px;">重构方案</span></span></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4ncip3xj"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(153, 153, 136);background: rgba(0, 0, 0, 0);display: inline;width: 142px;text-decoration: none solid rgb(153, 153, 136);font-weight: 400;font-style: italic;font-family: none;"><span leaf="">// 定义独立的Predicate</span></span><span leaf=""><br></span><span leaf="">Predicate <product> isExpensive = p -> p.getPrice() > </product></span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">100</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf="">Predicate <product> isInStock = p -> p.getStock() > </product></span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 7px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">0</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <product> products = productList.stream() </product></span><span leaf=""><br></span><span leaf=""> .filter(isExpensive.</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">and</span></span><span leaf="">(isInStock))</span><span leaf=""><br></span><span leaf=""> .collect(Collectors.toList());</span></code></pre> </section> <h4 cid="n38" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">2. 合理使用peek()</span></span></span></h4> <p cid="n39" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在监控日志场景中:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4nxvw20a"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <order> orders = orderList.stream() </order></span><span leaf=""><br></span><span leaf=""> .peek(o -> log.info(</span><span style="color: rgb(221, 17, 68);background: rgba(0, 0, 0, 0);display: inline;width: 144px;text-decoration: none solid rgb(221, 17, 68);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">"Processing order: {}"</span></span><span leaf="">, o.getId()))</span><span leaf=""><br></span><span leaf=""> .filter(o -> o.getStatus() == COMPLETED)</span><span leaf=""><br></span><span leaf=""> .collect(Collectors.toList());</span></code></pre> </section> <p cid="n41" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0.8em 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">注意事项</span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">:</span></span></p> <ul style="box-sizing: border-box;margin: 0.8em 0px;padding-left: 30px;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, 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;white-space: normal;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial; class="list-paddingleft-1"> <li style="box-sizing: border-box;margin: 0px;"><p cid="n44" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">peek()只能用于调试或副作用操作</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n46" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">避免在peek中修改流元素</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n48" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">并行流中慎用peek()</span></span></p></li> </ul> <h4 cid="n49" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">3. 自定义Collectors</span></span></span></h4> <p cid="n50" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在权限系统中,我们需要将用户角色收集为枚举集合:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4oja61f7j"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span leaf="">public </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 144px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">class</span></span><span leaf=""> </span><span style="color: rgb(68, 85, 136);background: rgba(0, 0, 0, 0);display: inline;width: 92px;text-decoration: none solid rgb(68, 85, 136);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">RoleCollectors</span></span><span leaf=""> {</span></span><span leaf=""><br></span><span leaf=""> public static Collector <user, ?, set<role>> rolesToSet() { </user,></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span leaf=""> Collector.</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">of</span></span><span leaf="">(</span><span leaf=""><br></span><span leaf=""> HashSet::</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">new</span></span><span leaf="">,</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 92px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 72px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">(set, user)</span></span><span leaf=""> -></span></span><span leaf=""> set.add(user.getRole()),</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 105px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 85px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">(left, right)</span></span><span leaf=""> -></span></span><span leaf=""> { left.addAll(right); </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span leaf=""> left; },</span><span leaf=""><br></span><span leaf=""> Collector.Characteristics.UNORDERED</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><span leaf=""><br></span><span style="color: rgb(0, 153, 38);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(0, 153, 38);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">//</span></span><span leaf=""> 使用示例</span><span leaf=""><br></span><span leaf="">Set <role> roles = users.stream() </role></span><span leaf=""><br></span><span leaf=""> .collect(RoleCollectors.rolesToSet());</span></code></pre> </section> <h4 cid="n52" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">4. 处理空流的正确姿势</span></span></span></h4> <p cid="n53" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在商品推荐场景中:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4p1dplw2"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <product> recommendations = productList.stream() </product></span><span leaf=""><br></span><span leaf=""> .filter(p -> p.getCategory().equals(</span><span style="color: rgb(221, 17, 68);background: rgba(0, 0, 0, 0);display: inline;width: 85px;text-decoration: none solid rgb(221, 17, 68);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">"electronics"</span></span><span leaf="">))</span><span leaf=""><br></span><span leaf=""> .findFirst()</span><span leaf=""><br></span><span leaf=""> .map(Collections::singletonList)</span><span leaf=""><br></span><span leaf=""> .orElse(Collections.emptyList());</span></code></pre> </section> <p cid="n55" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">更优雅的方式</span></span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4pqb5pur"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <product> recommendations = productList.stream() </product></span><span leaf=""><br></span><span leaf=""> .filter(p -> p.getCategory().equals(</span><span style="color: rgb(221, 17, 68);background: rgba(0, 0, 0, 0);display: inline;width: 85px;text-decoration: none solid rgb(221, 17, 68);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">"electronics"</span></span><span leaf="">))</span><span leaf=""><br></span><span leaf=""> .collect(Collectors.collectingAndThen(</span><span leaf=""><br></span><span leaf=""> Collectors.toList(),</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">list</span></span><span leaf=""> -> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">list</span></span><span leaf="">.isEmpty() ? Collections.singletonList(defaultProduct) : </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">list</span></span><span leaf=""><br></span><span leaf=""> ));</span></code></pre> </section> <h4 cid="n57" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">5. 结合Optional使用</span></span></span></h4> <p cid="n58" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在用户服务中:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4qb3dgn6"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span leaf="">User user = userRepository.findById(userId)</span><span leaf=""><br></span><span leaf=""> .orElseThrow(</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">()</span></span><span leaf=""> -></span></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">new</span></span><span leaf=""> UserNotFoundException(userId));</span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span leaf=""> user.getEmail();</span></code></pre> </section> <p cid="n60" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">Stream优化版</span></span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4qqa5sq0"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span leaf=""> userRepository.findById(userId)</span><span leaf=""><br></span><span leaf=""> .map(User::getEmail)</span><span leaf=""><br></span><span leaf=""> .orElseThrow(</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">()</span></span><span leaf=""> -></span></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">new</span></span><span leaf=""> UserNotFoundException(userId));</span></code></pre> </section> <section mpa-from-tpl="t" data-mpa-action-id="m8x4rz6yjxt" data-pm-slice="0 0 []"> <span leaf=""><br></span> </section> <section data-mpa-template="t" mpa-from-tpl="t" data-mpa-action-id="m8x4rz6y1cay"> <section data-mpa-template="t" mpa-from-tpl="t"> <h4 data-tool="mdnice编辑器" style="margin-bottom: 15px;font-weight: 400;font-size: 16px;text-align: justify;outline: 0px;color: rgb(34, 34, 34);letter-spacing: 0.544px;caret-color: rgb(51, 51, 51);line-height: 2em;"><span style="font-size: 20px;"><strong mpa-from-tpl="t" style="outline: 0px;"><span mpa-is-content="t" style="font-size: 20px;outline: 0px;color: rgb(0, 122, 170);"><span leaf="">三、Stream高级技巧:让代码会“呼吸”</span></span></strong></span></h4> </section> </section> <h4 cid="n63" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">1. 分阶段处理流</span></span></span></h4> <p cid="n64" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在物流系统中,订单处理分为三个阶段:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4ug6q8m1"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span leaf="">Stream <order> orderStream = orderRepository.findAll().stream(); </order></span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(153, 153, 136);background: rgba(0, 0, 0, 0);display: inline;width: 141px;text-decoration: none solid rgb(153, 153, 136);font-weight: 400;font-style: italic;font-family: none;"><span leaf="">// 阶段1:过滤有效订单</span></span><span leaf=""><br></span><span leaf="">Stream <order> validOrders = orderStream </order></span><span leaf=""><br></span><span leaf=""> .filter(Order::isValid)</span><span leaf=""><br></span><span leaf=""> .peek(o -> auditLogService.logValidation(o));</span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(153, 153, 136);background: rgba(0, 0, 0, 0);display: inline;width: 116px;text-decoration: none solid rgb(153, 153, 136);font-weight: 400;font-style: italic;font-family: none;"><span leaf="">// 阶段2:计算运费</span></span><span leaf=""><br></span><span leaf="">Map <long, double> shippingFees = validOrders </long,></span><span leaf=""><br></span><span leaf=""> .collect(Collectors.toMap(</span><span leaf=""><br></span><span leaf=""> Order::getId,</span><span leaf=""><br></span><span leaf=""> this::calculateShippingFee</span><span leaf=""><br></span><span leaf=""> ));</span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(153, 153, 136);background: rgba(0, 0, 0, 0);display: inline;width: 141px;text-decoration: none solid rgb(153, 153, 136);font-weight: 400;font-style: italic;font-family: none;"><span leaf="">// 阶段3:更新订单状态</span></span><span leaf=""><br></span><span leaf="">validOrders.</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 46px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">forEach</span></span><span leaf="">(o -> orderService.updateStatus(o, SHIPPING));</span></code></pre> </section> <h4 cid="n66" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">2. 使用Collectors.teeing()</span></span></span></h4> <p cid="n67" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在统计用户画像时:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4v43013ll"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span leaf="">UserProfile profile = users.stream()</span><span leaf=""><br></span><span leaf=""> .collect(Collectors.teeing(</span><span leaf=""><br></span><span leaf=""> Collectors.averagingInt(User::getAge),</span><span leaf=""><br></span><span leaf=""> Collectors.summingDouble(User::getSpending),</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 170px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 150px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">(avgAge, totalSpending)</span></span><span leaf=""> -></span></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">new</span></span><span leaf=""> UserProfile(avgAge, totalSpending)</span><span leaf=""><br></span><span leaf=""> ));</span></code></pre> </section> <h4 cid="n69" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">3. 处理并行流的陷阱</span></span></span></h4> <p cid="n70" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在文件处理场景中:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4w0szunk"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">List</span></span><span leaf=""> <string> lines = Files.readAllLines(Paths.get( </string></span><span style="color: rgb(221, 17, 68);background: rgba(0, 0, 0, 0);display: inline;width: 65px;text-decoration: none solid rgb(221, 17, 68);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">"data.txt"</span></span><span leaf="">));</span><span leaf=""><br></span><span leaf=""><br></span><span leaf="">lines.parallelStream()</span><span leaf=""><br></span><span leaf=""> .map(this::processLine)</span><span leaf=""><br></span><span leaf=""> .forEachOrdered(System.out::println);</span></code></pre> </section> <p cid="n72" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0.8em 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">关键点</span></span></strong></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">:</span></span></p> <ul style="box-sizing: border-box;margin: 0.8em 0px;padding-left: 30px;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, 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;white-space: normal;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial; class="list-paddingleft-1"> <li style="box-sizing: border-box;margin: 0px;"><p cid="n75" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">顺序敏感操作必须使用forEachOrdered()</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n77" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">共享资源需要线程安全处理</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n79" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">避免过度使用并行流</span></span></p></li> </ul> <h4 cid="n80" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 2;font-size: 1.25em;margin-top: 24px;margin-bottom: 24px;font-weight: bold;line-height: 2em;cursor: text;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">4. 自定义Spliterator</span></span></span></h4> <p cid="n81" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">在处理海量日志时:</span></span></span></p> <section data-mpa-preserve-tpl-color="t" data-mpa-template="t" mpa-preserve="t" mpa-from-tpl="t" data-mpa-action-id="m8x4xcc21t9x"> <pre style="margin: 0px;padding: 0px;background: none;font-family: none;"><code style="border-radius: 4px;font-size: 0.85em;font-family: none;margin: 0px 0.15em;background: rgb(248, 248, 248);color: rgb(51, 51, 51);display: block;padding: 5.95px;overflow-x: auto;white-space: nowrap;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">public</span></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 353px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">class</span></span><span leaf=""> </span><span style="color: rgb(68, 85, 136);background: rgba(0, 0, 0, 0);display: inline;width: 92px;text-decoration: none solid rgb(68, 85, 136);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">LogSpliterator</span></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 65px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">implements</span></span><span leaf=""> </span><span style="color: rgb(68, 85, 136);background: rgba(0, 0, 0, 0);display: inline;width: 72px;text-decoration: none solid rgb(68, 85, 136);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">Spliterator</span></span><span leaf=""><</span><span style="color: rgb(68, 85, 136);background: rgba(0, 0, 0, 0);display: inline;width: 52px;text-decoration: none solid rgb(68, 85, 136);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">LogEntry</span></span><span leaf="">> </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 46px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">private</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">final</span></span><span leaf=""> List <logentry> logs; </logentry></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 46px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">private</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">int</span></span><span leaf=""> currentIndex;</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 281px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">public</span></span><span leaf=""> </span><span style="color: rgb(153, 0, 0);background: rgba(0, 0, 0, 0);display: inline;width: 92px;text-decoration: none solid rgb(153, 0, 0);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">LogSpliterator</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 137px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">(List <logentry> logs) </logentry></span></span><span leaf=""> </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">this</span></span><span leaf="">.logs = logs;</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">this</span></span><span leaf="">.currentIndex = </span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 7px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">0</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(153, 153, 153);background: rgba(0, 0, 0, 0);display: inline;width: 59px;text-decoration: none solid rgb(153, 153, 153);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">@Override</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 399px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">public</span></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 46px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">boolean</span></span><span leaf=""> </span><span style="color: rgb(153, 0, 0);background: rgba(0, 0, 0, 0);display: inline;width: 65px;text-decoration: none solid rgb(153, 0, 0);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">tryAdvance</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 229px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">(Consumer<!--? </span--><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">super</span></span><span leaf=""> LogEntry> action)</span></span><span leaf=""> </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">if</span></span><span leaf=""> (currentIndex < logs.size()) {</span><span leaf=""><br></span><span leaf=""> action.accept(logs.get(currentIndex++));</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">true</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 33px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">false</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(153, 153, 153);background: rgba(0, 0, 0, 0);display: inline;width: 59px;text-decoration: none solid rgb(153, 153, 153);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">@Override</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 262px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">public</span></span><span leaf=""> Spliterator <logentry> </logentry></span><span style="color: rgb(153, 0, 0);background: rgba(0, 0, 0, 0);display: inline;width: 52px;text-decoration: none solid rgb(153, 0, 0);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">trySplit</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">()</span></span><span leaf=""> </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">int</span></span><span leaf=""> currentSize = logs.size() - currentIndex;</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">if</span></span><span leaf=""> (currentSize < </span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">1000</span></span><span leaf="">) </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">null</span></span><span leaf="">; </span><span style="color: rgb(153, 153, 136);background: rgba(0, 0, 0, 0);display: inline;width: 71px;text-decoration: none solid rgb(153, 153, 136);font-weight: 400;font-style: italic;font-family: none;"><span leaf="">// 阈值设定</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">int</span></span><span leaf=""> splitPos = currentIndex + currentSize / </span><span style="color: rgb(0, 128, 128);background: rgba(0, 0, 0, 0);display: inline;width: 7px;text-decoration: none solid rgb(0, 128, 128);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">2</span></span><span leaf="">;</span><span leaf=""><br></span><span leaf=""> Spliterator <logentry> split = </logentry></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">new</span></span><span leaf=""> LogSpliterator(logs.subList(currentIndex, splitPos));</span><span leaf=""><br></span><span leaf=""> currentIndex = splitPos;</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span leaf=""> split;</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(153, 153, 153);background: rgba(0, 0, 0, 0);display: inline;width: 59px;text-decoration: none solid rgb(153, 153, 153);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">@Override</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 177px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">public</span></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">long</span></span><span leaf=""> </span><span style="color: rgb(153, 0, 0);background: rgba(0, 0, 0, 0);display: inline;width: 78px;text-decoration: none solid rgb(153, 0, 0);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">estimateSize</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">()</span></span><span leaf=""> </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span leaf=""> logs.size() - currentIndex;</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(153, 153, 153);background: rgba(0, 0, 0, 0);display: inline;width: 59px;text-decoration: none solid rgb(153, 153, 153);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">@Override</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 190px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">public</span></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">int</span></span><span leaf=""> </span><span style="color: rgb(153, 0, 0);background: rgba(0, 0, 0, 0);display: inline;width: 98px;text-decoration: none solid rgb(153, 0, 0);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">characteristics</span></span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 13px;text-decoration: none solid rgb(51, 51, 51);font-weight: 400;font-style: normal;font-family: none;"><span leaf="">()</span></span><span leaf=""> </span></span><span leaf="">{</span><span leaf=""><br></span><span leaf=""> </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 39px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">return</span></span><span leaf=""> Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf="">}</span><span leaf=""><br></span><span leaf=""><br></span><span style="color: rgb(153, 153, 136);background: rgba(0, 0, 0, 0);display: inline;width: 71px;text-decoration: none solid rgb(153, 153, 136);font-weight: 400;font-style: italic;font-family: none;"><span leaf="">// 使用示例</span></span><span leaf=""><br></span><span leaf="">StreamSupport.stream(</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 20px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">new</span></span><span leaf=""> LogSpliterator(logs), </span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">true</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf=""> .parallel()</span><span leaf=""><br></span><span leaf=""> .forEach(</span><span style="color: rgb(51, 51, 51);background: rgba(0, 0, 0, 0);display: inline;width: 26px;text-decoration: none solid rgb(51, 51, 51);font-weight: 700;font-style: normal;font-family: none;"><span leaf="">this</span></span><span leaf="">::processLog);</span></span></code></pre> </section> <section mpa-from-tpl="t" data-mpa-action-id="m8x4xpy01p0e" data-pm-slice="0 0 []"> <span leaf=""><br></span> </section> <section data-mpa-template="t" mpa-from-tpl="t" data-mpa-action-id="m8x4xpy0iqe"> <section data-mpa-template="t" mpa-from-tpl="t"> <h4 data-tool="mdnice编辑器" style="margin-bottom: 15px;font-weight: 400;font-size: 16px;text-align: justify;outline: 0px;color: rgb(34, 34, 34);letter-spacing: 0.544px;caret-color: rgb(51, 51, 51);line-height: 2em;"><span style="font-size: 20px;"><strong mpa-from-tpl="t" style="outline: 0px;"><span mpa-is-content="t" style="font-size: 20px;outline: 0px;color: rgb(0, 122, 170);"><span leaf="">四、Stream代码质量检查清单</span></span></strong></span></h4> </section> </section> <ol style="box-sizing: border-box;margin: 0.8em 0px;padding-left: 30px;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, 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;white-space: normal;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial; class="list-paddingleft-1"> <li style="box-sizing: border-box;margin: 0px;"><p cid="n86" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">可读性检查</span></span></strong></span></p></li> <ol style="box-sizing: border-box;margin: 0px;padding-left: 30px;" class="list-paddingleft-1"> <li style="box-sizing: border-box;margin: 0px;"><p cid="n89" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">每个流操作是否有明确的业务含义</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n91" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">链式调用是否超过5层</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n93" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">是否使用了有意义的中间变量</span></span></p></li> </ol> <li style="box-sizing: border-box;margin: 0px;"><p cid="n95" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">性能检查</span></span></strong></span></p></li> <ol style="box-sizing: border-box;margin: 0px;padding-left: 30px;" class="list-paddingleft-1"> <li style="box-sizing: border-box;margin: 0px;"><p cid="n98" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">是否在不必要的情况下使用了boxed()</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n100" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">并行流是否适用于当前场景</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n102" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">收集操作是否考虑了数据规模</span></span></p></li> </ol> <li style="box-sizing: border-box;margin: 0px;"><p cid="n104" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">异常处理</span></span></strong></span></p></li> <ol style="box-sizing: border-box;margin: 0px;padding-left: 30px;" class="list-paddingleft-1"> <li style="box-sizing: border-box;margin: 0px;"><p cid="n107" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">是否处理了空流情况</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n109" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">是否合理使用了Optional</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n111" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">错误处理是否符合业务需求</span></span></p></li> </ol> <li style="box-sizing: border-box;margin: 0px;"><p cid="n113" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">可维护性</span></span></strong></span></p></li> <ol style="box-sizing: border-box;margin: 0px;padding-left: 30px;" class="list-paddingleft-1"> <li style="box-sizing: border-box;margin: 0px;"><p cid="n116" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">是否将复杂逻辑拆分为独立的方法</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n118" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">是否使用了自定义Collectors</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n120" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">是否考虑了未来的扩展需求</span></span></p></li> </ol> </ol> <section mpa-from-tpl="t" data-mpa-action-id="m8x50hz624mu" data-pm-slice="0 0 []"> <span leaf=""><br></span> </section> <section data-mpa-template="t" mpa-from-tpl="t" data-mpa-action-id="m8x50hz61dtp"> <section data-mpa-template="t" mpa-from-tpl="t"> <h4 data-tool="mdnice编辑器" style="margin-bottom: 15px;font-weight: 400;font-size: 16px;text-align: justify;outline: 0px;color: rgb(34, 34, 34);letter-spacing: 0.544px;caret-color: rgb(51, 51, 51);line-height: 2em;"><span style="font-size: 20px;"><strong mpa-from-tpl="t" style="outline: 0px;"><span mpa-is-content="t" style="font-size: 20px;outline: 0px;color: rgb(0, 122, 170);"><span leaf="">五、终极心法:流的本质是思维方式</span></span></strong></span></h4> </section> </section> <p cid="n122" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, sans-serif;font-size: 16px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;><span md-inline="plain" style="box-sizing: border-box;"><span leaf=""><span textstyle="" style="font-size: 17px;">最后分享一个真实案例:某电商平台通过重构Stream代码,使核心订单处理流程的代码量减少40%,同时性能提升30%。他们的秘诀在于:</span></span></span></p> <ol style="box-sizing: border-box;margin: 0.8em 0px;padding-left: 30px;color: rgb(51, 51, 51);font-family: " open sans, clear helvetica neue, helvetica, arial, 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;white-space: normal;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial; class="list-paddingleft-1"> <li style="box-sizing: border-box;margin: 0px;"><p cid="n125" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">将流操作与业务逻辑解耦</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n127" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">建立Stream最佳实践库</span></span></p></li> <li style="box-sizing: border-box;margin: 0px;"><p cid="n129" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin: 0px 0px 0.5rem;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">使用IDE插件(如StreamRefactor)进行代码检查 </span></span></p></li> </ol> <p cid="n129" mdtype="paragraph" style="box-sizing: border-box;line-height: 2em;orphans: 4;margin: 24px 0px;white-space: pre-wrap;"><span style="background-color: transparent;"><span leaf="">记住:Stream不是代码竞赛的工具,而是提升代码质量的手段</span></span><span md-inline="plain" style="box-sizing: border-box;"><span leaf="">。当你开始思考如何让Stream代码更易读、易维护、易扩展时,你就真正掌握了它的精髓。 </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: 0px;padding-right: 0px;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(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">就体验而言,笔者用的最多的当属:</span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">edge-tts</span></code><span leaf=""> </span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">FishSpeech</span></code><span leaf=""> 和 </span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">CosyVoice</span></code></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">其中,</span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">edge-tts</span></code><span leaf=""> 需联网,而 </span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">FishSpeech</span></code><span leaf=""> 和 </span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">CosyVoice</span></code><span leaf=""> 则需显卡。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">有没有端侧可运行的轻量级 TTS 模型?</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">之前还真发现过一个潜力股:</span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">Kokoro</span></code><span leaf="">,不过当时对中文不太友好,暂且搁置。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">最近,</span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">Kokoro</span></code><span leaf=""> 上新了,新增 100 种中文音色,且支持中英混合。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">这就有必要来聊聊了,希望能为您 TTS 选型提供一个参考。</span></p> <h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 0px;padding-bottom: 0px;padding-left: 10px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: solid;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 5px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(145, 109, 213);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: unset;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: block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">1. Kokoro 简介</span></span><span style="display: none;"></span></h2> <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(216, 156, 246);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(244, 238, 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;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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;color: rgb(0, 0, 0);font-size: 15px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;"><span leaf="">项目地址:</span><span leaf="">https://github.com/hexgrad/kokoro</span></p> </blockquote> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">一款超轻量级的 TTS 模型,只有 </span><strong style="color: rgb(145, 109, 213);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="">82M</span></strong><span leaf=""> 参数。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">别看它架构轻巧,音质仍可媲美动辄 0.5B 的大模型。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">且看语音合成领域的 TTS Arena 排行榜,荣登榜一,且遥遥领先!</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 class="rich_pages wxw-img" data-imgfileid="100005247" data-ratio="0.362962962962963" src="/upload/1364b2ff170d7c30785e2f71fe56a69b.png" 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: 8px;border-top-right-radius: 8px;border-bottom-right-radius: 8px;border-bottom-left-radius: 8px;object-fit: fill;box-shadow: rgba(153, 153, 153, 0.3) 2px 4px 8px 0px;"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">相比 v0.19,v1.0 训练数据规模增加了,支持的音色更多:</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 class="rich_pages wxw-img" data-imgfileid="100005246" data-ratio="0.2851851851851852" src="/upload/ec97a456a79c923b363d60d7c55f1f1d.png" 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: 8px;border-top-right-radius: 8px;border-bottom-right-radius: 8px;border-bottom-left-radius: 8px;object-fit: fill;box-shadow: rgba(153, 153, 153, 0.3) 2px 4px 8px 0px;"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(145, 109, 213);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></p> <ul style="list-style-type: circle;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(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <strong style="color: rgb(145, 109, 213);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><strong style="color: rgb(145, 109, 213);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="">8</span></strong><span leaf=""> 种语言。</span> </section></li> <li> <section style="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;"> <strong style="color: rgb(145, 109, 213);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(1, 1, 1);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;text-align: left;font-weight: normal;"> <strong style="color: rgb(145, 109, 213);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="">:CPU上可近乎实时,而在GPU上,则达到了50倍实时速度。</span> </section></li> <li> <section style="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;"> <strong style="color: rgb(145, 109, 213);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> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-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: flex;flex-direction: unset;float: unset;height: auto;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 17px;color: rgb(0, 0, 0);border-bottom-color: rgb(216, 156, 246);line-height: 1.5em;letter-spacing: 0em;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: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">1.1 音色地址</span></span><span style="display: none;"></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">Kokoro</span></code><span leaf=""> 的所有音色均以 pt 文件,存放在 huggingface,国内用户可通过以下地址下载:</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">v1.0:</span><span leaf="">https://hf-mirror.com/hexgrad/Kokoro-82M</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">v1.1 </span><span leaf="">https://hf-mirror.com/hexgrad/Kokoro-82M-v1.1-zh</span><span leaf="">,新增更多中文音色。</span></p> <h2 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 0px;padding-bottom: 0px;padding-left: 10px;padding-right: 0px;border-top-style: none;border-bottom-style: none;border-left-style: solid;border-right-style: none;border-top-width: 1px;border-bottom-width: 1px;border-left-width: 5px;border-right-width: 1px;border-top-color: rgb(0, 0, 0);border-bottom-color: rgb(0, 0, 0);border-left-color: rgb(145, 109, 213);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: unset;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: block;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">2. Kokoro 实测</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;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: flex;flex-direction: unset;float: unset;height: auto;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 17px;color: rgb(0, 0, 0);border-bottom-color: rgb(216, 156, 246);line-height: 1.5em;letter-spacing: 0em;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: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">2.1 安装依赖</span></span><span style="display: none;"></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">pip install kokoro</span><span leaf=""><br></span><span leaf="">pip install ordered-set</span><span leaf=""><br></span><span leaf="">pip install cn2an</span><span leaf=""><br></span><span leaf="">pip install pypinyin_dict</span><span leaf=""><br></span></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-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: flex;flex-direction: unset;float: unset;height: auto;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 17px;color: rgb(0, 0, 0);border-bottom-color: rgb(216, 156, 246);line-height: 1.5em;letter-spacing: 0em;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: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">2.2 模型和音色下载</span></span><span style="display: none;"></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">从 huggingface 上拉取模型权重,以及音色文件:</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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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: #e6c07b;line-height: 26px;"><span leaf="">export</span></span><span leaf=""> HF_ENDPOINT=https://hf-mirror.com </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 引入镜像地址</span></span><span leaf=""><br></span><span leaf="">huggingface-cli download --resume-download hexgrad/Kokoro-82M --</span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">local</span></span><span leaf="">-dir ./ckpts/kokoro-v1.0</span><span leaf=""><br></span><span leaf="">huggingface-cli download --resume-download hexgrad/Kokoro-82M-v1.1-zh --</span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">local</span></span><span leaf="">-dir ./ckpts/kokoro-v1.1</span><span leaf=""><br></span></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-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: flex;flex-direction: unset;float: unset;height: auto;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 17px;color: rgb(0, 0, 0);border-bottom-color: rgb(216, 156, 246);line-height: 1.5em;letter-spacing: 0em;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: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">2.3 模型推理</span></span><span style="display: none;"></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">下面以中文语音合成为例,进行演示。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">kokoro</span></code><span leaf=""> 模型推理,只需以下 4 步~</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(145, 109, 213);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="">step 1:引入依赖</span></strong></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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">import torch</span><span leaf=""><br></span><span leaf="">import time</span><span leaf=""><br></span><span leaf="">from kokoro import KPipeline, KModel</span><span leaf=""><br></span><span leaf="">import soundfile as sf</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(145, 109, 213);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="">step 2:加载音色</span></strong></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">尽管 </span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">kokoro</span></code><span leaf=""> 支持运行时下载音色,不过在 2.2 部分,我们已将音色文件下载到本地,这里直接 load 进来:</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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">voice_zf = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"zf_001"</span></span><span leaf=""><br></span><span leaf="">voice_zf_tensor = torch.load(f</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'ckpts/kokoro-v1.1/voices/{voice_zf}.pt'</span></span><span leaf="">, weights_only=True)</span><span leaf=""><br></span><span leaf="">voice_af = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'af_maple'</span></span><span leaf=""><br></span><span leaf="">voice_af_tensor = torch.load(f</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'ckpts/kokoro-v1.1/voices/{voice_af}.pt'</span></span><span leaf="">, weights_only=True)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(145, 109, 213);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="">step 3:加载模型</span></strong></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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">repo_id = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'hexgrad/Kokoro-82M-v1.1-zh'</span></span><span leaf=""><br></span><span leaf="">device = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'cuda'</span></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> torch.cuda.is_available() </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">else</span></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'cpu'</span></span><span leaf=""><br></span><span leaf="">model_path = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'ckpts/kokoro-v1.1/kokoro-v1_1-zh.pth'</span></span><span leaf=""><br></span><span leaf="">config_path = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'ckpts/kokoro-v1.1/config.json'</span></span><span leaf=""><br></span><span leaf="">model = KModel(model=model_path, config=config_path, repo_id=repo_id).to(device).</span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">eval</span></span><span leaf="">()</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(145, 109, 213);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="">step 4:开始推理</span></strong></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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">zh_pipeline = KPipeline(lang_code=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'z'</span></span><span leaf="">, repo_id=repo_id, model=model)</span><span leaf=""><br></span><span leaf="">sentence = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'如果您愿意帮助进一步完成这一使命,请考虑为此贡献许可的音频数据。'</span></span><span leaf=""><br></span><span leaf="">start_time = time.time()</span><span leaf=""><br></span><span leaf="">generator = zh_pipeline(sentence, voice=voice_zf_tensor, speed=speed_callable)</span><span leaf=""><br></span><span leaf="">result = next(generator)</span><span leaf=""><br></span><span leaf="">wav = result.audio</span><span leaf=""><br></span><span leaf="">speech_len = len(wav) / 24000</span><span leaf=""><br></span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">print</span></span><span leaf="">(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'yield speech len {}, rtf {}'</span></span><span leaf="">.format(speech_len, (time.time() - start_time) / speech_len)) </span><span leaf=""><br></span><span leaf="">sf.write(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'output.wav'</span></span><span leaf="">, wav, 24000)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">其中,</span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">speed</span></code><span leaf=""> 支持 float 类型的语速控制,</span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">speed_callable</span></code><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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">def speed_callable(len_ps):</span><span leaf=""><br></span><span leaf=""> speed = 0.8</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> len_ps <= 83:</span><span leaf=""><br></span><span leaf=""> speed = 1</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">elif</span></span><span leaf=""> len_ps < 183:</span><span leaf=""><br></span><span leaf=""> speed = 1 - (len_ps - 83) / 500</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> speed * 1.1</span><span leaf=""><br></span></code></pre> <hr 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;border-top-style: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 3px;border-left-width: 3px;border-right-width: 3px;border-top-color: rgb(217, 184, 250);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;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: 1px;"> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">对于</span><strong style="color: rgb(145, 109, 213);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="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">KPipeline</span></code><span leaf=""> 中增加 </span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">en_callable</span></code><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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">en_pipeline = KPipeline(lang_code=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'a'</span></span><span leaf="">, repo_id=repo_id, model=model)</span><span leaf=""><br></span><span leaf="">def en_callable(text):</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> text == </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'Kokoro'</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'kˈOkəɹO'</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">elif</span></span><span leaf=""> text == </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'Sol'</span></span><span leaf="">:</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'sˈOl'</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> next(en_pipeline(text, voice=voice_zf_tensor)).phonemes</span><span leaf=""><br></span><span leaf="">zh_pipeline = KPipeline(lang_code=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'z'</span></span><span leaf="">, repo_id=repo_id, model=model, en_callable=en_callable)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">最后,来听听合成效果:</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(145, 109, 213);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></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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">该 Apache 许可模式也符合 OpenAI 所宣称的广泛传播 AI 优势的使命。</span><span leaf=""><br></span></code></pre> <section nodeleaf=""> <mp-common-mpaudio class="js_editor_audio res_iframe js_uneditable custom_select_card" data-pluginname="insertaudio" name="kokoro-mixed" author="猴哥的AI知识库" src="/cgi-bin/readtemplate?t=tmpl/audio_tmpl&name=kokoro-mixed&play_length=6%E7%A7%92" isaac2="1" low_size="11.43" source_size="11.4" high_size="25.17" play_length="6000" data-trans_state="1" data-verify_state="3" voice_encode_fileid="MzkzMzY2MTkyN18yMjQ3NDg4OTEz" cover="https://wx.qlogo.cn/mmopen/l1BlcrnOO6TnMmibUYUfACWLNcCficWzsYGKqK3DN2dYKTF9jVRKcB2k9bpCk2I8u63dTdKicITKwoSEmF4QEWNtTk1icX4nARQFGzLOXtXdic4DBumSPOy1R0oibKhicGCmuwv/0"></mp-common-mpaudio> </section> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-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: flex;flex-direction: unset;float: unset;height: auto;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 17px;color: rgb(0, 0, 0);border-bottom-color: rgb(216, 156, 246);line-height: 1.5em;letter-spacing: 0em;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: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">2.4 速度测试</span></span><span style="display: none;"></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">GPU 推理显存占用:</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 class="rich_pages wxw-img" data-imgfileid="100005245" data-ratio="0.2111111111111111" src="/upload/032adddcb2799ef9e1eb1c6bec8f4bf9.png" 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: 8px;border-top-right-radius: 8px;border-bottom-right-radius: 8px;border-bottom-left-radius: 8px;object-fit: fill;box-shadow: rgba(153, 153, 153, 0.3) 2px 4px 8px 0px;"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">TTS 通用的速度评估指标为 </span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">rtf</span></code><span leaf="">,也即 </span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">推理耗时/生成音频耗时</span></code><span leaf="">,指标越低,代表推理速度越快!</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">kokoro</span></code><span leaf=""> GPU 推理:</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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">yield speech len 6.825, rtf 0.2680429521497789</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">kokoro</span></code><span leaf=""> CPU 推理:</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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">yield speech len 6.825, rtf 0.4242438012427026</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(145, 109, 213);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="">可以发现,即便是 CPU 推理,rtf 依然远小于 1,强啊!</span></strong></p> <h3 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-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: flex;flex-direction: unset;float: unset;height: auto;justify-content: center;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 17px;color: rgb(0, 0, 0);border-bottom-color: rgb(216, 156, 246);line-height: 1.5em;letter-spacing: 0em;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: solid;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;border-top-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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">2.5 服务端部署</span></span><span style="display: none;"></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">下面我们采用 FastAPI 完成服务部署。</span><em style="color: rgb(145, 109, 213);font-style: italic;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></em></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">首先,定义数据模型,用于接收POST请求中的数据:</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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">class TTSRequest(BaseModel):</span><span leaf=""><br></span><span leaf=""> tts_text: str </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 待合成的文本</span></span><span leaf=""><br></span><span leaf=""> voice_id: Optional[str] = </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"zf_001"</span></span><span leaf=""> </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 参考语音的id</span></span><span leaf=""><br></span><span leaf=""> speed: Optional[</span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">float</span></span><span leaf="">] = None </span><span style="color: #5c6370;font-style: italic;line-height: 26px;"><span leaf=""># 语速</span></span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">@app.post(</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'/tts'</span></span><span leaf="">)</span><span leaf=""><br></span><span leaf="">def tts(request: TTSRequest):</span><span leaf=""><br></span><span leaf=""> voice_path = f</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'ckpts/kokoro-v1.1/voices/{request.voice_id}.pt'</span></span><span leaf=""><br></span><span leaf=""> </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> not os.path.exists(voice_path):</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> JSONResponse(status_code=400, content={</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"error"</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"voice_id not found"</span></span><span leaf="">})</span><span leaf=""><br></span><span leaf=""> voice_tensor = torch.load(voice_path, weights_only=True)</span><span leaf=""><br></span><span leaf=""> speed = speed_callable </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">if</span></span><span leaf=""> request.speed is None </span><span style="color: #c678dd;line-height: 26px;"><span leaf="">else</span></span><span leaf=""> request.speed</span><span leaf=""><br></span><span leaf=""> generator = zh_pipeline(request.tts_text, voice=voice_tensor, speed=speed)</span><span leaf=""><br></span><span leaf=""> result = next(generator)</span><span leaf=""><br></span><span leaf=""> wav = result.audio.cpu().numpy()</span><span leaf=""><br></span><span leaf=""> wav = (wav * 32767).astype(np.int16)</span><span leaf=""><br></span><span leaf=""> wav_bytes = io.BytesIO()</span><span leaf=""><br></span><span leaf=""> wav_bytes.write(wav.tobytes())</span><span leaf=""><br></span><span leaf=""> wav_bytes.seek(0)</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">return</span></span><span leaf=""> StreamingResponse(wav_bytes, media_type=</span><span style="color: #98c379;line-height: 26px;"><span leaf="">'audio/pcm'</span></span><span leaf="">, headers=headers)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(145, 109, 213);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="">注意:模型原始输出为 torch.tensor,可转成 int16 以 pcm 格式输出。</span></strong></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">nohup uvicorn server:app --host 0.0.0.0 --port 3008 > server.log 2>&1 &</span><span leaf=""><br></span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">echo</span></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"Server started"</span></span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;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 kbcyznggu08mg3qlheiamqpnoe69vqcjcf2ostdygj4mweseihpl1klmxmmdoik8zozhyivhvibf4ch4dgynw55jjxok0wf6via 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="">def </span><span style="color: #e6c07b;line-height: 26px;"><span leaf="">test</span></span><span leaf="">():</span><span leaf=""><br></span><span leaf=""> data = {</span><span leaf=""><br></span><span leaf=""> </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'tts_text'</span></span><span leaf="">: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">'2024年12月21日,你好,欢迎使用语音合成服务,共收录2000余种语言。'</span></span><span leaf="">,</span><span leaf=""><br></span><span leaf=""> }</span><span leaf=""><br></span><span leaf=""> response = requests.post(f</span><span style="color: #98c379;line-height: 26px;"><span leaf="">"{url}/tts"</span></span><span leaf="">, json=data)</span><span leaf=""><br></span><span leaf=""> pcm2wav(response.content)</span><span leaf=""><br></span></code></pre> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">对于</span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">数字播报</span></code><span leaf="">这一老大难问题,</span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">kokoro</span></code><span leaf=""> 也能轻松拿捏,来听效果:</span></p> <section nodeleaf=""> <mp-common-mpaudio class="js_editor_audio res_iframe js_uneditable custom_select_card" data-pluginname="insertaudio" name="kokoro-num" author="猴哥的AI知识库" src="/cgi-bin/readtemplate?t=tmpl/audio_tmpl&name=kokoro-num&play_length=7%E7%A7%92" isaac2="1" low_size="12.93" source_size="12.9" high_size="29.29" play_length="7000" data-trans_state="1" data-verify_state="3" voice_encode_fileid="MzkzMzY2MTkyN18yMjQ3NDg4OTEy" cover="https://wx.qlogo.cn/mmopen/l1BlcrnOO6TnMmibUYUfACWLNcCficWzsYGKqK3DN2dYKTF9jVRKcB2k9bpCk2I8u63dTdKicITKwoSEmF4QEWNtTk1icX4nARQFGzLOXtXdic4DBumSPOy1R0oibKhicGCmuwv/0"></mp-common-mpaudio> </section> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);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: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">就凭这,</span><code style="color: rgb(145, 109, 213);font-size: 16px;line-height: 1.8em;letter-spacing: 0em;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;height: 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="">kokoro</span></code><span leaf=""> 吊打一众 TTS 巨无霸模型!</span></p> </section>
作者:微信小助手
<section style="letter-spacing: 1.3px;padding: 0px;box-sizing: border-box;font-style: normal;font-weight: 400;text-align: justify;font-size: 16px;color: rgb(62, 62, 62);"> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 22px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">一、SEO的核心逻辑:理解搜索引擎如何工作</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span style="font-size: 18px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">1. 搜索引擎的三大目标</span></span></strong></span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">理解内容:通过爬虫抓取和分析网页内容</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">评估质量:基于E-E-A-T原则(专业性、权威性、可信度)</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">匹配意图:判断内容是否解决用户真实需求</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf=""><br></span></span></strong></p> <p style="margin: 0px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">2. 谷歌算法核心关注点</span></span></strong></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/a006c6a1f028034826e09e7cebd70cb4.png" class="rich_pages wxw-img" data-ratio="0.32355723746452225" data-s="300,640" data-type="png" data-w="1057" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013465"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 22px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf=""> </span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 22px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">二、四步构建SEO基础框架</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">1. 关键词研究:找到用户的搜索语言</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(1)工具与步骤</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">免费工具:Google Keyword Planner、AnswerThePublic</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">付费工具:SEMrush、Ahrefs(试用期可申请)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">操作流程:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">输入5个种子词(如"咖啡机")</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">筛选搜索量≥300、竞争度≤40的词</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">按意图分类(信息/商业/导航/交易型)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(2)实战案例:咖啡馆长尾词优化</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">成功案例</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">背景:某咖啡馆网站流量停滞,核心词"咖啡"竞争度过高(KD=85)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">操作:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">用AnswerThePublic挖掘疑问词:"如何在家制作拿铁"、"咖啡豆保存方法"</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">筛选出20个搜索量200-500的长尾词</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">结果:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">3个月内"咖啡豆保存方法"排名第1,带来月均1500次点击</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">相关页面用户停留时间达4分钟(高于全站均值2倍)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">2. 网站技术优化:让谷歌爬虫畅通无阻</span></span></strong></p> <p style="margin: 0px;padding: 0px;box-sizing: border-box;"><span leaf="">(1)必做技术项清单</span></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/9090d08c0882e393704b498d4422e8f8.png" class="rich_pages wxw-img" data-ratio="0.36644798500468606" data-s="300,640" data-type="png" data-w="1067" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013466"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""> </span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">3. 内容策略:打造用户与搜索引擎都爱的内容</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(1)内容创作黄金公式</span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><span style="box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">标题:核心词+解决方案+附加值 </span></span></strong></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">✅ 正例:“2023咖啡机选购指南|5步避开智商税” </span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">❌ 反例:“咖啡机推荐|点击查看详情”</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">正文结构:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">用户痛点(前100字明确问题)</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:某健身器材页以“90%健身者忽视的5个错误姿势”开篇,跳出率降低40%</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">解决方案(分步骤/场景化说明)</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:某母婴用品站用视频+图文展示婴儿车折叠步骤,页面分享率提高3倍</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">权威背书(数据/证书/用户评价)</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:某保健品页添加“FDA认证”图标,转化率提升18%</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px;padding: 0px;box-sizing: border-box;"><span leaf="">(</span><span style="letter-spacing: 1.3px;box-sizing: border-box;"><span leaf="">2)内容更新周期</span></span></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/53464dce6d6da5d7da8ba708bb1f400f.png" class="rich_pages wxw-img" data-ratio="0.2706855791962175" data-s="300,640" data-type="png" data-w="846" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013463"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">4. 权威信号建设:获取高质量外链</span></span></strong></p> <p style="margin: 0px;padding: 0px;box-sizing: border-box;"><span style="letter-spacing: 1.3px;box-sizing: border-box;"><span leaf="">(</span></span><span style="letter-spacing: 1.3px;box-sizing: border-box;"><span leaf="">1)安全外链获取策略</span></span></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/2d2f15ef6158e31dbd2f54f2fefc5af3.png" class="rich_pages wxw-img" data-ratio="0.3113207547169811" data-s="300,640" data-type="png" data-w="1060" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013462"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(2)高危操作黑名单</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">❌ 购买PBN(私有博客网络)外链 案例:某电商站因购买PBN链接被谷歌降权,流量暴跌70%</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">❌ 群发垃圾评论获取链接 案例:某教育机构在论坛群发链接,域名被标记为SPAM</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">❌ 使用完全匹配锚文本超50% 案例:某金融站过度优化“贷款计算器”锚文本,排名不升反降</span></p> <p style="margin: 0px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 22px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">三、执行SEO方案的六大禁忌与真实教训</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">禁忌1:关键词堆砌</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:某旅游站重复堆砌"巴厘岛酒店"15次,被算法判定过度优化,排名消失</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">解决方案:自然分布核心词(密度1.2%-1.8%),用LSI词替代</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">禁忌2:忽视移动端</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:某餐厅网站未适配移动端,60%用户3秒内跳出,谷歌排名持续下滑</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">解决方案:用Google移动友好测试工具修复问题</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">禁忌3:抄袭内容</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:某健康站复制维基百科内容,Copyscape检测重复率62%,索引被删除</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">解决方案:原创内容+AI改写检测</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">禁忌4:忽略数据反馈</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:某电商站半年未查看Search Console,后续觉得奇怪才发现500个页面未被索引</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">解决方案:设置每周数据巡检制度</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">禁忌5:闭门造车</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:某工具站未分析竞品,错失"PDF转Word"等高价值词</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">解决方案:用SEMrush分析3个竞品策略</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">禁忌6:急功近利</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:某新站1个月内发布200篇AI生成内容,被算法惩罚降权</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">解决方案:保持自然增长节奏(每周发布2-3篇优质内容)</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;white-space: normal;margin: 0px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">四、新手必备工具包与使用场景</span></span></strong></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/62a152c68bef386a208d30e3a94c831a.png" class="rich_pages wxw-img" data-ratio="0.3242603550295858" data-s="300,640" data-type="png" data-w="845" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013464"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;white-space: normal;margin: 0px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">五、30天快速启动计划与成果预期</span></span></strong></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;width: 100%;height: auto;box-sizing: border-box;" nodeleaf=""> <img src="/upload/b378fe1443b285ebf076b97a5d9f3704.png" class="rich_pages wxw-img" data-ratio="0.2964930924548353" data-s="300,640" data-type="png" data-w="941" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013469"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 22px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf=""><br></span></span></strong></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 22px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">如何利用DeepSeek深度赋能SEO优化全流程</span></span></strong></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">一、DeepSeek在SEO中的核心价值</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">DeepSeek的核心优势:通过AI大模型的语义理解与生成能力,突破传统工具瓶颈,实现效率倍增+效果突破。以下为全流程整合方案:</span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf=""><br></span></span></strong></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf=""><br></span></span></strong></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">二、分阶段深度应用指南</span></span></strong></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">1. 关键词研究:智能语义挖掘</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(1)长尾词矩阵</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">基于'咖啡机'找到4个包含场景、地域、疑问结构的搜索词 "咖啡机清洁方法 视频教程", "深圳南山咖啡机租赁服务", "如何选择适合小户型的咖啡机", "咖啡机不出蒸汽故障排查"</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">验证操作方式:</span></p> <ol style="list-style-type: decimal;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">输入核心词+需求描述(如“带地域限定”“疑问句式”)</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">导出JSON格式词表,导入SEMrush验证搜索量</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">筛选KD<40且搜索量>200的词</span></p></li> </ol> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(2)搜索意图深度解析</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:分析“咖啡机推荐”的搜索意图演变:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">DeepSeek通过分析TOP100搜索结果,发现2024年用户更关注“节能参数”(提及率+35%)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">建议内容增加“每月耗电量对比”模块</span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf=""><br></span></span></strong></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">2. 内容优化:AI驱动的高效创作</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(1)E-E-A-T增强内容生成</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">操作流程:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">输入核心词+优化指令:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">"生成关于'咖啡机清洗'的专家级指南</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">要求:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">- 包含5个常见错误清洗方法</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">- 引用SCA(精品咖啡协会)标准</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">- 插入分步骤视频脚本"</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">输出内容经人工审核后发布</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">用Copyscape检测原创性(重复率<3%)</span></p> <p style="margin: 0px;padding: 0px;box-sizing: border-box;"><span leaf="">效率对比:</span></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/b3426586b859ea56e9dda9cb3bab4b8a.png" class="rich_pages wxw-img" data-ratio="0.2727272727272727" data-s="300,640" data-type="png" data-w="429" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013468"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">3. 技术SEO:智能化诊断与修复</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(1)自动化代码优化</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">批量生成页面结构化数据</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动检测标记错误(如价格单位缺失)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(2)智能异常监测</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">实时预警系统:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">监控Search Console数据,当出现以下情况时触发警报:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">✅ 核心词排名下跌>5位 </span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">✅ 索引覆盖率下降>10%</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">✅ 移动可用性评分<90</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动生成诊断报告与修复建议</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">4. 外链建设:AI驱动的资源获取</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(1)高权重媒体挖掘</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">操作流程:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">输入行业关键词(如“咖啡器具评测”)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">DeepSeek分析TOP100文章,提取高DR媒体列表</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">生成个性化投稿邮件模板:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""> "您好[编辑姓名], </span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""> 我是[品牌]的咖啡设备专家,基于SCA标准撰写了《2024咖啡机清洁白皮书》,包含行业首创的[具体技术点]。此文已被[某协会]推荐,希望能为贵站读者提供价值..."</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">(2)外链质量评估</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">AI评分模型:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">外链质量评估维度评估指标 = </span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">"域名权威性": 0.8, # DR>60为优质 </span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">"内容相关性": 0.9, # 与本站主题匹配度 </span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">"锚文本自然度": 0.7 # 商业关键词占比<30%</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">总评分 = sum(评估指标.values()) / len(评估指标) # 0.8</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">应用场景:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动过滤毒性外链(评分<0.6)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">优先获取评分>0.85的优质外链</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">三、高阶应用:预测与策略优化</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">1. 流量预测模型</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">操作示例:输入历史数据(关键词排名/流量),DeepSeek预测:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">"优化'家用咖啡机推荐'至TOP3后: - 预计月流量增长:1200-1500 - 转化率提升范围:1.8%-2.5% - 需新增3个DR>50的外链支撑"</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">2. 算法更新应对</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">实时监控与策略调整:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">当检测到HCU(Helpful Content Update)算法更新时:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动扫描低质量内容(用户停留时间<1分钟)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">生成重写建议(增加实操案例/专家问答)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">优先更新流量下降>20%的页面</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;white-space: normal;margin: 0px;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">四、实施工具链配置建议</span></span></strong></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/a28a9f741e3fc89b09c240dfd4a9774d.png" class="rich_pages wxw-img" data-ratio="0.47586206896551725" data-s="300,640" data-type="png" data-w="580" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013470"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">五、风险控制与最佳实践</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">1. 人工审核是必须项</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">AI生成内容需通过Copyscape+人工校验</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">外链建设策略需手动确认媒体相关性</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px;padding: 0px;box-sizing: border-box;"><span leaf="">2. 效果对比案例</span></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/7eef5b277a51a807f00d045b2c2dd93f.png" class="rich_pages wxw-img" data-ratio="0.3445121951219512" data-s="300,640" data-type="png" data-w="656" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013471"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">立即行动清单:</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">使用DeepSeek生成首个长尾词库(50词起步)</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">选择3个产品页测试AI生成Schema标记</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">配置核心词排名监控预警规则</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">通过DeepSeek的深度整合,SEO团队效率可提升3-5倍,同时内容质量评分提升40%+。建议从关键词挖掘和内容生成模块优先切入,逐步构建智能化工作流。</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 22px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">DeepSeek多语言SEO优化方案</span></span></strong></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">一、突破语言边界的智能策略</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">1. 语义精准适配</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">语境感知翻译系统自动识别不同语种的表达习惯,例如:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">英语用户搜索"best budget coffee maker"时,侧重性价比参数对比</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">日本用户查询"コーヒーメーカー 省エネ"(节能咖啡机)时,强化能耗认证信息</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">阿拉伯语场景下"ماكينة قهوة بدون صوت"(静音咖啡机)需突出降噪技术说明</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">文化敏感度检测自动预警宗教禁忌与敏感历史关联词,例如:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">中东地区规避含有酒精成分的食品描述</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">东南亚市场避免使用特定动物形象图标</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">2. 多维度关键词体系</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">本地化长尾词矩阵基于地理特征生成适配词库:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">德国用户偏好技术参数:"Kaffeevollautomat mit 15 Bar Druck"(15巴压力咖啡机)</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">巴西市场关注促销信息:"cafeteira automática com desconto"(自动咖啡机折扣)</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">韩国流行趋势词:"커피메이커 신제품 리뷰"(咖啡机新品评测)</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">动态搜索趋势追踪实时监控各语言区热搜变化,例如:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">发现法语区"machine à café écologique"(环保咖啡机)搜索量月增45%</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">及时生成《欧盟环保认证咖啡机选购指南》法文版</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 22px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">二、全流程技术适配方案</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">1. 地理智能识别系统</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">IP定位优化自动推送地域适配内容:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">墨西哥用户访问时优先展示西班牙语内容</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">加拿大法语区用户获取魁北克方言优化版本</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">多语言站群架构智能配置技术要素:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动生成hreflang标签关联各语言版本</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">动态调整服务器响应时间(欧洲节点<0.8秒,亚洲节点<1.2秒)</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">2. 跨平台内容管理</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">统一内容枢纽中央控制台实现:</span></p><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">多语言内容版本对比</span></p><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动同步产品数据更新</span></p><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">批量管理50+语言元标签</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">智能翻译记忆库积累行业专属术语库:</span></p><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">医疗设备领域精准对应"MRI"与"磁共振成像"</span></p><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">法律文件保持条款表述一致性</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">三、本地化权威建设体系</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">1. 区域化外联网络</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px;padding: 0px;box-sizing: border-box;"><span leaf="">高权重平台智能匹配自动推荐各语种优质资源:</span></p></li> </ul> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/5697d809dc17755682e75fe55c4de0a5.png" class="rich_pages wxw-img" data-ratio="0.4444444444444444" data-s="300,640" data-type="png" data-w="432" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013467"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""> </span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">本地KOL合作管理建立跨国红人数据库:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动分析红人领域匹配度</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">生成个性化合作邀约模板</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">追踪合作内容传播效果</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">2. 区域性信任背书</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动生成合规文档适配各地法规要求:</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">欧盟CE认证多语言说明书</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">北美UL安全认证指南</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">中国GB国家标准解读</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">本地客户证言系统智能收集展示案例:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动抓取Google My Business多语言评价</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">生成带地理标签的成功案例库</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">四、智能监测与持续优化</span></span></strong></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">1. 多维度数据看板</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">实时流量追踪可视化展示:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">各语言版本流量占比</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">本地搜索词排名波动</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">跨语言内容转化对比</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">智能预警系统自动识别风险:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">某语种跳出率突增20%</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">特定地区索引页面异常减少</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">重要关键词排名连续下降</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">2. 动态优化建议</span></p> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">内容迭代提示基于用户行为分析:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">发现西班牙语用户偏爱视频教程</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">建议将图文指南转化为短视频</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">竞品策略透视跨国竞品监控:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">分析德国竞品的技术文档结构</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">比对中国竞品的促销话术设计</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf=""><br></span></span></strong></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">五、实施路径与效果预测</span></span></strong></p> <p style="margin: 0px;padding: 0px;box-sizing: border-box;"><span leaf="">1. 三阶段实施计划</span></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/6e95da0d468bd09c929d69260871ed44.png" class="rich_pages wxw-img" data-ratio="0.36217948717948717" data-s="300,640" data-type="png" data-w="624" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013473"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="margin: 0px;padding: 0px;box-sizing: border-box;"><span leaf="">2. 成本效率对比</span></p> </section> <section style="line-height: 0;box-sizing: border-box;"> <section style="max-width: 100%;vertical-align: middle;display: inline-block;line-height: 0;box-sizing: border-box;" nodeleaf=""> <img src="/upload/3a256f89041dee48500f2005a6320ea4.png" class="rich_pages wxw-img" data-ratio="0.3729641693811075" data-s="300,640" data-type="png" data-w="614" style="vertical-align: middle;max-width: 100%;width: 100%;box-sizing: border-box;" data-imgfileid="100013472"> </section> </section> <section style="text-align: left;box-sizing: border-box;"> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf=""><br></span></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf=""><br></span></span></strong></p> <p style="text-align: justify;margin: 0px 0px 13px;white-space: normal;padding: 0px;box-sizing: border-box;"><strong style="box-sizing: border-box;"><span style="font-size: 18px;color: rgb(0, 0, 0);box-sizing: border-box;"><span leaf="">六、成功案例实证</span></span></strong></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">案例:智能家电品牌全球化突围</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">挑战:需在6个月内实现8种语言的SEO覆盖,目标进入20国市场Top3</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">解决方案:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">生成8000+本地化长尾词库</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">自动创建适配各区域的环保认证文档</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">建立跨语言客户案例库</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">成果:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">德语区核心词排名6周进入Top5</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">阿拉伯语版本转化率超本地品牌40%</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">整体优化成本降低67%</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">行动建议:</span></p> <ul style="list-style-type: disc;box-sizing: border-box;padding-left: 40px;list-style-position: outside;" class="list-paddingleft-2"> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">启动多语言SEO智能诊断(免费生成风险报告)</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">选择3个战略市场试点AI优化方案</span></p></li> <li style="box-sizing: border-box;"><p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">预约跨国SEO架构师定制路线图</span></p></li> </ul> <p style="margin: 0px 0px 13px;padding: 0px;box-sizing: border-box;"><span leaf="">通过DeepSeek的智能系统,可突破传统多语言管理的资源瓶颈,实现全球化精准获客。从关键词到内容,从技术到运营,全方位提升。</span></p> </section> </section>
作者:微信小助手
<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 []"> <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;"><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="">RAGFlow</span></strong><span leaf=""> 是基于深度文档理解的开源RAG引擎,通过与LLM结合提供带精准引用的问答能力。支持20+文档格式解析,提供智能分块策略和混合检索方案,具备可视化干预界面,支持Docker快速部署,是企业级知识库构建的利器!</span></p> </blockquote> <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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljxzjk51k5r0aedpwtfeoyvichjplcca76mmvuud5wbkg30er9sajpgng 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="">在企业知识管理、法律文书分析、学术研究等场景中,我们常面临三大痛点:</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="">AI问答存在"幻觉"风险</span> </section></li> </ol> <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/f79b049d88d0a69c31e2ed3aaad89462.jpg" class="rich_pages wxw-img" data-ratio="0.562962962962963" data-type="jpeg" 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="100007162"></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="">RAGFlow 正是为解决这些问题而生!</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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljxzjk51k5r0aedpwtfeoyvichjplcca76mmvuud5wbkg30er9sajpgng 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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljiicg8iccbcdl8vbgcoeokkwc2p3jq31drvgjvzyf0fhvwkrybyv7peqg 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> <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="">支持格式:PDF/DOCX/PPT/XLSX/JPG等20+常见格式</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><span leaf=""><br></span><span leaf="">✅ 表格数据结构化提取</span><span leaf=""><br></span><span leaf="">✅ 数学公式Latex格式保留</span><span leaf=""><br></span><span leaf="">✅ 图片OCR文字识别</span><span leaf=""><br></span><span leaf="">✅ 多栏排版智能重组</span> </section></li> </ul> <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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljiicg8iccbcdl8vbgcoeokkwc2p3jq31drvgjvzyf0fhvwkrybyv7peqg 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> <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 wzjhlvpsrd3ef7sqnh3uco6zmibsqgacdibndmqyq0wsy2p7k3aseainqjjiqli4tf4mic0nhvrnt5acljmblnjflsxotf9tckh 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=""># 分块配置示例(yaml格式)</span></span><span leaf=""><br></span><span leaf="">chunk:</span><span leaf=""><br></span><span leaf=""> splitter: </span><span style="color: #98c379;line-height: 26px;"><span leaf="">"smart"</span></span><span leaf=""><br></span><span leaf=""> max_length: </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">512</span></span><span leaf=""><br></span><span leaf=""> overlap: </span><span style="color: #d19a66;line-height: 26px;"><span leaf="">64</span></span><span leaf=""><br></span><span leaf=""> image_caption: true</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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljiicg8iccbcdl8vbgcoeokkwc2p3jq31drvgjvzyf0fhvwkrybyv7peqg 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> <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="">语义检索(Embedding模型)</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="">关键词检索(BM25算法)</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> <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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljiicg8iccbcdl8vbgcoeokkwc2p3jq31drvgjvzyf0fhvwkrybyv7peqg 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> <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 wzjhlvpsrd3ef7sqnh3uco6zmibsqgacdibndmqyq0wsy2p7k3aseainqjjiqli4tf4mic0nhvrnt5acljmblnjflsxotf9tckh 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 leaf="">docker compose -f docker/docker-compose.yml up -d</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="">支持CPU/GPU环境,最小4核CPU+16GB内存即可运行</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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljxzjk51k5r0aedpwtfeoyvichjplcca76mmvuud5wbkg30er9sajpgng 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> <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="">Apache Tika+自定义解析器</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="">向量数据库</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="">Elasticsearch 8.x</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="">对象存储</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="">MinIO</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="">任务调度</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="">Celery</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="">前端框架</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="">React+Ant Design</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> <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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljxzjk51k5r0aedpwtfeoyvichjplcca76mmvuud5wbkg30er9sajpgng 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="">相较于同类项目,RAGFlow 具备以下优势:</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="">RAGFlow</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="">LangChain</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="">LlamaIndex</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="">✅ 20+格式深度解析</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="">分块策略</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="">检索方案</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="">可视化干预</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="">企业级特性</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> <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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljxzjk51k5r0aedpwtfeoyvichjplcca76mmvuud5wbkg30er9sajpgng 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> <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="">LangChain</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="">LlamaIndex</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="">Haystack</span></strong><span leaf="">:工业级NLP管道框架,适合复杂业务场景</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="">Milvus</span></strong><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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljxzjk51k5r0aedpwtfeoyvichjplcca76mmvuud5wbkg30er9sajpgng 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> <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/e8ef8e26adcef33c7ca70b283f5d9e00.png" class="rich_pages wxw-img" data-ratio="0.5509259259259259" 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="100007158"></span> </figure> <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/a2776b3d8a660cad1a22af5db5454c40.png" class="rich_pages wxw-img" data-ratio="0.5472222222222223" 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="100007159"></span> </figure> <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/697fc889afc83c92f86fda63ec81a8ee.png" class="rich_pages wxw-img" data-ratio="0.5453703703703704" 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="100007160"></span> </figure> <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/42ee2843d97612c2bf02d05d5e7ef6be.png" class="rich_pages wxw-img" data-ratio="0.5462962962962963" 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="100007167"></span> </figure> <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/ae1eb9b1e7caad61392c9f2fea608dda.png" class="rich_pages wxw-img" data-ratio="0.5444444444444444" 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="100007166"></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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljxzjk51k5r0aedpwtfeoyvichjplcca76mmvuud5wbkg30er9sajpgng 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="">"当大模型遇上深度文档解析,RAGFlow 用结构化思维重新定义知识管理——支持20+格式智能解析、混合检索增强、可视化干预,让企业级知识库搭建像搭积木一样简单!"</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 mmbiz_png mrgvnruiwydfpgqx7myyyzbimhibrggljxzjk51k5r0aedpwtfeoyvichjplcca76mmvuud5wbkg30er9sajpgng 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="">https://github.com/infiniflow/ragflow</span></p> </section>
作者:微信小助手
<section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="margin-bottom: 0px;padding-left: 10px;padding-right: 10px;background-attachment: scroll;background-clip: border-box;background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 0%, rgba(0, 0, 0, 0) 6.76%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 0%, rgba(249, 247, 252, 0) 9.46%);background-origin: padding-box;background-position: 0% 0%;background-repeat: repeat, repeat;background-size: 20px 20px, 20px 20px;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;text-align: left; data-pm-slice="0 0 []"> <section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="padding-left: 3px;padding-right: 3px;background-attachment: scroll;background-clip: border-box;background-image: none;background-origin: padding-box;background-position: 0% 0%;background-repeat: no-repeat;background-size: auto;width: auto;font-family: PingFangSC-regular, sans-serif;line-height: 1.5em;word-spacing: 0em;letter-spacing: 0em;word-break: break-word;"> <figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;"> <span leaf=""><br></span> </figure> </section> <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: 3px;padding-right: 3px;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: PingFangSC-regular, sans-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 []"> <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 class="rich_pages wxw-img" data-imgfileid="100006653" data-ratio="0.4398148148148148" src="/upload/4380045967d6dfff690d442eb8aa5c48.png" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">在当今数字化时代,AI技术已经渗透到我们生活的方方面面,无论是内容创作、教育学习,还是市场营销,AI都发挥着巨大的作用。然而,对于许多AI使用者来说,如何高效地管理、优化和分享AI提示词,一直是一个令人头疼的问题。今天,我要给大家介绍一款专为AI提示词管理设计的工具——PromptPro。它不仅能帮助你高效管理提示词,还能让你的AI创作更加得心应手。</span></p> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">PromptPro:AI创作的得力助手</span></span><span style="display: none;"></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">PromptPro是一款专为AI提示词管理设计的工具,它的使命是通过简化提示词管理流程,让AI创作更加高效、直观和易于使用。</span></strong><span leaf="">无论你是AI创作爱好者,还是专业的内容创作者,PromptPro都能帮助你将创意转化为高质量的AI输出。它提供了本地存储和云端备份功能,支持文件夹和标签系统进行分类管理,版本控制记录每次修改,确保你的提示词库井井有条且随时可用。</span></p> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;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> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro采用前后端分离架构,这种架构设计不仅提高了系统的灵活性和可扩展性,还为用户带来了更流畅的使用体验。</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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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="">:基于Vue 3 + TypeScript的单页应用,使用IndexedDB实现本地数据存储。这种设计不仅保证了数据的安全性,还让应用能够在离线状态下正常运行。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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="">:Node.js + Express构建的RESTful API服务,提供云备份和提示词共享功能。后端使用MySQL作为数据库,确保数据的持久化存储。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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="">:集成OpenAI API实现提示词测试和优化,让你能够实时测试和优化你的提示词,确保它们能够产生最佳的AI输出。</span> </section></li> </ul> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;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> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro的数据管理流程非常严谨,无论是本地数据管理还是云备份,都经过精心设计,确保数据的安全性和一致性。</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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <p style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">:数据通过Pinia状态管理,Vue3组件响应式更新,确保用户界面的实时性和准确性。创建、编辑提示词的操作都会经过严格的本地存储流程,确保数据的完整性和安全性。<img class="rich_pages wxw-img" data-imgfileid="100006651" data-ratio="0.7916666666666666" src="/upload/df5dc4af50b5c31bf5c68fad492e9b9a.png" data-type="png" data-w="1080" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;"></span></p> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <p style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">:数据通过HTTPS加密传输,使用预处理语句防止SQL注入,确保数据在传输和存储过程中的安全性。用户可以随时请求云备份,备份数据会存储在MySQL数据库中,并返回备份ID,方便用户随时恢复数据。<img src="/upload/c37a45966165fdd98d7f1aee01d69f21.png" class="rich_pages wxw-img" data-ratio="0.6583333333333333" data-type="png" data-w="1080" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;" data-imgfileid="100006652"></span></p> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <p style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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="">:生成唯一的32位分享码,用户可以通过复制分享链接或二维码,将提示词分享给他人。分享的提示词会存储在MySQL数据库中,并返回分享码,确保分享过程的安全性和便捷性。<img src="/upload/7bda5c590a51ea85452a49d72801ba27.png" class="rich_pages wxw-img" data-ratio="0.7138888888888889" data-type="png" data-w="1080" style="display: block;margin-top: 0px;margin-right: auto;margin-bottom: 0px;margin-left: auto;max-width: 100%;" data-imgfileid="100006650"></span></p> </section></li> </ul> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;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> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro的前端采用了现代化的技术栈,确保了应用的高性能和良好的用户体验。</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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">框架:Vue 3 + TypeScript</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">UI库:Arco Design</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">状态管理:Pinia</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">本地存储:IndexedDB</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">路由:Vue Router</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">HTTP客户端:Axios</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">PWA支持:Vite PWA插件</span> </section></li> </ul> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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> <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 ijdpq631cvfpzevp7c96gfmjqygv5gmedjbvbunfkezfs4jpypiaufeo4ferun1nl7e13p1etekfxobsfngexn7folibrpfoian 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="">src/</span><span leaf=""><br></span><span leaf="">├── assets/ # 静态资源</span><span leaf=""><br></span><span leaf="">├── components/ # 通用组件</span><span leaf=""><br></span><span leaf="">├── composables/ # 可复用逻辑</span><span leaf=""><br></span><span leaf="">├── config/ # 配置文件</span><span leaf=""><br></span><span leaf="">├── db/ # IndexedDB管理</span><span leaf=""><br></span><span leaf="">├── router/ # 路由配置</span><span leaf=""><br></span><span leaf="">├── store/ # 状态管理</span><span leaf=""><br></span><span leaf="">├── utils/ # 工具函数</span><span leaf=""><br></span><span leaf="">├── views/ # 页面组件</span><span leaf=""><br></span><span leaf="">└── App.vue # 根组件</span><span leaf=""><br></span></code></pre> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;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> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">运行环境:Node.js</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">Web框架:Express</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">数据库:MySQL</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">ORM:原生SQL (mysql2/promise)</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">身份验证:简单的邮箱+密钥认证</span> </section></li> </ul> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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> <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 ijdpq631cvfpzevp7c96gfmjqygv5gmedjbvbunfkezfs4jpypiaufeo4ferun1nl7e13p1etekfxobsfngexn7folibrpfoian 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="">server/</span><span leaf=""><br></span><span leaf="">├── index.js # 入口文件</span><span leaf=""><br></span><span leaf="">├── db.js # 数据库连接</span><span leaf=""><br></span><span leaf="">├── routes/ # 路由定义</span><span leaf=""><br></span><span leaf="">│ ├── backups.js # 备份相关路由</span><span leaf=""><br></span><span leaf="">│ └── prompts.js # 提示词相关路由</span><span leaf=""><br></span><span leaf="">└── .env # 环境变量</span><span leaf=""><br></span></code></pre> <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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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="">API路由</span></strong><span leaf="">:提供了丰富的API接口,支持提示词的创建、获取、更新和删除操作,以及备份的管理功能。</span> </section></li> </ul> <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/f09c052a6b05eca4c0825f9c25cf3b7a.png" class="rich_pages wxw-img" data-ratio="0.15" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006649"></span> </figure> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;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> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro的数据模型设计非常清晰,无论是前端的IndexedDB还是后端的MySQL,都为数据的存储和管理提供了强大的支持。</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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">PROMPT:存储用户创建的所有提示词模板。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">FOLDER:提供分类管理提示词的结构。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">VERSION:记录提示词的修改历史。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">TAG:用于快速检索和分类提示词。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">SETTINGS:用户偏好设置,如界面主题、显示选项等。</span> </section></li> </ul> </ul> <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/899df2585662d0c4c9acb63876b1f47d.jpg" class="rich_pages wxw-img" data-ratio="1.0157407407407408" data-type="jpeg" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006656"></span> </figure> <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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">CLOUD_BACKUPS:存储用户的备份数据,通过email和access_key进行身份验证。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">SHARED_PROMPTS:存储用户分享的提示词,可通过share_code进行访问。</span> </section></li> </ul> </ul> <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/2d6c942f7c8c7810fb8344b1bb61466f.jpg" class="rich_pages wxw-img" data-ratio="0.9583333333333334" data-type="jpeg" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006657"></span> </figure> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;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> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro非常注重数据的安全性,无论是云备份还是提示词分享,都采用了严格的安全措施。</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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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="">:所有数据通过HTTPS加密传输,确保数据在传输过程中的安全性。</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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="">SQL注入防护</span></strong><span leaf="">:使用预处理语句防止SQL注入,确保数据库的安全性。</span> </section></li> </ul> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;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> <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/4847e4f901cc0d60c0d51555f2ebcf92.png" class="rich_pages wxw-img" data-ratio="0.8314814814814815" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006658"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro提供了多种部署选项,无论是个人用户还是团队用户,都能找到适合自己的部署方案。</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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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="">:适合生产环境,前端静态资源部署在CDN或静态文件服务器,后端API服务部署在独立服务器集群,数据库部署在专用数据库服务器或使用云数据库服务。</span> </section></li> </ul> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;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> <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/5cba9200f47cac3ff82716963d770c4c.png" class="rich_pages wxw-img" data-ratio="0.46296296296296297" 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: 0px;border-top-right-radius: 0px;border-bottom-right-radius: 0px;border-bottom-left-radius: 0px;object-fit: fill;box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px;" data-imgfileid="100006655"></span> </figure> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro提供了多种数据同步选项,确保用户能够在不同设备上无缝使用提示词库。</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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">PWA支持:类原生应用体验</span></span><span style="display: none;"></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro支持PWA(Progressive Web Apps),通过Workbox实现了一系列强大的功能。</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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <strong style="color: rgb(239, 112, 96);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> <h3 data-tool="mdnice编辑器" style="border-top-color: rgb(33, 33, 34);margin-top: 30px;margin-bottom: 15px;margin-left: 0px;margin-right: 0px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;border-bottom-width: 2px;border-left-width: 1px;border-right-width: 1px;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;height: auto;justify-content: unset;line-height: 1.5em;overflow-x: unset;overflow-y: unset;padding-top: 0px;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;text-align: left;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span style="display: none;"></span><span style="font-size: 18px;color: rgb(13, 13, 13);border-top-color: rgb(34, 34, 34);line-height: 1.8em;letter-spacing: 0em;padding-top: 4px;padding-bottom: 0px;padding-left: 6px;padding-right: 6px;align-items: unset;background-attachment: scroll;background-clip: border-box;background-color: unset;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: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 2px;border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;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;font-weight: bold;flex-direction: unset;float: unset;height: auto;justify-content: unset;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;overflow-x: unset;overflow-y: unset;text-align: left;text-indent: 0em;text-shadow: none;transform: none;width: auto;-webkit-box-reflect: unset;"><span leaf="">总结:高效、灵活、安全的AI提示词管理工具</span></span><span style="display: none;"></span></h3> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro是一款高效、灵活且安全的AI提示词管理工具。它通过现代化的前后端分离架构、严谨的数据管理流程、强大的PWA支持和灵活的部署选项,为用户带来了前所未有的AI创作体验。PromptPro不仅能够帮助你高效管理提示词,还能让你的AI创作更加得心应手。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">无论是个人用户还是团队用户,PromptPro都能满足你的需求。它支持多端使用,让你能够在不同设备上同步和使用提示词库;它保障数据安全,通过简单高效的认证机制保护你的个人数据;它共建提示词生态,通过公开分享功能让用户之间交流优质提示词。</span></p> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><span leaf="">PromptPro,是你AI创作的得力助手,快来体验一下吧!</span></p> <hr 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;border-top-style: solid;border-bottom-style: none;border-left-style: none;border-right-style: none;border-top-width: 1px;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: 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: 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: 1px;"> <p data-tool="mdnice编辑器" style="color: rgb(0, 0, 0);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;text-indent: 0em;margin-top: 0px;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;padding-top: 8px;padding-bottom: 8px;padding-left: 0px;padding-right: 0px;"><strong style="color: rgb(239, 112, 96);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></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: 20px;padding-right: 0px;color: rgb(0, 0, 0);" class="list-paddingleft-1"> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">https://prompt.orence.net/welcome</span> </section></li> <li> <section style="margin-top: 5px;margin-bottom: 5px;color: rgb(1, 1, 1);font-size: 15px;line-height: 2.1em;letter-spacing: 0.02em;text-align: left;font-weight: normal;"> <span leaf="">https://prompt.orence.net/app</span> </section></li> </ul> </section> </section>