{"id":10021060,"date":"2025-10-30T20:19:43","date_gmt":"2025-10-30T12:19:43","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021060"},"modified":"2025-10-30T20:19:43","modified_gmt":"2025-10-30T12:19:43","slug":"rag-chunking%e7%ad%96%e7%95%a5%e5%ae%9e%e6%88%98%ef%bd%9c%e5%be%97%e7%89%a9%e6%8a%80%e6%9c%af","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021060","title":{"rendered":"RAG\u2014Chunking\u7b56\u7565\u5b9e\u6218\uff5c\u5f97\u7269\u6280\u672f"},"content":{"rendered":"<hr>\n<h2>\u4e00\u3001\u80cc \u666f<\/h2>\n<p>\u5728 RAG \u7cfb\u7edf\u4e2d\uff0c\u5373\u4fbf\u91c7\u7528\u6027\u80fd\u5353\u8d8a\u7684 LLM \u5e76\u53cd\u590d\u6253\u78e8 Prompt\uff0c\u95ee\u7b54\u4ecd\u53ef\u80fd\u51fa\u73b0\u4e0a\u4e0b\u6587\u7f3a\u5931\u3001\u4e8b\u5b9e\u6027\u9519\u8bef\u6216\u62fc\u63a5\u4e0d\u8fde\u8d2f\u7b49\u95ee\u9898\u3002\u591a\u6570\u56e2\u961f\u4f1a\u9891\u7e41\u66f4\u6362\u68c0\u7d22\u7b97\u6cd5\u4e0e Embedding\u6a21\u578b\uff0c\u4f46\u6536\u76ca\u5e38\u5e38\u6709\u9650\u3002\u771f\u6b63\u7684\u74f6\u9888\uff0c\u5f80\u5f80\u6f5c\u4f0f\u5728\u6570\u636e\u5165\u5e93\u4e4b\u524d\u7684\u4e00\u4e2a\u7ec6\u8282\u2014\u2014\u6587\u6863\u5206\u5757\uff08chunking\uff09\u3002\u4e0d\u5f53\u7684\u5206\u5757\u4f1a\u7834\u574f\u8bed\u4e49\u8fb9\u754c\uff0c\u62c6\u6563\u5173\u952e\u7ebf\u7d22\u5e76\u4e0e\u566a\u58f0\u7ea0\u7f20\uff0c\u4f7f\u88ab\u68c0\u7d22\u7684\u7247\u6bb5\u5448\u73b0\u201c\u987a\u5e8f\u9519\u4e71\u3001\u4fe1\u606f\u6b8b\u7f3a\u201d\u7684\u9762\u8c8c\u3002\u5728\u8fd9\u6837\u7684\u8f93\u5165\u4e0b\uff0c\u518d\u5f3a\u5927\u7684\u6a21\u578b\u4e5f\u96be\u4ee5\u57fa\u4e8e\u652f\u79bb\u7834\u788e\u7684\u77e5\u8bc6\u63a8\u7406\u51fa\u5b8c\u6574\u3001\u53ef\u9760\u7684\u7b54\u6848\u3002\u67d0\u79cd\u610f\u4e49\u4e0a\uff0c\u5206\u5757\u8d28\u91cf\u51e0\u4e4e\u51b3\u5b9a\u4e86RAG\u7684\u6027\u80fd\u4e0a\u9650\u2014\u2014\u5b83\u51b3\u5b9a\u77e5\u8bc6\u662f\u4ee5\u8fde\u8d2f\u7684\u4e0a\u4e0b\u6587\u5448\u73b0\uff0c\u8fd8\u662f\u9000\u5316\u4e3a\u65e0\u6cd5\u62fc\u5408\u7684\u788e\u7247\u3002<\/p>\n<p>\u5728\u5b9e\u9645\u573a\u666f\u4e2d\uff0c\u6700\u5e38\u89c1\u7684\u9519\u8bef\u662f\u6309\u56fa\u5b9a\u957f\u5ea6\u751f\u786c\u5207\u5272\uff0c\u5ffd\u7565\u6587\u6863\u7684\u7ed3\u6784\u4e0e\u8bed\u4e49\uff1a\u5b9a\u4e49\u4e0e\u4fe1\u606f\u88ab\u5207\u5f00\u3001\u8868\u5934\u4e0e\u6570\u636e\u5206\u79bb\u3001\u6b65\u9aa4\u8bf4\u660e\u88ab\u622a\u65ad\u3001\u4ee3\u7801\u4e0e\u6ce8\u91ca\u8131\u8282\uff0c\u7ed3\u679c\u5c31\u662f\u53ec\u56de\u547d\u4e2d\u5374\u65e0\u6cd5\u652f\u6491\u7ed3\u8bba\uff0c\u751a\u81f3\u8bf1\u53d1\u5e7b\u89c9\u4e0e\u9519\u8bef\u5f15\u7528\u3002\u76f8\u53cd\uff0c\u9ad8\u8d28\u91cf\u7684\u5206\u5757\u5e94\u5c3d\u91cf\u8d34\u5408\u81ea\u7136\u8fb9\u754c\uff08\u6807\u9898\u3001\u6bb5\u843d\u3001\u5217\u8868\u3001\u8868\u683c\u3001\u4ee3\u7801\u5757\u7b49\uff09\uff0c\u4ee5\u9002\u5ea6\u91cd\u53e0\u4fdd\u6301\u4e0a\u4e0b\u6587\u8fde\u7eed\uff0c\u5e76\u4fdd\u7559\u5fc5\u8981\u7684\u6765\u6e90\u4e0e\u7ae0\u8282\u5143\u6570\u636e\uff0c\u786e\u4fdd\u53ef\u8ffd\u6eaf\u4e0e\u91cd\u6392\u53ef\u7528\u3002\u5f53\u5206\u5757\u5c0a\u91cd\u6587\u6863\u7684\u53d9\u4e8b\u4e0e\u7ed3\u6784\u65f6\uff0c\u68c0\u7d22\u7684\u76f8\u5173\u6027\u4e0e\u7b54\u6848\u7684\u4e8b\u5b9e\u4e00\u81f4\u6027\u5f80\u5f80\u663e\u8457\u63d0\u5347\uff0c\u8fdc\u80dc\u4e8e\u4e00\u5473\u66f4\u6362\u5411\u91cf\u6a21\u578b\u6216\u8c03\u53c2\uff1b\u6362\u8a00\u4e4b\uff0c\u60f3\u8981\u771f\u6b63\u6539\u5584 RAG \u7684\u7a33\u5065\u6027\u4e0e\u4e0a\u9650\uff0c\u9996\u5148\u8981\u628a\u201c\u77e5\u8bc6\u5982\u4f55\u88ab\u5207\u5f00\u5e76\u5448\u73b0\u7ed9\u6a21\u578b\u201d\u8fd9\u4ef6\u4e8b\u505a\u597d\u3002<\/p>\n<p><strong>PS\uff1a\u672c\u6587\u4e3b\u8981\u662f\u9488\u5bf9\u4e2d\u6587\u6587\u6863\u7c7b\u578b\u7684\u5d4c\u5165\u8fdb\u884c\u5b9e\u6218\u3002<\/strong><\/p>\n<h2>\u4e8c\u3001\u4ec0\u4e48\u662f\u5206\u5757\uff08Chunking\uff09<\/h2>\n<p>\u5206\u5757\u662f\u5c06\u5927\u5757\u6587\u672c\u5206\u89e3\u6210\u8f83\u5c0f\u6bb5\u843d\u7684\u8fc7\u7a0b\uff0c\u8fd9\u4f7f\u5f97\u6587\u672c\u6570\u636e\u66f4\u6613\u4e8e\u7ba1\u7406\u548c\u5904\u7406\u3002\u901a\u8fc7\u5206\u5757\uff0c\u6211\u4eec\u80fd\u591f\u66f4\u9ad8\u6548\u5730\u8fdb\u884c\u5185\u5bb9\u5d4c\u5165\uff08embedding\uff09\uff0c\u5e76\u663e\u8457\u63d0\u5347\u4ece\u5411\u91cf\u6570\u636e\u5e93\u4e2d\u53ec\u56de\u5185\u5bb9\u7684\u76f8\u5173\u6027\u548c\u51c6\u786e\u6027\u3002<\/p>\n<p>\u5728\u5b9e\u9645\u64cd\u4f5c\u4e2d\uff0c\u5206\u5757\u7684\u597d\u5904\u662f\u591a\u65b9\u9762\u7684\u3002\u9996\u5148\uff0c\u5b83\u80fd\u591f\u63d0\u9ad8\u6a21\u578b\u5904\u7406\u7684\u6548\u7387\uff0c\u56e0\u4e3a\u8f83\u5c0f\u7684\u6587\u672c\u6bb5\u843d\u66f4\u5bb9\u6613\u8fdb\u884c\u5d4c\u5165\u548c\u68c0\u7d22\u3002<\/p>\n<p>\u5176\u6b21\uff0c\u5206\u5757\u540e\u7684\u6587\u672c\u80fd\u591f\u66f4\u7cbe\u786e\u5730\u5339\u914d\u7528\u6237\u67e5\u8be2\uff0c\u4ece\u800c\u63d0\u4f9b\u66f4\u76f8\u5173\u7684\u641c\u7d22\u7ed3\u679c\u3002\u8fd9\u5bf9\u4e8e\u9700\u8981\u9ad8\u7cbe\u5ea6\u4fe1\u606f\u68c0\u7d22\u548c\u5185\u5bb9\u751f\u6210\u7684\u5e94\u7528\u7a0b\u5e8f\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n<p>\u901a\u8fc7\u4f18\u5316\u5185\u5bb9\u7684\u5206\u5757\u548c\u5d4c\u5165\u7b56\u7565\uff0c\u6211\u4eec\u53ef\u4ee5\u6700\u5927\u5316LLM\u5728\u5404\u79cd\u5e94\u7528\u573a\u666f\u4e2d\u7684\u6027\u80fd\u3002\u5206\u5757\u6280\u672f\u4e0d\u4ec5\u63d0\u9ad8\u4e86\u5185\u5bb9\u53ec\u56de\u7684\u51c6\u786e\u6027\uff0c\u8fd8\u63d0\u5347\u4e86\u6574\u4f53\u7cfb\u7edf\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u5728\u6784\u5efa\u548c\u4f18\u5316\u57fa\u4e8eLLM\u7684\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u7406\u89e3\u548c\u5e94\u7528\u5206\u5757\u6280\u672f\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u6b65\u9aa4\u3002<\/p>\n<p>\u5206\u5757\u8fc7\u7a0b\u4e2d\u4e3b\u8981\u7684\u4e24\u4e2a\u6982\u5ff5\uff1achunk\/_size\u5757\u7684\u5927\u5c0f\uff0cchunk\/_overlap\u91cd\u53e0\u7a97\u53e3\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"141\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdmSiQ\" alt=\"image.png\" title=\"image.png\"><\/p>\n<h2>\u4e09\u3001\u4e3a\u4f55\u8981\u5bf9\u5185\u5bb9\u505a\u5206\u5757\u5904\u7406<\/h2>\n<ul>\n<li><strong>\u6a21\u578b\u4e0a\u4e0b\u6587\u7a97\u53e3\u9650\u5236<\/strong>\uff1aLLM\u65e0\u6cd5\u4e00\u6b21\u5904\u7406\u8d85\u957f\u6587\u672c\u3002\u5206\u5757\u7684\u76ee\u7684\u5728\u4e8e\u5c06\u957f\u6587\u6863\u5207\u6210\u6a21\u578b\u53ef\u7a33\u5b9a\u5904\u7406\u7684\u4e2d\u7b49\u7c92\u5ea6\u7247\u6bb5\uff0c\u5e76\u5c3d\u91cf\u5bf9\u9f50\u81ea\u7136\u8bed\u4e49\u8fb9\u754c\uff08\u5982\u6807\u9898\u3001\u6bb5\u843d\u3001\u53e5\u5b50\u3001\u4ee3\u7801\u5757\uff09\uff0c\u907f\u514d\u786c\u5207\u5bfc\u81f4\u5173\u952e\u4fe1\u606f\u88ab\u622a\u65ad\u6216\u8bed\u4e49\u6f02\u79fb\u3002\u5373\u4fbf\u4f7f\u7528\u957f\u4e0a\u4e0b\u6587\u6a21\u578b\uff0c\u8fc7\u957f\u8f93\u5165\u4e5f\u4f1a\u63a8\u9ad8\u6210\u672c\u5e76\u7a00\u91ca\u4fe1\u606f\u5bc6\u5ea6\uff0c\u5408\u7406\u5206\u5757\u4ecd\u662f\u5fc5\u9700\u7684\u524d\u7f6e\u7ea6\u675f\u3002<br \/>*<\/li>\n<li><strong>\u68c0\u7d22\u7684\u4fe1\u566a\u6bd4<\/strong>\uff1a\u5757\u8fc7\u5927\u65f6\u65e0\u5173\u5185\u5bb9\u4f1a\u7a00\u91ca\u4fe1\u53f7\u3001\u964d\u4f4e\u76f8\u4f3c\u5ea6\u5224\u522b\u529b\uff1b\u5757\u8fc7\u5c0f\u65f6\u8bed\u5883\u4e0d\u8db3\u3001\u5bb9\u6613\u201c\u53ea\u547d\u4e2d\u8bcd\u4e0d\u547d\u4e2d\u4e49\u201d\u3002\u5408\u9002\u7684\u5757\u7c92\u5ea6\u53ef\u5728\u53ec\u56de\u4e0e\u7cbe\u5ea6\u95f4\u53d6\u5f97\u66f4\u597d\u5e73\u8861\uff0c\u65e2\u8986\u76d6\u7528\u6237\u610f\u56fe\uff0c\u53c8\u4e0d\u5f15\u5165\u591a\u4f59\u566a\u58f0\u3002\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u63d0\u5347\u68c0\u7d22\u76f8\u5173\u6027\u7684\u540c\u65f6\u53c8\u80fd\u4fdd\u8bc1\u7ed3\u679c\u7a33\u5b9a\u6027\u3002<br \/>*<\/li>\n<li><strong>\u8bed\u4e49\u8fde\u7eed\u6027<\/strong>\uff1a\u8de8\u6bb5\u843d\u6216\u8de8\u7ae0\u8282\u7684\u8bed\u4e49\u5173\u7cfb\u5e38\u5728\u8fb9\u754c\u5904\u88ab\u5207\u65ad\u3002\u901a\u8fc7\u8bbe\u7f6e\u9002\u5ea6\u7684 chunk\/_overlap\uff0c\u53ef\u4fdd\u7559\u8de8\u5757\u7ebf\u7d22\u3001\u51cf\u5c11\u5173\u952e\u5b9a\u4e49\/\u6761\u4ef6\u88ab\u201c\u5207\u5f00\u201d\u7684\u98ce\u9669\u3002\u5bf9\u4e8e\u5f3a\u7ed3\u6784\u6587\u6863\uff0c\u4f18\u5148\u8ba9\u8fb9\u754c\u8d34\u5408\u6807\u9898\u5c42\u7ea7\u4e0e\u53e5\u5b50\u65ad\u70b9\uff1b\u5fc5\u8981\u65f6\u5728\u68c0\u7d22\u9636\u6bb5\u505a\u8f7b\u91cf\u90bb\u8fd1\u6269\u5c55\uff0c\u4ee5\u63d0\u5347\u7b54\u6848\u7684\u8fde\u8d2f\u6027\u4e0e\u53ef\u8ffd\u6eaf\u6027\uff0c\u540c\u65f6\u907f\u514d\u91cd\u590d\u5185\u5bb9\u6324\u5360\u4e0a\u4e0b\u6587\u9884\u7b97\u3002<\/li>\n<\/ul>\n<p>\u603b\u4e4b\u7406\u60f3\u7684\u5206\u5757\u662f\u5728\u201c\u4e0a\u4e0b\u6587\u5b8c\u6574\u6027\u201d\u548c\u201c\u4fe1\u606f\u5bc6\u5ea6\u201d\u4e4b\u95f4\u53d6\u5f97\u52a8\u6001\u5e73\u8861\uff1achunk\/_size\u51b3\u5b9a\u4fe1\u606f\u627f\u8f7d\u91cf\uff0cchunk\/_overlap \u7528\u4e8e\u5f25\u8865\u8fb9\u754c\u65ad\u88c2\u5e76\u7ef4\u6301\u8bed\u4e49\u8fde\u7eed\u3002\u53ea\u8981\u8fb9\u754c\u5bf9\u9f50\u8bed\u4e49\u3001\u7c92\u5ea6\u8d34\u5408\u5185\u5bb9\uff0c\u68c0\u7d22\u4e0e\u751f\u6210\u7684\u8d28\u91cf\u5c31\u80fd\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"289\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdmSiR\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<h2>\u56db\u3001\u5206\u5757\u7b56\u7565\u8be6\u89e3<\/h2>\n<h2>4.1 \u57fa\u7840\u5206\u5757<\/h2>\n<p><strong>\u57fa\u4e8e\u56fa\u5b9a\u957f\u5ea6\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong>\uff1a\u6309\u9884\u8bbe\u5b57\u7b26\u6570 chunk\/_size \u76f4\u63a5\u5207\u5206\uff0c\u4e0d\u8003\u8651\u6587\u672c\u7ed3\u6784\u3002<\/li>\n<li><strong>\u4f18\u70b9<\/strong>\uff1a\u5b9e\u73b0\u6700\u7b80\u5355\u3001\u901f\u5ea6\u5feb\u3001\u5bf9\u4efb\u610f\u6587\u672c\u901a\u7528\u3002<\/li>\n<li><strong>\u7f3a\u70b9<\/strong>\uff1a\u5bb9\u6613\u7834\u574f\u8bed\u4e49\u8fb9\u754c\uff1b\u5757\u8fc7\u5927\u5bb9\u6613\u5f15\u5165\u8f83\u591a\u566a\u58f0\uff0c\u8fc7\u5c0f\u5219\u4f1a\u5bfc\u81f4\u4e0a\u4e0b\u6587\u4e0d\u8db3\u3002<\/li>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u7ed3\u6784\u6027\u5f31\u7684\u7eaf\u6587\u672c\uff0c\u6216\u6570\u636e\u9884\u5904\u7406\u521d\u671f\u7684\u57fa\u7ebf\u65b9\u6848\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>from langchain_text_splitters import CharacterTextSplitter\n\n\nsplitter = CharacterTextSplitter(\n    separator=&quot;&quot;,        # \u7eaf\u6309\u957f\u5ea6\u5207\n    chunk_size=600,      # \u4f9d\u636e\u5b9e\u9a8c\u4e0e\u6a21\u578b\u4e0a\u9650\u8c03\u6574\n    chunk_overlap=90,    # 15% \u91cd\u53e0\n)\nchunks = splitter.split_text(text)\n<\/code><\/pre>\n<ul>\n<li><strong>\u53c2\u6570\u5efa\u8bae\uff08\u4ec5\u9650\u4e2d\u6587\u8bed\u6599\u5efa\u8bae\uff09<\/strong> \uff1a<\/li>\n<li>\n<ul>\n<li>chunk\/_size\uff1a300\u2013800 \u5b57\u4f18\u5148\u5c1d\u8bd5\uff1b\u82e5\u5d4c\u5165\u6a21\u578b\u6700\u4f73\u8f93\u5165\u4e3a 512\/1024 tokens\uff0c\u53ef\u6298\u7b97\u4e3a\u7ea6 350\/700 \u4e2d\u6587\u5b57\u7b26\u8d77\u6b65\u3002<\/li>\n<li>chunk\/_overlap\uff1a10%\u201320% \u8d77\u6b65\uff1b\u8d85\u8fc7 30% \u901a\u5e38\u5bfc\u81f4\u7d22\u5f15\u4f53\u79ef\u4e0e\u68c0\u7d22\u5f00\u9500\u663e\u8457\u4e0a\u5347\uff0c\u5bf9\u5b9e\u9645\u6027\u80fd\u8d77\u8d1f\u4f5c\u7528\uff0c\u6700\u540e\u7684\u6548\u679c\u5e76\u4e0d\u4f1a\u5f97\u5230\u660e\u663e\u63d0\u5347\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u57fa\u4e8e\u53e5\u5b50\u7684\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong>\uff1a\u5148\u6309\u53e5\u5b50\u5207\u5206\uff0c\u518d\u5c06\u82e5\u5e72\u53e5\u5b50\u805a\u5408\u6210\u6ee1\u8db3chunk\/_size\u7684\u5757\uff1b\u4fdd\u8bc1\u6700\u57fa\u672c\u7684\u8bed\u4e49\u5b8c\u6574\u6027\u3002<\/li>\n<li><strong>\u4f18\u70b9<\/strong>\uff1a\u53e5\u5b50\u7ea7\u5b8c\u6574\u6027\u6700\u597d\u3002\u5bf9\u95ee\u53e5\/\u7b54\u53e5\u6620\u5c04\u53cb\u597d\u3002\u4fbf\u4e8e\u9ad8\u8d28\u91cf\u5f15\u7528\u3002<\/li>\n<li><strong>\u7f3a\u70b9<\/strong>\uff1a\u4e2d\u6587\u5206\u53e5\u9700\u7279\u522b\u5904\u7406\u3002\u4ec5\u53e5\u5b50\u7ea7\u5207\u5206\u53ef\u80fd\u5bfc\u81f4\u5757\u8fc7\u77ed\uff0c\u9700\u540e\u7eed\u805a\u5408\u3002<\/li>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u6cd5\u5f8b\u6cd5\u89c4\u3001\u65b0\u95fb\u3001\u516c\u544a\u3001FAQ \u7b49\u4ee5\u53e5\u5b50\u4e3a\u4e3b\u7684\u6587\u672c\u3002<\/li>\n<li><strong>\u4e2d\u6587\u5206\u53e5\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<\/li>\n<li>\n<ul>\n<li>\u4e0d\u8981\u76f4\u63a5\u7528 NLTK \u82f1\u6587 Punkt\uff1a\u65e0\u6cd5\u8bc6\u522b\u4e2d\u6587\u6807\u70b9\uff0c\u5206\u53e5\u4f1a\u5931\u8d25\u6216\u5f02\u5e38\u3002<\/li>\n<li>\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u4ee5\u4e0b\u5185\u5bb9\u8fdb\u884c\u5206\u53e5\uff1a<\/li>\n<li>\n<ul>\n<li>\u57fa\u4e8e\u4e2d\u6587\u6807\u70b9\u7684\u6b63\u5219\uff1a\u6309\u201c\u3002\uff01\uff1f\uff1b\u201d\u7b49\u5207\u5206\uff0c\u4fdd\u7559\u5f15\u53f7\u4e0e\u7701\u7565\u53f7\u7b49\u8fb9\u754c\u3002<\/li>\n<li>\u4f7f\u7528\u652f\u6301\u4e2d\u6587\u7684 NLP \u5e93\u8fdb\u884c\u66f4\u7cbe\u7ec6\u7684\u5206\u53e5\uff1a<\/li>\n<li>HanLP\uff08\u63a8\u8350\uff0c\u5de5\u4e1a\u7ea7\uff0c\u652f\u6301\u7e41\u591a\u8bed\u8a00\u5b66\u7279\u6027\uff09Stanza\uff08\u6e05\u534e\/\u65af\u5766\u798f\u5408\u4f5c\uff0c\u4e2d\u6587\u652f\u6301\u8f83\u597d\uff09spaCy + pkuseg \u63d2\u4ef6\uff08\u6216 zh-core-web-sm\/med\/lg \u751f\u6001\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u793a\u4f8b<\/strong>\uff08\u9002\u914d\u5e38\u89c1\u4e2d\u6587\u6807\u70b9\uff0c\u57fa\u4e8e\u6b63\u5219\u7684\u5206\u53e5\uff09\uff1a<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>import re\n\n\ndef split_sentences_zh(text: str):\n    # \u5728\u53e5\u672b\u6807\u70b9\uff08\u3002\uff01\uff1f\uff1b\uff09\u540e\u9762\u5e26\u53ef\u9009\u5f15\u53f7\u7684\u573a\u666f\u65ad\u53e5\n    pattern = re.compile(r'([^\u3002\uff01\uff1f\uff1b]*[\u3002\uff01\uff1f\uff1b]+|[^\u3002\uff01\uff1f\uff1b]+$)')\n    sentences = [m.group(0).strip() for m in pattern.finditer(text) if m.group(0).strip()]\n    return sentences\n\n\ndef sentence_chunk(text: str, chunk_size=600, overlap=80):\n    sents = split_sentences_zh(text)\n    chunks, buf = [], &quot;&quot;\n    for s in sents:\n        if len(buf) + len(s) &lt;= chunk_size:\n            buf += s\n        else:\n            if buf:\n                chunks.append(buf)\n            # \u7b80\u5355\u91cd\u53e0\uff1a\u4ece\u5f53\u524d\u5757\u5c3e\u90e8\u622a\u53d6 overlap \u5b57\u7b26\u4e0e\u4e0b\u4e00\u53e5\u62fc\u63a5\n            buf = (buf[-overlap:] if overlap &gt; 0 and len(buf) &gt; overlap else &quot;&quot;) + s\n    if buf:\n        chunks.append(buf)\n    return chunks\n\n\nchunks = sentence_chunk(text, chunk_size=600, overlap=90)\n<\/code><\/pre>\n<p>HanLP \u5206\u53e5\u793a\u4f8b\uff1a<\/p>\n<pre><code>from hanlp_common.constant import ROOT\nimport hanlp\n\n\ntokenizer = hanlp.load('PKU_NAME_MERGED_SIX_MONTHS_CONVSEG')  # \u6216\u53e5\u6cd5\/\u53e5\u5b50\u7ea7\u7ba1\u7ebf\n# HanLP \u9ad8\u5c42 API \u901a\u5e38\u901a\u8fc7\u53e5\u6cd5\/\u8bed\u6599\u7ba1\u7ebf\u83b7\u5f97\u53e5\u5b50\u8fb9\u754c\uff0c\u5177\u4f53\u4ee5\u6240\u7528\u7248\u672c API \u4e3a\u51c6\n# \u5c06\u53e5\u5b50\u5217\u8868\u518d\u505a\u805a\u5408\u4e3a chunk_size\n<\/code><\/pre>\n<p><strong>\u57fa\u4e8e\u9012\u5f52\u5b57\u7b26\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong>\uff1a\u7ed9\u5b9a\u4e00\u7ec4\u7531\u201c\u7c97\u5230\u7ec6\u201d\u7684\u5206\u9694\u7b26\uff08\u5982\u6bb5\u843d\u2192\u6362\u884c\u2192\u7a7a\u683c\u2192\u5b57\u7b26\uff09\uff0c\u81ea\u4e0a\u800c\u4e0b\u9012\u5f52\u5207\u5206\uff0c\u5728\u4e0d\u8d85\u51fa chunk\/_size \u7684\u524d\u63d0\u4e0b\u5c3d\u91cf\u4fdd\u7559\u81ea\u7136\u8bed\u4e49\u8fb9\u754c\u3002<\/li>\n<li><strong>\u4f18\u70b9<\/strong>\uff1a\u5728\u201c\u4fdd\u6301\u8bed\u4e49\u8fb9\u754c\u201d\u548c\u201c\u63a7\u5236\u5757\u5927\u5c0f\u201d\u4e4b\u95f4\u53d6\u5f97\u7a33\u5065\u5e73\u8861\uff0c\u5bf9\u5927\u591a\u6570\u6587\u672c\u5373\u63d2\u5373\u7528\u3002<\/li>\n<li><strong>\u7f3a\u70b9<\/strong>\uff1a\u5206\u9694\u7b26\u914d\u7f6e\u4e0d\u5f53\u4f1a\u5bfc\u81f4\u5757\u7c92\u5ea6\u5931\u8861\uff0c\u6781\u5ea6\u683c\u5f0f\u5316\u6587\u672c\uff08\u8868\u683c\/\u4ee3\u7801\uff09\u6548\u679c\u4e00\u822c\u3002<\/li>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u7efc\u5408\u6027\u8bed\u6599\u3001\u8bf4\u660e\u6587\u6863\u3001\u62a5\u544a\u3001\u77e5\u8bc6\u5e93\u6761\u76ee\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>import re\nfrom langchain_text_splitters import RecursiveCharacterTextSplitter\n\n\nseparators = [\n    r&quot;\/n#{1,6}\/s&quot;,                 # \u6807\u9898\n    r&quot;\/n\/d+(?:.\/d+)*\/s&quot;,          # \u6570\u5b57\u7f16\u53f7\u6807\u9898 1. \/ 2.3. \u7b49\n    &quot;\/n\/n&quot;,                        # \u6bb5\u843d\n    &quot;\/n&quot;,                          # \u884c\n    &quot; &quot;,                           # \u7a7a\u683c\n    &quot;&quot;,                            # \u515c\u5e95\u5b57\u7b26\u7ea7\n]\nsplitter = RecursiveCharacterTextSplitter(\n    separators=separators,\n    chunk_size=700,\n    chunk_overlap=100,\n    is_separator_regex=True,       # \u544a\u8bc9\u5206\u5272\u5668\u4e0a\u9762\u5305\u542b\u6b63\u5219\n)\nchunks = splitter.split_text(text)\n<\/code><\/pre>\n<ul>\n<li><strong>\u53c2\u6570\u4e0e\u5206\u9694\u7b26\u5efa\u8bae<\/strong>\uff08\u4ec5\u4e2d\u6587\u6587\u6863\u5efa\u8bae\uff09\uff1a<\/li>\n<li>\n<ul>\n<li>chunk\/_size\uff1a400\u2013800 \u5b57\u7b26\uff1b\u5982\u679c\u5185\u5bb9\u66f4\u6280\u672f\u5316\u3001\u957f\u53e5\u591a\u65f6\u53ef\u9002\u5f53\u4e0a\u8c03\u8be5\u6570\u503c\u3002<\/li>\n<li>chunk\/_overlap\uff1a10%\u201320%\u3002<\/li>\n<li>separators\uff08\u7531\u7c97\u5230\u7ec6\uff0c\u6309\u9700\u88c1\u526a\uff09\uff1a<\/li>\n<li>\n<ul>\n<li>\u7ae0\u8282\/\u6807\u9898\uff1a\u6b63\u5219 r&#8221;^#{1,6}\/s&#8221;\uff08Markdown \u6807\u9898\uff09\u3001r&#8221;^\/d+(.\/d+)*\/s&#8221;\uff08\u7f16\u53f7\u6807\u9898\uff09<\/li>\n<li>\u6bb5\u843d\uff1a&#8221;\/n\/n&#8221;<\/li>\n<li>\u6362\u884c\uff1a&#8221;\/n&#8221;<\/li>\n<li>\u7a7a\u683c\uff1a&#8221; &#8220;<\/li>\n<li>\u515c\u5e95\uff1a&#8221;&#8221;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n<ul>\n<li><strong>\u8c03\u4f18\u6d41\u7a0b<\/strong>\uff1a<\/li>\n<li>\n<ul>\n<li>\u56fa\u5b9a\u68c0\u7d22\u4e0e\u91cd\u6392\uff0c\u53ea\u52a8\u5206\u5757\u53c2\u6570\u3002<\/li>\n<li>\u7528\u9a8c\u8bc1\u96c6\u8ba1\u7b97 Recall\/@k\u3001nDCG\u3001MRR\u3001\u6765\u6e90\u547d\u4e2d\u6587\u6863\u8986\u76d6\u7387\u3001\u7b54\u6848\u4e8b\u5b9e\u6027\uff08faithfulness\uff09\u3002<\/li>\n<li>\u89c2\u5bdf\u5757\u957f\u5206\u5e03\uff1a\u82e5\u957f\u5c3e\u592a\u957f\uff0c\u9002\u5f53\u6536\u7d27chunk\/_size \u6216\u589e\u52a0\u7c97\u7c92\u5ea6\u5206\u9694\u7b26\uff1b\u82e5\u8fc7\u77ed\uff0c\u653e\u5bbdchunk\/_size \u6216\u964d\u4f4e\u5206\u9694\u7b26\u4f18\u5148\u7ea7\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u91cd\u53e0\u7684\u6210\u672c\u4e0e\u6536\u76ca<\/strong>\uff1a<\/li>\n<li>\n<ul>\n<li>\u6536\u76ca\uff1a\u7f13\u89e3\u8fb9\u754c\u65ad\u88c2\uff0c\u63d0\u5347\u7b54\u6848\u8fde\u8d2f\u6027\u4e0e\u53ef\u8ffd\u6eaf\u6027\u3002<\/li>\n<li>\u6210\u672c\uff1a\u7d22\u5f15\u5c3a\u5bf8\u589e\u957f\u3001\u53ec\u56de\u91cd\u590d\u5757\u589e\u591a\u3001rerank \u8d1f\u8f7d\u63d0\u5347\u3002\u901a\u5e38\u4e0d\u5efa\u8bae\u8d85\u8fc7 20%\u201325%\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u7ec4\u5408\u6280\u5de7<\/strong>\uff1a<\/li>\n<li>\n<ul>\n<li>\u5148\u9012\u5f52\u5206\u5757\uff0c\u518d\u5bf9\u201c\u5f02\u5e38\u957f\u53e5\u201d\u6216\u201c\u8de8\u6bb5\u5f15\u7528\u201d\u573a\u666f\u52a0\u4e00\u70b9\u70b9\u989d\u5916 overlap\u3002<\/li>\n<li>\u5bf9\u6807\u9898\u5757\u6ce8\u5165\u7236\u7ea7\u6807\u9898\u4e0a\u4e0b\u6587\uff0c\u63d0\u9ad8\u5b9a\u4f4d\u80fd\u529b\u4e0e\u53ef\u89e3\u91ca\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4f55\u65f6\u5207\u6362\u7b56\u7565<\/strong>\uff1a<\/li>\n<li>\n<ul>\n<li>\u82e5\u95ee\u7b54\u9891\u7e41\u4e22\u4e0a\u4e0b\u6587\u6216\u5f15\u7528\u65ad\u88c2\uff1a\u589e\u5927overlap\u6216\u6539\u7528\u53e5\u5b50\/\u7ed3\u6784\u611f\u77e5\u7b56\u7565\u3002<\/li>\n<li>\u82e5\u53ec\u56de\u542b\u566a\u8fc7\u591a\uff1a\u51cf\u5c0f chunk\/_size \u6216\u5f15\u5165\u66f4\u5f3a\u7684\u7ed3\u6784\u5206\u9694\u7b26\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>4.2 \u7ed3\u6784\u611f\u77e5\u5206\u5757<\/h2>\n<p>\u5229\u7528\u6587\u6863\u56fa\u6709\u7ed3\u6784\uff08\u6807\u9898\u5c42\u7ea7\u3001\u5217\u8868\u3001\u4ee3\u7801\u5757\u3001\u8868\u683c\u3001\u5bf9\u8bdd\u8f6e\u6b21\uff09\u4f5c\u4e3a\u5206\u5757\u8fb9\u754c\uff0c\u903b\u8f91\u6e05\u6670\u3001\u53ef\u8ffd\u6eaf\u6027\u5f3a\uff0c\u80fd\u5728\u4fdd\u8bc1\u4e0a\u4e0b\u6587\u5b8c\u6574\u6027\u7684\u540c\u65f6\u63d0\u5347\u68c0\u7d22\u4fe1\u566a\u6bd4\u3002<\/p>\n<p><strong>\u7ed3\u6784\u5316\u6587\u672c\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong><\/li>\n<li>\u4ee5\u6807\u9898\u5c42\u7ea7\uff08H1\u2013H6\u3001\u7f16\u53f7\u6807\u9898\uff09\u6216\u8bed\u4e49\u5757\uff08\u6bb5\u843d\u3001\u5217\u8868\u3001\u8868\u683c\u3001\u4ee3\u7801\u5757\uff09\u4e3a\u6b64\u7c7b\u578b\u6587\u6863\u7684\u5929\u7136\u8fb9\u754c\uff0c\u5bf9\u8fc7\u957f\u7684\u7ed3\u6784\u5757\u518d\u505a\u4e8c\u6b21\u7ec6\u5206\uff0c\u5bf9\u8fc7\u77ed\u7684\u8fdb\u884c\u76f8\u90bb\u5408\u5e76\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u5b9e\u65bd\u6b65\u9aa4<\/strong><\/li>\n<li>\n<ul>\n<li>\u89e3\u6790\u7ed3\u6784\uff1aMarkdown \u7528\u89e3\u6790\u5668remark\/markdown-it-py\u6216\u6b63\u5219\u8bc6\u522b\u6807\u9898\u4e0e\u8bed\u5757\uff1bHTML\u7528 DOMBeautifulSoup\/Cheerio\u904d\u5386 Hx\u3001p\u3001li\u3001pre\u3001table \u7b49\u3002<\/li>\n<li>\u751f\u6210\u7ae0\u8282\uff1a\u4ee5\u6807\u9898\u4e3a\u7236\u8282\u70b9\uff0c\u5c06\u5176\u540e\u7684\u8fde\u7eed\u5144\u5f1f\u8282\u70b9\u7eb3\u5165\u8be5\u7ae0\u8282\uff0c\u76f4\u81f3\u9047\u5230\u540c\u7ea7\u6216\u66f4\u9ad8\u5c42\u7ea7\u6807\u9898\u3002<\/li>\n<li>\u4e8c\u6b21\u5207\u5206\uff1a\u7ae0\u8282\u8d85\u51fa chunk\/_size\u65f6\uff0c\u4f18\u5148\u6309\u5b50\u6807\u9898\/\u6bb5\u843d\u5207\uff0c\u518d\u4e0d\u8db3\u65f6\u6309\u53e5\u5b50\u6216\u9012\u5f52\u5b57\u7b26\u5207\u5206\u3002<\/li>\n<li>\u5408\u5e76\u77ed\u5757\uff1a\u4f4e\u4e8e min\/_chunk\/_chars \u7684\u5757\u4e0e\u76f8\u90bb\u5757\u5408\u5e76\uff0c\u4f18\u5148\u4e0e\u540c\u4e00\u7236\u6807\u9898\u4e0b\u7684\u524d\u540e\u5757\u3002<\/li>\n<li>\u4e0a\u4e0b\u6587\u91cd\u53e0\uff1a\u4f18\u5148\u7528\u201c\u7ed3\u6784\u91cd\u53e0\u201d\uff08\u7236\u7ea7\u6807\u9898\u8def\u5f84\u3001\u524d\u4e00\u5c0f\u8282\u6807\u9898+\u6458\u8981\uff09\uff0c\u518d\u8f85\u4ee5\u5c0f\u6bd4\u4f8b\u5b57\u7b26overlap\uff0810%\u201315%\uff09\u3002<\/li>\n<li>\u5199\u5165 metadata\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u793a\u4f8b\u4ee3\u7801<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>import re\nfrom typing import List, Dict\n\n\nheading_pat = re.compile(r'^(#{1,6})\/s+(.*)$')  # \u6807\u9898\nfence_pat = re.compile(r'^```')                 # fenced code fence\n\n\ndef split_markdown_structure(text: str, chunk_size=900, min_chunk=250, overlap_ratio=0.1) -&gt; List[Dict]:\n    lines = text.splitlines()\n    sections = []\n    in_code = False\n    current = {&quot;level&quot;: 0, &quot;title&quot;: &quot;&quot;, &quot;content&quot;: [], &quot;path&quot;: []}\n    \n    path_stack = []  # [(level, title)]\n    \n    for ln in lines:\n        if fence_pat.match(ln):\n            in_code = not in_code\n        m = heading_pat.match(ln) if not in_code else None\n        if m:\n            if current[&quot;content&quot;]:\n                sections.append(current)\n            level = len(m.group(1))\n            title = m.group(2).strip()\n\n\n            while path_stack and path_stack[-1][0] &gt;= level:\n                path_stack.pop()\n            path_stack.append((level, title))\n            breadcrumbs = [t for _, t in path_stack]\n            current = {&quot;level&quot;: level, &quot;title&quot;: title, &quot;content&quot;: [], &quot;path&quot;: breadcrumbs}\n        else:\n            current[&quot;content&quot;].append(ln)\n    \n    if current[&quot;content&quot;]:\n        sections.append(current)\n    \n    # \u901a\u8fc7\u4e8c\u6b21\u62c6\u5206\/\u5408\u5e76\u5c06\u90e8\u5206\u5e73\u94fa\u6210\u5757\n    chunks = []\n    def emit_chunk(text_block: str, path: List[str], level: int):\n        chunks.append({\n            &quot;text&quot;: text_block.strip(),\n            &quot;meta&quot;: {\n                &quot;section_title&quot;: path[-1] if path else &quot;&quot;,\n                &quot;breadcrumbs&quot;: path,\n                &quot;section_level&quot;: level,\n            }\n        })\n    \n    for sec in sections:\n        raw = &quot;\/n&quot;.join(sec[&quot;content&quot;]).strip()\n        if not raw:\n            continue\n        if len(raw) &lt;= chunk_size:\n            emit_chunk(raw, sec[&quot;path&quot;], sec[&quot;level&quot;])\n        else:\n            paras = [p.strip() for p in raw.split(&quot;\/n\/n&quot;) if p.strip()]\n            buf = &quot;&quot;\n            for p in paras:\n                if len(buf) + len(p) + 2 &lt;= chunk_size:\n                    buf += ((&quot;\/n\/n&quot; + p) if buf else p)\n                else:\n                    if buf:\n                        emit_chunk(buf, sec[&quot;path&quot;], sec[&quot;level&quot;])\n                    buf = p\n            if buf:\n                emit_chunk(buf, sec[&quot;path&quot;], sec[&quot;level&quot;])\n    \n    merged = []\n    for ch in chunks:\n        if not merged:\n            merged.append(ch)\n            continue\n        if len(ch[&quot;text&quot;]) &lt; min_chunk and merged[-1][&quot;meta&quot;][&quot;breadcrumbs&quot;] == ch[&quot;meta&quot;][&quot;breadcrumbs&quot;]:\n            merged[-1][&quot;text&quot;] += &quot;\/n\/n&quot; + ch[&quot;text&quot;]\n        else:\n            merged.append(ch)\n    \n    overlap = int(chunk_size * overlap_ratio)\n    for ch in merged:\n        bc = &quot; &gt; &quot;.join(ch[&quot;meta&quot;][&quot;breadcrumbs&quot;][-3:])\n        prefix = f&quot;[{bc}]\/n&quot; if bc else &quot;&quot;\n        if prefix and not ch[&quot;text&quot;].startswith(prefix):\n            ch[&quot;text&quot;] = prefix + ch[&quot;text&quot;]\n        # optional character overlap can\u5728\u68c0\u7d22\u9636\u6bb5\u7528\u90bb\u63a5\u805a\u5408\u66ff\u4ee3\uff0c\u8fd9\u91cc\u7565\n    \n    return merged\n<\/code><\/pre>\n<ul>\n<li><strong>\u53c2\u6570\u5efa\u8bae\uff08\u4e2d\u6587\u6587\u6863\uff09<\/strong><\/li>\n<li>\n<ul>\n<li>chunk\/_size\uff1a600\u20131000 \u5b57\uff1b\u6280\u672f\u6587\/\u957f\u6bb5\u843d\u53ef\u53d6\u4e0a\u9650\uff0c\u7ee7\u7eed\u9002\u5f53\u589e\u52a0\u3002<\/li>\n<li>min\/_chunk\/_chars\uff1a200\u2013300 \u5b57\uff08\u5c0f\u4e8e\u5219\u5408\u5e76\uff09\u3002<\/li>\n<li>chunk\/_overlap\uff1a10%\u201315%\uff1b\u82e5\u4f7f\u7528\u201c\u7236\u7ea7\u6807\u9898\u8def\u5f84 + \u6458\u8981\u201d\u4f5c\u4e3a\u7ed3\u6784\u91cd\u53e0\uff0c\u53ef\u964d\u81f3 5%\u201310%\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u5bf9\u8bdd\u5f0f\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong><\/li>\n<li><strong>\u4ee5\u201c\u8f6e\u6b21\/\u8bf4\u8bdd\u4eba\u201d\u4e3a\u8fb9\u754c\uff0c\u4f18\u5148\u6309\u5bf9\u8bdd\u90bb\u63a5\u5bf9\u548c\u5c0f\u6bb5\u8bdd\u9898\u7a97\u53e3\u805a\u5408\u3002\u91cd\u53e0\u91c7\u7528\u201c\u8f6e\u6b21\u91cd\u53e0\u201d\u800c\u975e\u5355\u7eaf\u5b57\u7b26\u91cd\u53e0\uff0c\u4fdd\u8bc1\u4e0a\u4e0b\u6587\u6d41\u7545\u3002<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong><\/li>\n<li><strong>\u5ba2\u670d\u5bf9\u8bdd\u3001\u8bbf\u8c08\u3001\u4f1a\u8bae\u7eaa\u8981\u3001\u6280\u672f\u652f\u6301\u5de5\u5355\u7b49\u591a\u8f6e\u4ea4\u6d41\u3002<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u68c0\u7d22\u671f\u90bb\u63a5\u805a\u5408<\/strong><\/li>\n<li><strong>\u5728\u68c0\u7d22\u9636\u6bb5\u5bf9\u5bf9\u8bdd\u5757\u505a\u201c\u90bb\u63a5\u6269\u5c55\u201d\uff1a\u53d6\u88ab\u53ec\u56de\u5757\u524d\u540e\u5404 1\u20132 \u8f6e\u4e0a\u4e0b\u6587\uff08\u6216\u76f8\u90bb\u5757\u62fc\u63a5\uff09\u4f5c\u4e3a\u6700\u7ec8\u9001\u5ba1\u4e0a\u4e0b\u6587\uff0c\u4ee5\u63d0\u9ad8\u56de\u7b54\u8fde\u8d2f\u6027\u4e0e\u53ef\u8ffd\u6eaf\u6027\u3002<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4e0e\u91cd\u6392\u534f\u540c<\/strong><\/li>\n<li><strong>\u53ef\u63d0\u5347\u5bf9\u201c\u8c01\u8bf4\u7684\u3001\u5728\u54ea\u6bb5\u8bf4\u7684\u201d\u7684\u5224\u65ad\u529b\u3002<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u793a\u4f8b\u4ee3\u7801<\/strong>\uff1a\uff08\u6309\u8f6e\u6b21\u6ed1\u52a8\u7a97\u53e3\u5206\u5757\uff09<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>from typing import List, Dict\n\n\ndef chunk_dialogue(turns: List[Dict], max_turns=10, max_chars=900, overlap_turns=2):\n    &quot;&quot;&quot;\n    turns: [{&quot;speaker&quot;:&quot;User&quot;,&quot;text&quot;:&quot;...&quot; , &quot;ts_start&quot;:123, &quot;ts_end&quot;:130}, ...]\n    &quot;&quot;&quot;\n    chunks = []\n    i = 0\n    while i &lt; len(turns):\n        j = i\n        char_count = 0\n        speakers = set()\n        while j &lt; len(turns):\n            t = turns[j]\n            uttr_len = len(t[&quot;text&quot;])\n            # \u82e5\u5355\u6761\u8d85\u957f\uff0c\u5141\u8bb8\u5728\u53e5\u7ea7\u4e8c\u6b21\u5207\u5206\uff08\u6b64\u5904\u7565\uff09\uff0c\u4f46\u4e0d\u8de8 speaker\n            if (j - i + 1) &gt; max_turns or (char_count + uttr_len) &gt; max_chars:\n                break\n            char_count += uttr_len\n            speakers.add(t[&quot;speaker&quot;])\n            j += 1\n        \n        if j &gt; i:\n            window = turns[i:j]\n        elif i &lt; len(turns):\n            window = [turns[i]]\n        else:\n            break\n        text = &quot;\/n&quot;.join([f'{t[&quot;speaker&quot;]}: {t[&quot;text&quot;]}' for t in window])\n        meta = {\n            &quot;speakers&quot;: list(speakers),\n            &quot;turns_range&quot;: (i, j - 1),\n            &quot;ts_start&quot;: window[0].get(&quot;ts_start&quot;),\n            &quot;ts_end&quot;: window[-1].get(&quot;ts_end&quot;),\n        }\n        chunks.append({&quot;text&quot;: text, &quot;meta&quot;: meta})\n        \n        # \u6309\u8f6e\u6b21\u91cd\u53e0\u56de\u9000\n        if j &gt;= len(turns):\n            break\n        next_start = i + len(window) - overlap_turns\n        i = max(next_start, i + 1)  # \u786e\u4fdd\u81f3\u5c11\u524d\u8fdb1\u6b65\n    return chunks\n<\/code><\/pre>\n<ul>\n<li><strong>\u53c2\u6570\u5efa\u8bae<\/strong><\/li>\n<li>\n<ul>\n<li>max\/_turns\/_per\/_chunk\uff1a6\u201312 \u8f6e\u8d77\u6b65\uff1b\u8bed\u901f\u5feb\u4fe1\u606f\u5bc6\u5ea6\u9ad8\u53ef\u53d6 8\u201310\u3002<\/li>\n<li>max\/_chars\/_per\/_chunk\uff1a600\u20131000 \u5b57\uff1b\u82e5\u5b58\u5728\u957f\u6bb5\u72ec\u767d\uff0c\u4f18\u5148\u53e5\u7ea7\u518d\u5207\uff0c\u4e0d\u8de8\u8bf4\u8bdd\u4eba\u3002<\/li>\n<li>overlap\/_turns\uff1a1\u20132 \u8f6e\uff1b\u4fdd\u8bc1\u4e0a\u4e00\u95ee\u4e0b\u4e00\u7b54\u7684\u8fde\u7eed\u6027\u3002<\/li>\n<li>keep\/_pairing\uff1a\u4e0d\u8981\u62c6\u5f00\u660e\u663e\u7684\u95ee\u7b54\u5bf9\uff1b\u82e5 chunk \u4e34\u754c\uff0c\u5b81\u53ef\u6269\u4e00\u8f6e\u6216\u540e\u79fb\u5207\u5206\u70b9\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n<ul>\n<li>\u9996\u9009\u7528\u7ed3\u6784\u8fb9\u754c\u505a\u7b2c\u4e00\u6b21\u5207\u5206\uff0c\u518d\u7528\u53e5\u7ea7\/\u9012\u5f52\u7b56\u7565\u505a\u4e8c\u6b21\u7ec6\u5206\u3002<\/li>\n<li>\u4f18\u5148\u4f7f\u7528\u201c\u7ed3\u6784\u91cd\u53e0\u201d\uff08\u7236\u6807\u9898\u8def\u5f84\u3001\u4e0a\u6bb5\u6807\u9898+\u6458\u8981\u3001\u76f8\u90bb\u53d1\u8a00\uff09\u66ff\u4ee3\u5927\u6bd4\u4f8b\u5b57\u7b26\u91cd\u53e0\u3002<\/li>\n<li>\u4e3a\u6bcf\u4e2a\u5757\u5199\u597d metadata\uff0c\u53ef\u663e\u8457\u63d0\u5347\u68c0\u7d22\u8d28\u91cf\u4e0e\u53ef\u89e3\u91ca\u6027\u3002<\/li>\n<li>\u5bf9 PDF\/HTML \u5148\u53bb\u566a\uff08\u9875\u7709\u9875\u811a\u3001\u5bfc\u822a\u3001\u5e7f\u544a\u7b49\uff09\uff0c\u907f\u514d\u628a\u566a\u58f0\u7d22\u5f15\u8fdb\u5e93\u3002<\/li>\n<\/ul>\n<h2>4.3 \u8bed\u4e49\u4e0e\u4e3b\u9898\u5206\u5757<\/h2>\n<p>\u8be5\u65b9\u6cd5\u4e0d\u4f9d\u8d56\u6587\u6863\u7684\u7269\u7406\u7ed3\u6784\uff0c\u800c\u662f\u4f9d\u636e\u8bed\u4e49\u8fde\u7eed\u6027\u4e0e\u8bdd\u9898\u8f6c\u79fb\u6765\u51b3\u5b9a\u5207\u5206\u70b9\uff0c\u5c24\u5176\u9002\u5408\u5e0c\u671b\u201c\u5757\u5185\u9ad8\u5ea6\u5185\u805a\u3001\u5757\u95f4\u6e05\u6670\u5206\u754c\u201d\u7684\u77e5\u8bc6\u5e93\u4e0e\u7814\u7a76\u7c7b\u6587\u672c\u3002<\/p>\n<p><strong>\u8bed\u4e49\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong><\/li>\n<li>\n<ul>\n<li>\u5bf9\u6587\u672c\u5148\u505a\u53e5\u7ea7\u5207\u5206\uff0c\u8ba1\u7b97\u53e5\u5b50\u6216\u77ed\u6bb5\u7684\u5411\u91cf\u8868\u793a\uff1b<\/li>\n<li>\u5f53\u76f8\u90bb\u8bed\u4e49\u7684\u76f8\u4f3c\u5ea6\u663e\u8457\u4e0b\u964d\uff08\u53d1\u751f\u201c\u8bed\u4e49\u7a81\u53d8\u201d\uff09\u65f6\u8bbe\u4e3a\u5207\u5206\u70b9\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong><\/li>\n<li>\n<ul>\n<li>\u4e13\u9898\u5316\u3001\u8bba\u8bc1\u7ed3\u6784\u660e\u663e\u7684\u6587\u6863\uff1a<\/li>\n<li>\u767d\u76ae\u4e66\u3001\u8bba\u6587\u3001\u6280\u672f\u624b\u518c\u3001FAQ \u805a\u5408\u9875\uff1b<\/li>\n<li>\u9700\u8981\u9ad8\u5185\u805a\u68c0\u7d22\u4e0e\u9ad8\u53ef\u8ffd\u6eaf\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u6d41\u7a0b<\/strong><\/li>\n<li>\n<ul>\n<li>\u53e5\u7ea7\u5207\u5206\uff1a\u5148\u7528\u4e2d\u6587\u5206\u53e5\uff08\u6807\u70b9\/\u4e2d\u6587\u5206\u53e5\u6a21\u578b\uff09\u5f97\u5230\u53e5\u5b50\u5e8f\u5217\u3002<\/li>\n<li>\u5411\u91cf\u5316\uff1a\u5bf9\u6bcf\u4e2a\u53e5\u5b50\u7f16\u7801\uff0c\u5f00\u542f\u5f52\u4e00\u5316\uff08normalize\uff09\u4ee5\u4fbf\u7528\u4f59\u5f26\u76f8\u4f3c\u5ea6\u3002<\/li>\n<li>\u7a81\u53d8\u68c0\u6d4b\uff1a<\/li>\n<li>\n<ul>\n<li>\u7b80\u5355\u7c97\u66b4\u7684\u65b9\u6cd5\uff1asim(i, i-1) \u4f4e\u4e8e\u9608\u503c\u5219\u5207\u5206\u3002<\/li>\n<li>\u7a33\u5065\u7684\u65b9\u6cd5\uff1a\u4e0e\u201c\u524d\u540e\u7a97\u53e3\u7684\u5747\u503c\u5411\u91cf\u201d\u6bd4\u8f83\uff0c\u8ba1\u7b97\u65b0\u9896\u5ea6 novelty = 1 &#8211; cos(emb\/_i, mean\/_emb\/_window)\uff0c\u65b0\u9896\u5ea6\u9ad8\u4e8e\u9608\u503c\u5219\u5207\u5206\u3002<\/li>\n<li>\u5e73\u6ed1\u7684\u65b9\u6cd5\uff1a\u5bf9\u76f8\u4f3c\u5ea6\/\u65b0\u9896\u5ea6\u505a\u79fb\u52a8\u5e73\u5747\uff0c\u964d\u4f4e\u6296\u52a8\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7ea6\u675f\u4e0e\u4fee\u6b63\uff1a\u8bbe\u7f6e\u6700\u5c0f\/\u6700\u5927\u5757\u957f\uff0c\u907f\u514d\u8fc7\u788e\u6216\u8fc7\u957f\uff0c\u5fc5\u8981\u65f6\u8fdb\u884c\u76f8\u90bb\u5757\u5408\u5e76\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4e0e\u68c0\u7d22\/\u91cd\u6392\u7684\u534f\u540c<\/strong><\/li>\n<li><strong>\u53ec\u56de\u65f6\u53ef\u505a\u201c\u90bb\u63a5\u6269\u5c55\u201d\uff08\u628a\u88ab\u547d\u4e2d\u7684\u5757\u524d\u540e\u5404\u8ffd\u52a0\u4e00\u4e24\u53e5\uff09\uff0c\u518d\u505a\u91cd\u6392\u5e8f\u3002\u8bed\u4e49\u5206\u5757\u7684\u9ad8\u5185\u805a\u53ef\u8ba9 \u91cd\u6392\u5e8f\u66f4\u7cbe\u51c6\u5730\u533a\u5206\u76f8\u8fd1\u5019\u9009\u3002<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4ee3\u7801\u793a\u4f8b<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>from typing import List, Dict, Tuple\nimport numpy as np\nfrom sentence_transformers import SentenceTransformer\nimport re\n\n\ndef split_sentences_zh(text: str) -&gt; List[str]:\n    # \u7b80\u6613\u4e2d\u6587\u5206\u53e5\uff0c\u53ef\u66ff\u6362\u4e3a HanLP\/Stanza \u66f4\u7a33\u5065\u7684\u5b9e\u73b0\n    pattern = re.compile(r'([^\u3002\uff01\uff1f\uff1b]*[\u3002\uff01\uff1f\uff1b]+|[^\u3002\uff01\uff1f\uff1b]+$)')\n    return [m.group(0).strip() for m in pattern.finditer(text) if m.group(0).strip()]\n\n\ndef rolling_mean(vecs: np.ndarray, i: int, w: int) -&gt; np.ndarray:\n    s = max(0, i - w)\n    e = min(len(vecs), i + w + 1)\n    return vecs[s:e].mean(axis=0)\n\n\ndef semantic_chunk(\n    text: str,\n    model_name: str = &quot;BAAI\/bge-m3&quot;,\n    window_size: int = 2,\n    min_chars: int = 350,\n    max_chars: int = 1100,\n    lambda_std: float = 0.8,\n    overlap_chars: int = 80,\n) -&gt; List[Dict]:\n    sents = split_sentences_zh(text)\n    if not sents:\n        return []\n    \n    model = SentenceTransformer(model_name)\n    emb = model.encode(sents, normalize_embeddings=True, batch_size=64, show_progress_bar=False)\n    emb = np.asarray(emb)\n    \n    # \u57fa\u4e8e\u7a97\u53e3\u5747\u503c\u7684\u201c\u65b0\u9896\u5ea6\u201d\u5206\u6570\n    novelties = []\n    for i in range(len(sents)):\n        ref = rolling_mean(emb, i-1, window_size) if i &gt; 0 else emb[0]\n        ref = ref \/ (np.linalg.norm(ref) + 1e-8)\n        novelty = 1.0 - float(np.dot(emb[i], ref))\n        novelties.append(novelty)\n    novelties = np.array(novelties)\n    \n    # \u76f8\u5bf9\u9608\u503c\uff1a\u03bc + \u03bb\u03c3\n    mu, sigma = float(novelties.mean()), float(novelties.std() + 1e-8)\n    threshold = mu + lambda_std * sigma\n    \n    chunks, buf, start_idx = [], &quot;&quot;, 0\n    def flush(end_idx: int):\n        nonlocal buf, start_idx\n        if buf.strip():\n            chunks.append({\n                &quot;text&quot;: buf.strip(),\n                &quot;meta&quot;: {&quot;start_sent&quot;: start_idx, &quot;end_sent&quot;: end_idx-1}\n            })\n        buf, start_idx = &quot;&quot;, end_idx\n    \n    for i, s in enumerate(sents):\n        # \u82e5\u8d85\u957f\u5219\u5148\u51b2\u6d17\n        if len(buf) + len(s) &gt; max_chars and len(buf) &gt;= min_chars:\n            flush(i)\n            # \u7ed3\u6784\u5316\u91cd\u53e0\uff1a\u9644\u52a0\u4e0a\u4e00\u4e2a\u5757\u7684\u5c3e\u90e8\n            if overlap_chars &gt; 0 and len(s) &lt; overlap_chars:\n                buf = s\n                continue\n        \n        buf += s\n        \n        # \u8fbe\u5230\u6700\u5c0f\u957f\u5ea6\u540e\u9047\u5230\u7a81\u53d8\u5219\u5207\u5206\n        if len(buf) &gt;= min_chars and novelties[i] &gt; threshold:\n            flush(i + 1)\n    \n    if buf:\n        flush(len(sents))\n    \n    return chunks\n<\/code><\/pre>\n<ul>\n<li><strong>\u53c2\u6570\u8c03\u4f18\u8bf4\u660e<\/strong>\uff08\u4ec5\u4f5c\u53c2\u8003\uff09<\/li>\n<li>\n<ul>\n<li>\u9608\u503c\u7684\u542b\u4e49\uff1a\u8bed\u4e49\u53d8\u5316\u654f\u611f\u5ea6\u63a7\u5236\u5668\uff0c\u8d8a\u4f4e\u8d8a\u5bb9\u6613\u5207\u3001\u8d8a\u9ad8\u8d8a\u4fdd\u5b88\u3002<\/li>\n<li>\u8bbe\u5b9a\u65b9\u5f0f\uff1a<\/li>\n<li>\n<ul>\n<li>\u7edd\u5bf9\u9608\u503c\uff1a\u4f8b\u5982\u4f7f\u7528\u4f59\u5f26\u76f8\u4f3c\u5ea6\uff0c\u82e5 sim &lt; 0.75 \u5219\u5207\u5206\uff08\u9700\u6309\u8bed\u6599\u6821\u51c6\uff09\u3002<\/li>\n<li>\u76f8\u5bf9\u9608\u503c\uff1a\u5bf9\u5168\u7bc7\u7684\u76f8\u4f3c\u5ea6\/\u65b0\u9896\u5ea6\u5206\u5e03\u4f30\u8ba1\u5747\u503c\u03bc\u4e0e\u6807\u51c6\u5dee\u03c3\uff0c\u4f7f\u7528 \u03bc \u00b1 \u03bb\u03c3 \u4f5c\u4e3a\u9608\u503c\uff0c\u66f4\u7a33\u5065\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u521d\u59cb\u7684\u914d\u7f6e\u5efa\u8bae\uff08\u4ec5\u9650\u4e8e\u4e2d\u6587\u6280\u672f\/\u8bf4\u660e\u6587\u6863\uff09\uff1a<\/li>\n<li>\n<ul>\n<li>\u7a97\u53e3\u5927\u5c0f window\/_size\uff1a2\u20134 \u53e5<\/li>\n<li>\u6700\u5c0f\/\u6700\u5927\u5757\u957f\uff1amin\/_chunk\/_chars=300\u2013400\uff0cmax\/_chunk\/_chars=1000\u20131200<\/li>\n<li>\u9608\u503c\u7b56\u7565\uff1anovelty &gt; \u03bc + 0.8\u03c3 \u6216\u76f8\u4f3c\u5ea6 &lt; \u03bc &#8211; 0.8\u03c3\uff08\u5148\u7c97\u8c03\u540e\u5fae\u8c03\uff09<\/li>\n<li>overlap\uff1a10% \u5de6\u53f3\u6216\u6309\u201c\u9644\u52a0\u4e0a\u4e00\u53e5\u201d\u505a\u8f7b\u91cf\u8f6e\u6b21\u91cd\u53e0<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u4e3b\u9898\u7684\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong><\/li>\n<li><strong>\u5229\u7528\u4e3b\u9898\u6a21\u578b\u6216\u805a\u7c7b\u7b97\u6cd5\u5728\u201c\u5b8f\u89c2\u8bdd\u9898\u201d\u53d1\u751f\u5207\u6362\u65f6\u8fdb\u884c\u5207\u5206\uff0c\u66f4\u591a\u7684\u5173\u6ce8\u7ae0\u8282\u7ea7\u3001\u6bb5\u843d\u7ea7\u7684\u4e3b\u9898\u8fb9\u754c\u3002\u8be5\u7c7b\u5206\u5757\u7b56\u7565\u4e3b\u8981\u9002\u5408\u957f\u7bc7\u3001\u591a\u4e3b\u9898\u6750\u6599\u3002<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong><\/li>\n<li>\n<ul>\n<li>\u62a5\u544a\u3001\u4e66\u7c4d\u3001\u957f\u8c03\u7814\u6587\u6863\u3001\u7efc\u5408\u8bc4\u5ba1\uff1b<\/li>\n<li>\u5f53\u6587\u6863\u5185\u90e8\u786e\u6709\u8f83\u7a33\u5b9a\u7684\u201c\u8bdd\u9898\u5757\u201d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u6d41\u7a0b<\/strong>\uff08\u6700\u597d\u7528\u201c\u53e5\u5411\u91cf + \u805a\u7c7b + \u5e8f\u5217\u5e73\u6ed1\u201d\u800c\u975e\u7eaf LDA\uff09<\/li>\n<li>\n<ul>\n<li>\u53e5\u7ea7\u5207\u5206\u5e76\u7f16\u7801\uff1a\u9996\u5148\u901a\u8fc7\u5411\u91cf\u6a21\u578b\u5f97\u5230\u53e5\u5411\u91cf\uff0cnormalize\u3002<\/li>\n<li>\u6587\u6863\u5185\u6216\u8bed\u6599\u7ea7\u805a\u7c7b\uff1a<\/li>\n<li>\n<ul>\n<li>\u6587\u6863\u5185\u5c0f\u89c4\u6a21\uff1aMiniBatchKMeans\uff08k=3\u20138 \u5148\u9a8c\uff09\u6216 SpectralClustering\u3002<\/li>\n<li>\u8bed\u6599\u7ea7\u7edf\u4e00\u4e3b\u9898\uff1a\u5728\u5927\u91cf\u6587\u6863\u4e0a\u805a\u7c7b\uff08\u6216\u7528 HDBSCAN+UMAP\uff09\uff0c\u518d\u5c06\u6bcf\u7bc7\u6587\u6863\u7684\u53e5\u5b50\u6620\u5c04\u5230\u6700\u8fd1\u4e3b\u9898\u4e2d\u5fc3\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5e8f\u5217\u5e73\u6ed1\u4e0e\u89e3\u7801\uff1a<\/li>\n<li>\n<ul>\n<li>\u5bf9\u53e5\u5b50\u7684\u4e3b\u9898\u6807\u7b7e\u505a\u6ed1\u7a97\u591a\u6570\u6295\u7968\u6216\u4e00\u9636\u9a6c\u5c14\u53ef\u592b\u5e73\u6ed1\uff0c\u907f\u514d\u9891\u7e41\u6296\u52a8\u3002<\/li>\n<li>\u5f53\u4e3b\u9898\u6807\u7b7e\u7a33\u5b9a\u53d8\u5316\u5e76\u6ee1\u8db3\u6700\u5c0f\u5757\u957f\u65f6\uff0c\u8bbe\u4e3a\u5207\u5206\u70b9\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u4e3b\u9898\u547d\u540d\uff1a<\/li>\n<li>\u7528 KeyBERT\/TF-IDF \u5728\u6bcf\u4e2a\u5757\u5185\u62bd\u5173\u952e\u8bcd\uff0c\u6216\u7528\u5c0f\u6a21\u578b\u751f\u6210\u4e00\u53e5\u8bdd\u4e3b\u9898\u6458\u8981\uff0c\u5199\u5165 metadata\u3002<\/li>\n<li>\u7ea6\u675f\uff1amin\/max\/_chars\uff0c\u4fdd\u7559\u4ee3\u7801\/\u8868\u683c\u7b49\u539f\u5b50\u5757\uff0c\u5fc5\u8981\u65f6\u4e0e\u7ed3\u6784\u8fb9\u754c\u7ed3\u5408\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4ee3\u7801\u793a\u4f8b<\/strong>\uff08KMeans \u6587\u6863\u5185\u805a\u7c7b + \u5e8f\u5217\u5e73\u6ed1\uff09<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>from typing import List, Dict\nimport numpy as np\nfrom sentence_transformers import SentenceTransformer\nfrom sklearn.cluster import KMeans\nimport re\n\n\ndef split_sentences_zh(text: str) -&gt; List[str]:\n    pattern = re.compile(r'([^\u3002\uff01\uff1f\uff1b]*[\u3002\uff01\uff1f\uff1b]+|[^\u3002\uff01\uff1f\uff1b]+$)')\n    return [m.group(0).strip() for m in pattern.finditer(text) if m.group(0).strip()]\n\n\ndef topic_chunk(\n    text: str,\n    k_topics: int = 5,\n    min_chars: int = 500,\n    max_chars: int = 1400,\n    smooth_window: int = 2,\n    model_name: str = &quot;BAAI\/bge-m3&quot;\n) -&gt; List[Dict]:\n    sents = split_sentences_zh(text)\n    if not sents:\n        return []\n    \n    model = SentenceTransformer(model_name)\n    emb = model.encode(sents, normalize_embeddings=True, batch_size=64, show_progress_bar=False)\n    emb = np.asarray(emb)\n    \n    km = KMeans(n_clusters=k_topics, n_init=&quot;auto&quot;, random_state=42)\n    labels = km.fit_predict(emb)\n    \n    # \u7b80\u5355\u5e8f\u5217\u5e73\u6ed1\uff1a\u6ed1\u7a97\u591a\u6570\u6295\u7968\n    smoothed = labels.copy()\n    for i in range(len(labels)):\n        s = max(0, i - smooth_window)\n        e = min(len(labels), i + smooth_window + 1)\n        window = labels[s:e]\n        vals, counts = np.unique(window, return_counts=True)\n        smoothed[i] = int(vals[np.argmax(counts)])\n    \n    chunks, buf, start_idx, cur_label = [], &quot;&quot;, 0, smoothed[0]\n    def flush(end_idx: int):\n        nonlocal buf, start_idx\n        if buf.strip():\n            chunks.append({\n                &quot;text&quot;: buf.strip(),\n                &quot;meta&quot;: {&quot;start_sent&quot;: start_idx, &quot;end_sent&quot;: end_idx-1, &quot;topic&quot;: int(cur_label)}\n            })\n        buf, start_idx = &quot;&quot;, end_idx\n    \n    for i, s in enumerate(sents):\n        switched = smoothed[i] != cur_label\n        over_max = len(buf) + len(s) &gt; max_chars\n        under_min = len(buf) &lt; min_chars\n        \n        # \u5c1d\u8bd5\u5ef6\u540e\u5207\u5206\uff0c\u4fdd\u8bc1\u6700\u5c0f\u5757\u957f\n        if switched and not under_min:\n            flush(i)\n            cur_label = smoothed[i]\n        \n        if over_max and not under_min:\n            flush(i)\n        \n        buf += s\n    \n    if buf:\n        flush(len(sents))\n    \n    return chunks\n<\/code><\/pre>\n<ul>\n<li><strong>\u4e00\u4e9b\u53c2\u6570\u5bf9\u7ed3\u679c\u7684\u5f71\u54cd<\/strong><\/li>\n<li>\n<ul>\n<li>k\uff08\u4e3b\u9898\u6570\uff09\uff1a\u96be\u4ee5\u7cbe\u51c6\u9884\u8bbe\uff0c\u53ef\u901a\u8fc7\u8f6e\u5ed3\u7cfb\u6570\uff08silhouette\uff09\/\u8098\u90e8\u6cd5\u521d\u7b5b\uff0c\u518d\u7ed3\u5408\u9886\u57df\u5148\u9a8c\u4e0e\u4eba\u5de5\u6821\u6b63\u3002<\/li>\n<li>HDBSCAN\uff1amin\/_cluster\/_size \u5f71\u54cd\u8f83\u5927\uff0c\u8fc7\u5c0f\u4f1a\u788e\u7247\u5316\uff0c\u8fc7\u5927\u5219\u5408\u5e76\u4e0d\u540c\u8bdd\u9898\u3002<\/li>\n<li>min\/_topic\/_span\/_sents\uff1a\u5982 5\u20138 \u53e5\uff0c\u9632\u6b62\u6807\u7b7e\u6296\u52a8\u5bfc\u81f4\u8fc7\u5bc6\u5207\u5206\u3002<\/li>\n<li>\u5c0f\u6587\u6863\u4e0d\u5b9c\u7528\uff1a\u6837\u672c\u592a\u5c11\u65f6\u4e3b\u9898\u4e0d\u53ef\u5206\uff0c\u4f18\u5148\u7528\u8bed\u4e49\u5206\u5757\u6216\u7ed3\u6784\u5206\u5757\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>4.4 \u9ad8\u7ea7\u5206\u5757<\/h2>\n<p><strong>\u5c0f-\u5927\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong><\/li>\n<li>\u7528\u201c\u5c0f\u7c92\u5ea6\u5757\u201d\uff08\u5982\u53e5\u5b50\/\u77ed\u53e5\uff09\u505a\u9ad8\u7cbe\u5ea6\u53ec\u56de\uff0c\u5b9a\u4f4d\u5230\u6700\u76f8\u5173\u7684\u5fae\u7247\u6bb5\uff1b\u518d\u5c06\u5176\u201c\u6240\u5728\u7684\u5927\u7c92\u5ea6\u5757\u201d\uff08\u5982\u6bb5\u843d\/\u5c0f\u8282\uff09\u4f5c\u4e3a\u4e0a\u4e0b\u6587\u9001\u5165 LLM\uff0c\u4ee5\u517c\u987e\u7cbe\u786e\u6027\u4e0e\u4e0a\u4e0b\u6587\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u6d41\u7a0b<\/strong><\/li>\n<li>\n<ul>\n<li>\u6784\u5efa\u7d22\u5f15\uff08\u79bb\u7ebf\uff09\uff1a<\/li>\n<li>\n<ul>\n<li>Sentence\/\u77ed\u53e5\u7d22\u5f15\uff08\u7d22\u5f15A\uff09\uff1a\u5355\u4f4d\u4e3a\u53e5\u5b50\u6216\u5b50\u53e5\u3002<\/li>\n<li>\u6bb5\u843d\/\u5c0f\u8282\u5b58\u50a8\uff08\u5b58\u50a8B\uff09\uff1a\u4fdd\u7559\u539f\u59cb\u5927\u5757\u6587\u672c\u4e0e\u7ed3\u6784\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u68c0\u7d22\uff08\u5728\u7ebf\uff09\uff1a<\/li>\n<li>\n<ul>\n<li>\u7528\u7d22\u5f15A\u53ec\u56de top\/_k\/_small \u4e2a\u5c0f\u5757\uff08\u5411\u91cf\u68c0\u7d22\uff09\u3002<\/li>\n<li>\u5c06\u5c0f\u5757\u6309 parent\/_id \u5206\u7ec4\uff0c\u8ba1\u7b97\u7ec4\u5185\u5206\u6570\uff08max\/mean\/\u52a0\u6743\uff09\uff0c\u9009\u51fa top\/_m\/_big \u4e2a\u7236\u5757\u5019\u9009\u3002<\/li>\n<li>\u5bf9\u201c\u67e5\u8be2-\u7236\u5757\u6587\u672c\u201d\u505a\u4ea4\u53c9\u7f16\u7801\u91cd\u6392\uff0c\u63d0\u5347\u76f8\u5173\u6027\u6392\u5e8f\u7684\u7a33\u5b9a\u6027\u3002<\/li>\n<li>\u4e0a\u4e0b\u6587\u7ec4\u88c5\uff1a\u5728\u6bcf\u4e2a\u7236\u5757\u4e2d\u9ad8\u4eae\u6216\u4f18\u5148\u4fdd\u7559\u547d\u4e2d\u5c0f\u53e5\u9644\u8fd1\u7684\u4e0a\u4e0b\u6587\uff08\u90bb\u8fd1N\u53e5\u6216\u7a97\u53e3\u5b57\u7b26 w\uff09\uff0c\u5728\u6574\u4f53 token \u9884\u7b97\u5185\u62fc\u63a5\u591a\u5757\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4ee3\u7801\u793a\u4f8b\uff08\u4f2a\u4ee3\u7801\uff09<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code># \u79bb\u7ebf\uff1a\u6784\u5efa\u5c0f\u5757\u7d22\u5f15\uff0c\u5e76\u4fdd\u5b58 parent_id -&gt; \u5927\u5757\u6587\u672c \u7684\u6620\u5c04\n# \u5728\u7ebf\u68c0\u7d22\uff1a\nsmall_hits = small_index.search(embed(query), top_k=30)\ngroups = group_by_parent(small_hits)\nscored_parents = score_groups(groups, agg=&quot;max&quot;)\ncandidates = top_m(scored_parents, m=3)\n\n\n# \u4ea4\u53c9\u7f16\u7801\u91cd\u6392\nrerank_inputs = [(query, parent_text(pid)) for pid in candidates]\nreranked = cross_encoder_rerank(rerank_inputs)\n\n\n# \u7ec4\u88c5\u4e0a\u4e0b\u6587\uff1a\u5bf9\u6bcf\u4e2a\u7236\u5757\uff0c\u4ec5\u4fdd\u7559\u547d\u4e2d\u53e5\u53ca\u5176\u90bb\u8fd1\u7a97\u53e3\uff0c\u5e76\u52a0\u4e0a\u6807\u9898\u8def\u5f84\ncontexts = []\nfor pid, _ in reranked:\n    hits = groups[pid]\n    context = build_local_window(parent_text(pid), hits, window_sents=1)\n    contexts.append(prefix_with_breadcrumbs(pid) + context)\n\n\nfinal_context = pack_under_budget(contexts, token_budget=3000)    # \u7559\u51fa\u56de\u7b54\u7a7a\u95f4\n<\/code><\/pre>\n<p><strong>\u7236\u5b50\u6bb5\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong><\/li>\n<li>\u5c06\u6587\u6863\u6309\u7ae0\u8282\/\u6bb5\u843d\u7b49\u7ed3\u6784\u5355\u5143\u5207\u6210\u201c\u7236\u5757\u201d\uff08Parent\uff09\uff0c\u518d\u5728\u6bcf\u4e2a\u7236\u5757\u5185\u5207\u51fa\u201c\u5b50\u5757\u201d\uff08\u901a\u5e38\u4e3a\u53e5\u5b50\/\u77ed\u6bb5\u6216\u8005\u7b03\u56fa\u5b9a\u5757\uff09\u3002\u7136\u540e\u4e3a\u201c\u5b50\u5757\u201d\u5efa\u5411\u91cf\u7d22\u5f15\u4ee5\u505a\u9ad8\u7cbe\u5ea6\u53ec\u56de\u3002\u5f53\u68c0\u7d22\u65f6\u5148\u53ec\u56de\u5b50\u5757\uff0c\u518d\u6309 parent\/_id \u805a\u5408\u5e76\u6269\u5c55\u5230\u7236\u5757\u6216\u7236\u5757\u4e2d\u7684\u5c40\u90e8\u7a97\u53e3\uff0c\u517c\u987e\u6700\u540e\u53ec\u56de\u5185\u5bb9\u7684\u7cbe\u51c6\u4e0e\u4e0a\u4e0b\u6587\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong><\/li>\n<li>\n<ul>\n<li>\u7ed3\u6784\u6e05\u6670\u7684\u8bf4\u660e\u6587\u3001\u624b\u518c\u3001\u767d\u76ae\u4e66\u3001\u6cd5\u89c4\u3001FAQ \u805a\u5408\u9875\uff1b<\/li>\n<li>\u9700\u8981\u201c\u53e5\u7ea7\u8bc1\u636e\u51c6\u786e + \u6bb5\/\u5c0f\u8282\u7ea7\u4e0a\u4e0b\u6587\u5b8c\u6574\u201d\u7684\u95ee\u7b54\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u6d41\u7a0b<\/strong><\/li>\n<li>\n<ul>\n<li>\u7ed3\u6784\u7c97\u5207\uff08\u7236\u5757\uff09<\/li>\n<li>\n<ul>\n<li>\u6309\u6807\u9898\u5c42\u7ea7\/\u6bb5\u843d\/\u4ee3\u7801\u5757\u5207\u51fa\u7236\u5757\u3002<\/li>\n<li>\u7236\u5757\u5199\u5165 breadcrumbs\uff08H1\/H2\/&#8230;\uff09\u3001anchor\u3001block\/_type\u3001start\/end\/_offset\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7cbe\u7ec6\u5207\u5206\uff08\u5b50\u5757\uff09<\/li>\n<li>\n<ul>\n<li>\u5728\u7236\u5757\u5185\u90e8\u4ee5\u53e5\u5b50\/\u5b50\u53e5\/\u56fa\u5b9a\u5757\u4e3a\u5355\u4f4d\u5207\u5206\uff08\u53ef\u7528\u9012\u5f52\u5206\u5757\u515c\u5e95\uff09\uff0c\u5c0f\u6bd4\u4f8b overlap\uff08\u6216\u9644\u52a0\u4e0a\u4e00\u53e5\u5185\u5bb9\uff09\u3002<\/li>\n<li>\u4e3a\u6bcf\u4e2a\u5b50\u5757\u8bb0\u5f55child\/_offset\u3001sent\/_index\/_range\u3001parent\/_id\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5efa\u7d22\u5f15\u4e0e\u5b58\u50a8<\/li>\n<li>\n<ul>\n<li>\u5b50\u5757\u5411\u91cf\u7d22\u5f15A\uff1a\u5148\u7f16\u7801\uff0cnormalize \u540e\u5efa\u7d22\u5f15\u3002<\/li>\n<li>\u7236\u5757\u5b58\u50a8B\uff1a\u4fdd\u5b58\u539f\u6587\u4e0e\u7ed3\u6784\u5143\u4fe1\u606f\uff0c\u6b64\u5904\u53ef\u4ee5\u9009\u5efa\u4e00\u4e2a\u7236\u5757\u7ea7\u5411\u91cf\u7d22\u5f15\u7528\u4e8e\u7c97\u6392\u6216\u56de\u9000\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u68c0\u7d22\u4e0e\u7ec4\u88c5<\/li>\n<li>\n<ul>\n<li>\u7528\u7d22\u5f15A\u53ec\u56de top\/_k\/_child \u5b50\u5757\u3002<\/li>\n<li>\u6309 parent\/_id \u5206\u7ec4\u5e76\u805a\u5408\u6253\u5206\uff08max\/mean\/\u547d\u4e2d\u5bc6\u5ea6\uff09\uff0c\u9009\u51fa top\/_m\/_parent \u7236\u5757\u5019\u9009\u3002<\/li>\n<li>\u5bf9 (query, parent\/_text \u6216 parent\/_window) \u4ea4\u53c9\u7f16\u7801\u91cd\u6392\u3002<\/li>\n<li>\u4e0a\u4e0b\u6587\u88c1\u526a\uff1a\u5bf9\u6bcf\u4e2a\u7236\u5757\u4ec5\u4fdd\u7559\u201c\u547d\u4e2d\u5b50\u5757\u00b1\u90bb\u8fd1\u7a97\u53e3\u201d\uff08\u00b11\u20132 \u53e5\u6216 80\u2013200 \u5b57\uff09\uff0c\u52a0\u4e0a\u6807\u9898\u8def\u5f84\u524d\u7f00\uff0c\u63a7\u5236\u6574\u4f53 token \u9884\u7b97\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u6253\u5206\u4e0e\u805a\u5408\u7b56\u7565<\/strong><\/li>\n<li>\n<ul>\n<li>\u7ec4\u5206\u6570\uff1ascore\/_parent = \u03b1\u00b7max(child\/_scores) + (1-\u03b1)\u00b7mean(child\/_scores) + \u03b2\u00b7coverage\uff08\u547d\u4e2d\u5b50\u5757\u6570\/\u7236\u5757\u5b50\u5757\u603b\u6570\uff09\u3002<\/li>\n<li>\u5bc6\u5ea6\u5f52\u4e00\u5316\uff1adensity = sum(exp(score\/_i)) \/ length(parent\/_text)\uff0c\u4e3a\u907f\u514d\u957f\u7236\u5757\u56e0\u547d\u4e2d\u591a\u800c\u201c\u5929\u7136\u5360\u4f18\u201d\u3002<\/li>\n<li>\u7a97\u53e3\u5408\u5e76\uff1a\u540c\u4e00\u7236\u5757\u5185\u76f8\u90bb\u547d\u4e2d\u7a97\u53e3\u82e5\u95f4\u8ddd\u5c0f\u4e8e\u9608\u503c\u5219\u5408\u5e76\uff0c\u51cf\u5c11\u91cd\u590d\u4e0e\u788e\u7247\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4e0e\u201c\u5c0f-\u5927\u5206\u5757\u201d\u7684\u5173\u7cfb<\/strong><\/li>\n<li>\n<ul>\n<li>\u5c0f-\u5927\u5206\u5757\u662f\u68c0\u7d22\u5de5\u4f5c\u6d41\uff08\u5c0f\u7c92\u5ea6\u53ec\u56de\u2192\u5927\u7c92\u5ea6\u4e0a\u4e0b\u6587\uff09\uff1b<\/li>\n<li>\u7236\u5b50\u6bb5\u5206\u5757\u662f\u6570\u636e\u5efa\u6a21\u4e0e\u7d22\u5f15\u8bbe\u8ba1\uff08\u663e\u5f0f\u7ef4\u62a4 parent\u2013child \u6620\u5c04\uff09\u3002<\/li>\n<li>\u4e24\u8005\u5f3a\u76f8\u5173\u3001\u5e38\u914d\u5408\u4f7f\u7528\uff1a\u7236\u5b50\u6620\u5c04\u8ba9\u5c0f-\u5927\u6269\u5c55\u66f4\u7a33\u3001\u66f4\u6613\u53bb\u91cd\u4e0e\u56de\u94fe\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u793a\u4f8b<\/strong><\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>from typing import List, Dict, Tuple\nimport numpy as np\nfrom sentence_transformers import SentenceTransformer\n\n\n\n\nembedder = SentenceTransformer(&quot;BAAI\/bge-m3&quot;)\n\n\ndef search_parent_child(query: str, top_k_child=40, top_m_parent=3, window_chars=180):\n    q = embedder.encode([query], normalize_embeddings=True)[0]\n    hits = small_index.search(q, top_k=top_k_child)  # \u8fd4\u56de [(child_id, score), ...]\n    # \u5206\u7ec4\n    groups: Dict[str, List[Tuple[str, float]]] = {}\n    for cid, score in hits:\n        p = child_parent_id[cid]\n        groups.setdefault(p, []).append((cid, float(score)))\n    \n    # \u805a\u5408\u6253\u5206\uff08max + coverage\uff09\n    scored = []\n    for pid, items in groups.items():\n        scores = np.array([s for _, s in items])\n        agg = 0.7 * scores.max() + 0.3 * (len(items) \/ (len(parents[pid][&quot;sent_spans&quot;]) + 1e-6))\n        scored.append((pid, float(agg)))\n    scored.sort(key=lambda x: x[1], reverse=True)\n    candidates = [pid for pid, _ in scored[:top_m_parent]]\n    \n    # \u4e3a\u6bcf\u4e2a\u7236\u5757\u6784\u9020\u201c\u547d\u4e2d\u7a97\u53e3\u201d\n    contexts = []\n    for pid in candidates:\n        ptext = parents[pid][&quot;text&quot;]\n        # \u627e\u5230\u5b50\u5757\u547d\u4e2d\u533a\u95f4\u5e76\u5408\u5e76\u7a97\u53e3\n        spans = sorted([(children[cid][&quot;start&quot;], children[cid][&quot;end&quot;]) for cid, _ in groups[pid]])\n        merged = []\n        for s, e in spans:\n            s = max(0, s - window_chars)\n            e = min(len(ptext), e + window_chars)\n            if not merged or s &gt; merged[-1][1] + 50:\n                merged.append([s, e])\n            else:\n                merged[-1][1] = max(merged[-1][1], e)\n        windows = [ptext[s:e] for s, e in merged]\n        prefix = &quot; &gt; &quot;.join(parents[pid][&quot;meta&quot;].get(&quot;breadcrumbs&quot;, [])[-3:])\n        contexts.append((pid, f&quot;[{prefix}]\/n&quot; + &quot;\/n...\/n&quot;.join(windows)))\n    \n    # \u4ea4\u53c9\u7f16\u7801\u91cd\u6392\uff08\u6b64\u5904\u7528\u5360\u4f4d\u51fd\u6570\uff09\n    reranked = cross_encoder_rerank(query, [c[1] for c in contexts])  # \u8fd4\u56de indices \u987a\u5e8f\n    ordered = [contexts[i] for i in reranked]\n    return ordered  # [(parent_id, context_text), ...]\n<\/code><\/pre>\n<ul>\n<li><strong>\u8c03\u53c2\u5efa\u8bae<\/strong>\uff08\u4ec5\u4f5c\u53c2\u8003\uff0c\u5177\u4f53\u9700\u8981\u6309\u7167\u5b9e\u9645\u6765\uff09<\/li>\n<li>\u8c03\u53c2\u987a\u5e8f\uff1a\u5148\u5b9a\u7236\/\u5b50\u5757\u957f\u5ea6 \u2192 \u6807\u5b9a top\/_k\/_child \u4e0e\u805a\u5408\u6743\u91cd \u2192 \u8c03\u6574\u7a97\u53e3\u5927\u5c0f\u4e0e\u5408\u5e76\u9608\u503c \u2192 \u6700\u540e\u63a5\u5165\u4ea4\u53c9\u7f16\u7801\u91cd\u6392\u5e76\u63a7\u5236 token \u9884\u7b97\u3002<\/li>\n<\/ul>\n<p><strong>\u4ee3\u7406\u5f0f\u5206\u5757<\/strong><\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong><\/li>\n<li>\u4f7f\u7528\u4e00\u4e2a\u5c0f\u6e29\u5ea6\u3001\u5f3a\u7ea6\u675f\u7684 LLM Agent \u6a21\u62df\u201c\u4eba\u7c7b\u9605\u8bfb\u4e0e\u7f16\u6392\u201d\uff0c\u6839\u636e\u8bed\u4e49\u3001\u7ed3\u6784\u4e0e\u4efb\u52a1\u76ee\u6807\u52a8\u6001\u51b3\u5b9a\u5206\u5757\u8fb9\u754c\uff0c\u5e76\u8f93\u51fa\u7ed3\u6784\u5316\u8fb9\u754c\u4fe1\u606f\u4e0e\u7406\u7531\uff08rationale \u53ef\u9009\uff0c\u4e0d\u7528\u4e8e\u68c0\u7d22\uff09\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u9002\u7528\u573a\u666f<\/strong><\/li>\n<li>\n<ul>\n<li>\u9ad8\u5ea6\u590d\u6742\u3001\u957f\u7bc7\u3001\u975e\u7ed3\u6784\u5316\u4e14\u6df7\u5408\u683c\u5f0f\uff08\u6587\u672c+\u4ee3\u7801+\u8868\u683c\uff09\u7684\u6587\u6863\uff1b<\/li>\n<li>\u7ed3\u6784\/\u8bed\u4e49\/\u4e3b\u9898\u7b56\u7565\u5355\u72ec\u4f7f\u7528\u96be\u4ee5\u53d6\u5f97\u7406\u60f3\u8fb9\u754c\u65f6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u65f6\u7684\u6ce8\u610f\u4e8b\u9879<\/strong><\/li>\n<li>\n<ul>\n<li>\u89c4\u5219\u62a4\u680f\uff1a<\/li>\n<li>\n<ul>\n<li>\u7981\u6b62\u5728\u4ee3\u7801\u5757\u3001\u8868\u683c\u5355\u5143\u3001\u5f15\u7528\u5757\u4e2d\u95f4\u5207\u5206\uff0c\u5bf9\u56fe\u7247\/\u516c\u5f0f\u4f5c\u4e3a\u539f\u5b50\u5355\u5143\u5904\u7406\u3002<\/li>\n<li>\u4fdd\u6301\u6807\u9898\u94fe\u8def\u5b8c\u6574\uff0c\u5f3a\u5236\u6700\u5c0f\/\u6700\u5927\u5757\u957f\uff08min\/max\/_chars \/ min\/max\/_sents\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u76ee\u6807\u5bf9\u9f50\uff1a<\/li>\n<li>\u5728\u7cfb\u7edf\u63d0\u793a\u4e2d\u660e\u786e\u201c\u4e3a\u4e86\u68c0\u7d22\u95ee\u7b54\/\u7528\u4e8e\u6458\u8981\/\u7528\u4e8e\u8bca\u65ad\u201d\u7684\u76ee\u6807\uff0cAgent \u4ee5\u4efb\u52a1\u4f18\u5148\u7ea7\u51b3\u5b9a\u8fb9\u754c\u4e0e\u4e0a\u4e0b\u6587\u5197\u4f59\u5ea6\u3002<\/li>\n<li>\u7ed3\u6784\u5316\u8f93\u51fa\uff1a<\/li>\n<li>\u8981\u6c42\u8f93\u51fa segments: [{start\/_offset, end\/_offset, title\/_path, reason}]\uff0c\u4e0d\u80fd\u63a5\u53d7\u81ea\u7531\u6587\u672c\u3002<\/li>\n<li>\u81ea\u68c0\u4e0e\u56de\u9000\uff1a<\/li>\n<li>Agent \u4ea7\u51fa\u7684\u8fb9\u754c\u5148\u8fc7\u4e00\u904d\u7ea6\u675f\u6821\u9a8c\u5668\uff08\u5982\u957f\u5ea6\u3001\u539f\u5b50\u5757\u3001\u987a\u5e8f\u7b49\uff09\uff0c\u4e0d\u7b26\u5408\u89c4\u5219\u7684\u5185\u5bb9\u5219\u81ea\u52a8\u56de\u9000\u5230\u9012\u5f52\/\u53e5\u7ea7\u5206\u5757\u3002<\/li>\n<li>\u6210\u672c\u63a7\u5236\uff1a<\/li>\n<li>\n<ul>\n<li>\u957f\u6587\u5206\u6279\u9605\u8bfb\uff08\u5206\u6bb5\u6ed1\u52a8\u7a97\u53e3\uff09\uff1b<\/li>\n<li>\u5728\u6bcf\u6bb5\u672b\u5c3e\u53ea\u8f93\u51fa\u8fb9\u754c\u8349\u6848\uff0c\u6700\u7ec8\u6c47\u603b\u5e76\u53bb\u91cd\uff1b<\/li>\n<li>\u6e29\u5ea6\u4f4e\uff08\u22640.3\uff09\u3001max\/_tokens \u53d7\u63a7\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u793a\u4f8b<\/strong>\uff1aAgent \u8f93\u51fa\u6a21\u5f0f\uff08\u4f2a Prompt \u7247\u6bb5\uff09<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>\u7cfb\u7edf\uff1a\u4f60\u662f\u5206\u5757\u5668\u3002\u76ee\u6807\uff1a\u4e3aRAG\u68c0\u7d22\u521b\u5efa\u9ad8\u5185\u805a\u3001\u53ef\u8ffd\u6eaf\u7684\u5757\u3002\u89c4\u5219\uff1a\n1) \u4e0d\u5f97\u5728\u4ee3\u7801\/\u8868\u683c\/\u516c\u5f0f\u4e2d\u95f4\u5207\u5206\uff1b\n2) \u6bcf\u5757400-1000\u5b57\uff1b\n3) \u4fdd\u6301\u6807\u9898\u8def\u5f84\u5b8c\u6574\uff1b\n4) \u5c3d\u91cf\u8ba9\u201c\u5b9a\u4e49+\u89e3\u91ca\u201d\u5728\u540c\u4e00\u5757\uff1b\n5) \u8f93\u51faJSON\uff0c\u542b start_offset\/end_offset\/title_path\u3002\n\n\n\u7528\u6237\uff1a&lt;\u6587\u6863\u7247\u6bb5\u6587\u672c&gt;\n\u52a9\u624b\uff08\u793a\u4f8b\u8f93\u51fa\uff09\uff1a\n{\n  &quot;segments&quot;: [\n    {&quot;start&quot;: 0, &quot;end&quot;: 812, &quot;title_path&quot;: [&quot;\u6307\u5357&quot;,&quot;\u5b89\u88c5&quot;], &quot;reason&quot;: &quot;\u5b8c\u6574\u6b65\u9aa4+\u6ce8\u610f\u4e8b\u9879&quot;},\n    {&quot;start&quot;: 813, &quot;end&quot;: 1620, &quot;title_path&quot;: [&quot;\u6307\u5357&quot;,&quot;\u914d\u7f6e&quot;], &quot;reason&quot;: &quot;\u53c2\u6570\u8868\u4e0e\u793a\u4f8b\u7d27\u5bc6\u76f8\u5173&quot;}\n  ]\n}\n<\/code><\/pre>\n<ul>\n<li><strong>\u96c6\u6210\u7684\u6d41\u7a0b<\/strong><\/li>\n<li>\n<ul>\n<li>\u7c97\u5207\uff1a\u5148\u7528\u7ed3\u6784\u611f\u77e5\/\u9012\u5f52\u7b56\u7565\u83b7\u5f97\u521d\u6b65\u5757\uff0c\u964d\u4f4e Agent \u5904\u7406\u8de8\u5ea6\u3002<\/li>\n<li>Agent \u7cbe\u4fee\uff1a\u5bf9\u201c\u7591\u96be\u5757\u201d\uff08\u8fc7\u957f\/\u591a\u683c\u5f0f\/\u4e3b\u9898\u6df7\u6742\uff09\u8c03\u7528 Agent \u7ec6\u5316\u8fb9\u754c\u3002<\/li>\n<li>\u8d28\u68c0\uff1a\u89c4\u5219\u6821\u9a8c + \u8bed\u4e49\u7a00\u758f\u5ea6\u68c0\u6d4b\uff08\u5757\u5185\u76f8\u4f3c\u5ea6\u65b9\u5dee\u8fc7\u5927\u5219\u518d\u7ec6\u5206\uff09\u3002<\/li>\n<li>\u5199\u5165 metadata\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>4.5 \u6df7\u5408\u5206\u5757<\/h2>\n<p>\u5355\u4e00\u7b56\u7565\u96be\u8986\u76d6\u6240\u6709\u6587\u6863\u4e0e\u573a\u666f\u3002\u6df7\u5408\u5206\u5757\u901a\u8fc7\u201c\u5148\u7c97\u540e\u7ec6\u3001\u6309\u9700\u7ec6\u5316\u201d\uff0c\u5728\u6548\u7387\u3001\u53ef\u8ffd\u6eaf\u6027\u4e0e\u7b54\u6848\u8d28\u91cf\u4e4b\u95f4\u53d6\u5f97\u7a33\u5065\u5e73\u8861\u3002<\/p>\n<ul>\n<li><strong>\u5206\u5757\u7b56\u7565<\/strong><\/li>\n<li>\u5148\u7528\u5b8f\u89c2\u8fb9\u754c\uff08\u7ed3\u6784\u611f\u77e5\uff09\u505a\u7c97\u7c92\u5ea6\u5207\u5206\uff0c\u518d\u5bf9\u201c\u8fc7\u5927\u6216\u4e3b\u9898\u8de8\u5ea6\u5927\u7684\u5757\u201d\u5e94\u7528\u66f4\u7cbe\u7ec6\u7684\u7b56\u7565\uff08\u9012\u5f52\u3001\u53e5\u5b50\u3001\u8bed\u4e49\/\u4e3b\u9898\uff09\u3002\u67e5\u8be2\u65f6\u914d\u5408\u201c\u5c0f-\u5927\u5206\u5757\u201d\/\u201c\u7236\u5b50\u6bb5\u5206\u5757\u201d\u7684\u68c0\u7d22\u7ec4\u88c5\uff0c\u4ee5\u5c0f\u7cbe\u53ec\u56de\u3001\u4ee5\u5927\u4fdd\u4e0a\u4e0b\u6587\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u6d41\u7a0b<\/strong><\/li>\n<li>\n<ul>\n<li>\u7c97\u5207\uff08\u79bb\u7ebf\uff09\uff1a\u6309\u6807\u9898\/\u6bb5\u843d\/\u4ee3\u7801\u5757\/\u8868\u683c\u7b49\u7ed3\u6784\u5355\u5143\u5207\u5206\uff0c\u6e05\u7406\u566a\u58f0\uff08\u9875\u7709\u9875\u811a\/\u5bfc\u822a\uff09\u3002<\/li>\n<li>\u7ec6\u5316\uff08\u79bb\u7ebf\uff09\uff1a\u5bf9\u8d85\u957f\u6216\u5bc6\u5ea6\u4e0d\u5747\u7684\u5757\uff0c\u6309\u89c4\u5219\u9009\u7528\u9012\u5f52\/\u53e5\u5b50\/\u8bed\u4e49\u5206\u5757\u4e8c\u6b21\u7ec6\u5206\u3002<\/li>\n<li>\u7d22\u5f15\uff08\u79bb\u7ebf\uff09\uff1a\u540c\u65f6\u4e3a\u201c\u5c0f\u5757\u7d22\u5f15\uff08\u53e5\/\u5b50\u53e5\uff09\u201d\u4e0e\u201c\u5927\u5757\u5b58\u50a8\uff08\u6bb5\/\u5c0f\u8282\uff09\u201d\u751f\u6210\u6570\u636e\u4e0emetadata\u3002<\/li>\n<li>\u68c0\u7d22\uff08\u5728\u7ebf\uff09\uff1a\u5c0f\u5757\u9ad8\u7cbe\u5ea6\u53ec\u56de \u2192 \u6309\u7236\u5757\u805a\u5408\u4e0e\u91cd\u6392\u2192 \u5728\u7236\u5757\u4e2d\u62bd\u53d6\u547d\u4e2d\u53e5\u90bb\u57df\u4f5c\u4e3a\u4e0a\u4e0b\u6587\uff0c\u63a7\u5236\u6574\u4f53 token \u9884\u7b97\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u7b56\u7565\u9009\u62e9\u89c4\u5219<\/strong><\/li>\n<li>\n<ul>\n<li>\u82e5\u5757\u7c7b\u578b\u4e3a\u4ee3\u7801\/\u8868\u683c\/\u516c\u5f0f\uff1a\u4fdd\u6301\u539f\u5b50\uff0c\u4e0d\u5728\u4e2d\u95f4\u5207\u5206\uff0c\u76f4\u63a5\u4e0e\u5176\u89e3\u91ca\u6587\u5b57\u6253\u5305\u3002<\/li>\n<li>\u82e5\u4e3a\u5bf9\u8bdd\uff1a\u6309\u8f6e\u6b21\/\u8bf4\u8bdd\u4eba\u505a\u5bf9\u8bdd\u5f0f\u5206\u5757\uff0coverlap \u4f7f\u7528\u201c\u8f6e\u6b21\u91cd\u53e0\u201d\u3002<\/li>\n<li>\u82e5\u4e3a\u666e\u901a\u8bf4\u660e\u6587\/Markdown\u7ae0\u8282\uff1a<\/li>\n<li>\n<ul>\n<li>\u957f\u5ea6 &gt; max\/_coarse\u6216\u53e5\u957f\u65b9\u5dee\u9ad8\/\u6807\u70b9\u7a00\u758f\uff1a\u4f18\u5148\u8bed\u4e49\u5206\u5757\uff08\u53e5\u5411\u91cf+\u7a81\u53d8\u9608\u503c\uff09\u3002<\/li>\n<li>\u5426\u5219\uff1a\u9012\u5f52\u5b57\u7b26\u5206\u5757\uff08\u6807\u9898\/\u6bb5\u843d\/\u6362\u884c\/\u7a7a\u683c\/\u5b57\u7b26\uff09\u4fdd\u6301\u8bed\u4e49\u8fb9\u754c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5bf9\u8fc7\u77ed\u5757\uff1a\u4e0e\u540c\u4e00\u7236\u6807\u9898\u76f8\u90bb\u5757\u5408\u5e76\uff0c\u4f18\u5148\u5411\u540e\u5408\u5e76\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li><strong>\u8d28\u91cf-\u6210\u672c\u6863\u4f4d<\/strong>\uff08\u4ec5\u4f9b\u53c2\u8003\uff09<\/li>\n<li>\n<ul>\n<li>fast\uff1a\u4ec5\u7ed3\u6784\u2192\u9012\u5f52\u3002overlap 5%\u201310%\uff0c\u4e0d\u8dd1\u8bed\u4e49\u5206\u5757\u548c\u4e3b\u9898\u5206\u5757<\/li>\n<li>balanced\uff08\u63a8\u8350\uff09\uff1a\u7ed3\u6784\u2192\u9012\u5f52\uff0c\u5bf9\u5f02\u5e38\u5757\u542f\u7528\u8bed\u4e49\u5206\u5757\uff0c\u5c0f-\u5927\u68c0\u7d22\uff0coverlap 10%\u5de6\u53f3<\/li>\n<li>quality\uff1a\u5728 balanced \u57fa\u7840\u4e0a\u5bf9\u7591\u96be\u5757\u542f\u7528 Agent \u7cbe\u4fee\uff0c\u66f4\u5f3a\u7684\u90bb\u63a5\u6269\u5c55\u4e0ererank<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<ul>\n<li>\u7b80\u6d01\u8c03\u5ea6\u5668\u793a\u4f8b\uff0c \u5c06\u7ed3\u6784\u7c97\u5207\u4e0e\u82e5\u5e72\u7ec6\u5206\u5668\u7ec4\u5408\u4e3a\u4e00\u4e2a\u201c\u6df7\u5408\u5206\u5757\u201d\u5165\u53e3\uff0c\u5173\u952e\u662f\u7c7b\u578b\u5224\u65ad\u4e0e\u957f\u5ea6\u9608\u503c\u63a7\u5236\u3002\u53ef\u4ee5\u628a\u524d\u6587\u5df2\u5b9e\u73b0\u7684\u7ed3\u6784\/\u53e5\u5b50\/\u8bed\u4e49\/\u5bf9\u8bdd\u5206\u5757\u51fd\u6570\u6302\u5165\u6b64\u8c03\u5ea6\u5668\u3002<\/li>\n<\/ul>\n<p>&lt;!&#8212;-&gt;<\/p>\n<pre><code>from typing import List, Dict\n\n\ndef hybrid_chunk(\n    doc_text: str,\n    parse_structure,          # \u51fd\u6570\uff1a\u8fd4\u56de [{'type': 'text|code|table|dialogue', 'text': str, 'breadcrumbs': [...], 'anchor': str}]\n    recursive_splitter,       # \u51fd\u6570\uff1atext -&gt; [{'text': str}]\n    sentence_splitter,        # \u51fd\u6570\uff1atext -&gt; [{'text': str}]\n    semantic_splitter,        # \u51fd\u6570\uff1atext -&gt; [{'text': str}]\n    dialogue_splitter,        # \u51fd\u6570\uff1aturns(list) -&gt; [{'text': str}]\uff0c\u82e5\u65e0\u5bf9\u8bdd\u5219\u5ffd\u7565\n    max_coarse_len: int = 1100,\n    min_chunk_len: int = 320,\n    target_len: int = 750,\n    overlap_ratio: float = 0.1,\n) -&gt; List[Dict]:\n    &quot;&quot;&quot;\n    \u8fd4\u56de\u683c\u5f0f: [{'text': str, 'meta': {...}}]\n    &quot;&quot;&quot;\n    blocks = parse_structure(doc_text)  # \u5148\u62ff\u5230\u7ed3\u6784\u5757\n    chunks: List[Dict] = []\n    \n    def emit(t: str, meta_base: Dict):\n        t = t.strip()\n        if not t:\n            return\n        # \u7ed3\u6784\u91cd\u53e0\u524d\u7f00\uff08\u6807\u9898\u8def\u5f84\uff09\n        bc = &quot; &gt; &quot;.join(meta_base.get(&quot;breadcrumbs&quot;, [])[-3:])\n        prefix = f&quot;[{bc}]\/n&quot; if bc else &quot;&quot;\n        chunks.append({\n            &quot;text&quot;: (prefix + t) if not t.startswith(prefix) else t,\n            &quot;meta&quot;: meta_base\n        })\n    \n    for b in blocks:\n        t = b[&quot;text&quot;]\n        btype = b.get(&quot;type&quot;, &quot;text&quot;)\n        \n        # \u539f\u5b50\u5757\uff1a\u4ee3\u7801\/\u8868\u683c\n        if btype in {&quot;code&quot;, &quot;table&quot;, &quot;formula&quot;}:\n            emit(t, {**b, &quot;splitter&quot;: &quot;atomic&quot;})\n            continue\n        \n        # \u5bf9\u8bdd\u5757\n        if btype == &quot;dialogue&quot;:\n            for ck in dialogue_splitter(b.get(&quot;turns&quot;, [])):\n                emit(ck[&quot;text&quot;], {**b, &quot;splitter&quot;: &quot;dialogue&quot;})\n            continue\n        \n        # \u666e\u901a\u6587\u672c\uff1a\u4f9d\u636e\u957f\u5ea6\u4e0e\u201c\u53ef\u8bfb\u6027\u201d\u542f\u7528\u4e0d\u540c\u7ec6\u5206\u5668\n        if len(t) &lt;= max_coarse_len:\n            # \u4e2d\u77ed\u6587\u672c\uff1a\u9012\u5f52 or \u53e5\u5b50\n            sub = recursive_splitter(t)\n            # \u5408\u5e76\u8fc7\u77ed\u5b50\u5757\n            buf = &quot;&quot;\n            for s in sub:\n                txt = s[&quot;text&quot;]\n                if len(buf) + len(txt) &lt; min_chunk_len:\n                    buf += txt\n                else:\n                    emit(buf or txt, {**b, &quot;splitter&quot;: &quot;recursive&quot;})\n                    buf = &quot;&quot; if buf else &quot;&quot;\n            if buf:\n                emit(buf, {**b, &quot;splitter&quot;: &quot;recursive&quot;})\n        else:\n            # \u8d85\u957f\u6587\u672c\uff1a\u8bed\u4e49\u5206\u5757\u4f18\u5148\n            for ck in semantic_splitter(t):\n                emit(ck[&quot;text&quot;], {**b, &quot;splitter&quot;: &quot;semantic&quot;})\n    \n    # \u8f7b\u91cf\u5b57\u7b26\u91cd\u53e0\uff08\u53ef\u9009\uff09\n    if overlap_ratio &gt; 0:\n        overlapped = []\n        for i, ch in enumerate(chunks):\n            overlapped.append(ch)\n            if i + 1 &lt; len(chunks) and ch[&quot;meta&quot;].get(&quot;breadcrumbs&quot;) == chunks[i+1][&quot;meta&quot;].get(&quot;breadcrumbs&quot;):\n                # \u5728\u76f8\u90bb\u540c\u7ae0\u8282\u5757\u95f4\u5f15\u5165\u5c0f\u6bd4\u4f8b\u91cd\u53e0\n                ov = int(len(ch[&quot;text&quot;]) * overlap_ratio)\n                if ov &gt; 0:\n                    head = ch[&quot;text&quot;][-ov:]\n                    chunks[i+1][&quot;text&quot;] = head + chunks[i+1][&quot;text&quot;]\n        chunks = overlapped\n    \n    return chunks\n<\/code><\/pre>\n<h2>\u4e94\u3001\u7ed3\u8bba<\/h2>\n<p><img decoding=\"async\" width=\"723\" height=\"381\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdmSiS\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<h2>\u5f80\u671f\u56de\u987e<\/h2>\n<ol>\n<li>\u544a\u522b\u6570\u636e\u65e0\u5e8f\uff1a\u5f97\u7269\u6570\u636e\u7814\u53d1\u4e0e\u7ba1\u7406\u5e73\u53f0\u7684\u7834\u5c40\u4e4b\u8def<\/li>\n<li>\u4ece\u4e00\u6b21\u542f\u52a8\u5931\u8d25\u6df1\u5165\u5256\u6790\uff1aSpring\u5faa\u73af\u4f9d\u8d56\u7684\u771f\u76f8\uff5c\u5f97\u7269\u6280\u672f<\/li>\n<li>Apex AI\u8f85\u52a9\u7f16\u7801\u52a9\u624b\u7684\u8bbe\u8ba1\u548c\u5b9e\u8df5\uff5c\u5f97\u7269\u6280\u672f<\/li>\n<li>\u4ece JSON \u5b57\u7b26\u4e32\u5230 Java \u5bf9\u8c61\uff1aFastjson 1.2.83 \u5168\u7a0b\u89e3\u6790\uff5c\u5f97\u7269\u6280\u672f<\/li>\n<li>\u7528\u597d TTL Agent \u4e0d\u8e29\u96f7\uff1a\u907f\u5f00\u5185\u5b58\u6cc4\u9732\u4e0eCPU 100%\u4e24\u5927\u6838\u5fc3\u5751\uff5c\u5f97\u7269\u6280\u672f<\/li>\n<\/ol>\n<h2>\u6587 \/\u6606\u5c9a<\/h2>\n<p>\u5173\u6ce8\u5f97\u7269\u6280\u672f\uff0c\u6bcf\u5468\u66f4\u65b0\u6280\u672f\u5e72\u8d27<\/p>\n<p>\u8981\u662f\u89c9\u5f97\u6587\u7ae0\u5bf9\u4f60\u6709\u5e2e\u52a9\u7684\u8bdd\uff0c\u6b22\u8fce\u8bc4\u8bba\u8f6c\u53d1\u70b9\u8d5e\uff5e<\/p>\n<p>\u672a\u7ecf\u5f97\u7269\u6280\u672f\u8bb8\u53ef\u4e25\u7981\u8f6c\u8f7d\uff0c\u5426\u5219\u4f9d\u6cd5\u8ffd\u7a76\u6cd5\u5f8b\u8d23\u4efb\u3002<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000047358624\">https:\/\/segmentfault.com\/a\/1190000047358624<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u80cc \u666f \u5728 RAG \u7cfb\u7edf\u4e2d\uff0c\u5373\u4fbf\u91c7\u7528\u6027\u80fd\u5353\u8d8a\u7684 LLM \u5e76\u53cd\u590d\u6253\u78e8 Prompt\uff0c\u95ee\u7b54\u4ecd\u53ef\u80fd\u51fa\u73b0\u4e0a\u4e0b\u6587\u7f3a\u5931 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021060","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021060"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021060\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}