{"id":20961,"date":"2024-07-04T11:10:37","date_gmt":"2024-07-04T03:10:37","guid":{"rendered":"https:\/\/aif.amtbbs.org\/?p=20961"},"modified":"2024-07-04T11:38:56","modified_gmt":"2024-07-04T03:38:56","slug":"%e7%bb%86%e6%95%b0rag%e7%9a%8412%e4%b8%aa%e7%97%9b%e7%82%b9%ef%bc%8c%e8%8b%b1%e4%bc%9f%e8%be%be%e9%ab%98%e7%ba%a7%e6%9e%b6%e6%9e%84%e5%b8%88%e4%ba%b2%e6%8e%88%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/aif.amtbbs.org\/index.php\/2024\/07\/04\/20961\/","title":{"rendered":"\u7ec6\u6570RAG\u768412\u4e2a\u75db\u70b9\uff0c\u82f1\u4f1f\u8fbe\u9ad8\u7ea7\u67b6\u6784\u5e08\u4eb2\u6388\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"<div><img data-dominant-color=\"c6bfbe\" data-has-transparency=\"false\" style=\"--dominant-color: #c6bfbe;\" loading=\"lazy\" decoding=\"async\" class=\"not-transparent alignnone size-full wp-image-20969\" src=\"https:\/\/aiforumimage.oss-cn-shanghai.aliyuncs.com\/wp-content\/uploads\/2024\/07\/998892518652b605cee5862b730f10d690a8da-300x167-1-1.jpg\" width=\"300\" height=\"167\" alt=\"\" srcset=\"https:\/\/aiforumimage.oss-cn-shanghai.aliyuncs.com\/wp-content\/uploads\/2024\/07\/998892518652b605cee5862b730f10d690a8da-300x167-1-1.jpg 300w, https:\/\/aiforumimage.oss-cn-shanghai.aliyuncs.com\/wp-content\/uploads\/2024\/07\/998892518652b605cee5862b730f10d690a8da-300x167-1-1-150x84.jpg 150w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/div>\n<div><\/div>\n<div class=\"article-desc\">\u8fd1\u65e5\uff0c\u82f1\u4f1f\u8fbe\u751f\u6210\u5f0fAI\u9ad8\u7ea7\u89e3\u51b3\u65b9\u6848\u67b6\u6784\u5e08Wenqi Glantz \u5728 Towards Data Science \u53d1\u5e03\u4e86\u4e00\u7bc7\u6587\u7ae0\uff0c\u68b3\u7406\u4e86 12 \u4e2a RAG \u7684\u75db\u70b9\u5e76\u7ed9\u51fa\u4e86\u76f8\u5e94\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/div>\n<div id=\"postspictures\" class=\"article-content\">\n<div id=\"container\" class=\"container am-engine\" data-v-1d7a5742=\"\" data-element=\"root\">\n<p>\u68c0\u7d22\u589e\u5f3a\u5f0f\u751f\u6210\uff08RAG\uff09\u662f\u4e00\u79cd\u4f7f\u7528\u68c0\u7d22\u63d0\u5347\u8bed\u8a00\u6a21\u578b\u7684\u6280\u672f\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5c31\u662f\u5728\u8bed\u8a00\u6a21\u578b\u751f\u6210\u7b54\u6848\u4e4b\u524d\uff0c\u5148\u4ece\u5e7f\u6cdb\u7684\u6587\u6863\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u76f8\u5173\u4fe1\u606f\uff0c\u7136\u540e\u5229\u7528\u8fd9\u4e9b\u4fe1\u606f\u6765\u5f15\u5bfc\u751f\u6210\u8fc7\u7a0b\u3002\u8fd9\u79cd\u6280\u672f\u80fd\u6781\u5927\u63d0\u5347\u5185\u5bb9\u7684\u51c6\u786e\u6027\u548c\u76f8\u5173\u6027\uff0c\u5e76\u80fd\u6709\u6548\u7f13\u89e3\u5e7b\u89c9\u95ee\u9898\uff0c\u63d0\u9ad8\u77e5\u8bc6\u66f4\u65b0\u7684\u901f\u5ea6\uff0c\u5e76\u589e\u5f3a\u5185\u5bb9\u751f\u6210\u7684\u53ef\u8ffd\u6eaf\u6027\u3002RAG \u65e0\u7591\u662f\u6700\u6fc0\u52a8\u4eba\u5fc3\u7684\u4eba\u5de5\u667a\u80fd\u7814\u7a76\u9886\u57df\u4e4b\u4e00\u3002\u6709\u5173 RAG \u7684\u66f4\u591a\u8be6\u60c5\u8bf7\u53c2\u9605\u673a\u5668\u4e4b\u5fc3\u4e13\u680f\u6587\u7ae0\u300a\u4e13\u8865\u5927\u6a21\u578b\u77ed\u677f\u7684RAG\u6709\u54ea\u4e9b\u65b0\u8fdb\u5c55\uff1f\u8fd9\u7bc7\u7efc\u8ff0\u8bb2\u660e\u767d\u4e86\u300b\u3002<\/p>\n<p class=\"js_darkmode__9\">\u4f46 RAG \u4e5f\u5e76\u975e\u5b8c\u7f8e\uff0c\u7528\u6237\u5728\u4f7f\u7528\u65f6\u4e5f\u5e38\u4f1a\u906d\u9047\u4e00\u4e9b\u300c\u75db\u70b9\u300d\u3002\u8fd1\u65e5\uff0c\u82f1\u4f1f\u8fbe\u751f\u6210\u5f0fAI\u9ad8\u7ea7\u89e3\u51b3\u65b9\u6848\u67b6\u6784\u5e08Wenqi Glantz \u5728 Towards Data Science \u53d1\u5e03\u4e86\u4e00\u7bc7\u6587\u7ae0\uff0c\u68b3\u7406\u4e86 12 \u4e2a RAG \u7684\u75db\u70b9\u5e76\u7ed9\u51fa\u4e86\u76f8\u5e94\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><img decoding=\"async\" title=\"\u56fe\u7247\" src=\"https:\/\/s4.51cto.com\/oss\/202407\/04\/34922fd90c07dfc6dba651428805c3f0ccbaa4.webp\" alt=\"\u56fe\u7247\" data-type=\"inline\" \/><\/p>\n<p class=\"js_darkmode__12\">\u6587\u7ae0\u76ee\u5f55\u5982\u4e0b\uff1a<\/p>\n<p class=\"js_darkmode__14\">\u75db\u70b9 1\uff1a\u5185\u5bb9\u7f3a\u5931<\/p>\n<p class=\"js_darkmode__15\">\u75db\u70b9 2\uff1a\u9519\u8fc7\u6392\u540d\u9760\u524d\u7684\u6587\u6863<\/p>\n<p class=\"js_darkmode__16\">\u75db\u70b9 3\uff1a\u4e0d\u5728\u4e0a\u4e0b\u6587\u4e2d\u2014\u2014\u5408\u5e76\u7b56\u7565\u7684\u5c40\u9650<\/p>\n<p class=\"js_darkmode__17\">\u75db\u70b9 4\uff1a\u672a\u63d0\u53d6\u51fa\u6765<\/p>\n<p class=\"js_darkmode__18\">\u75db\u70b9 5\uff1a\u683c\u5f0f\u9519\u8bef<\/p>\n<p class=\"js_darkmode__19\">\u75db\u70b9 6\uff1a\u4e0d\u6b63\u786e\u7684\u5177\u4f53\u8bf4\u660e<\/p>\n<p class=\"js_darkmode__20\">\u75db\u70b9 7\uff1a\u4e0d\u5b8c\u5907<\/p>\n<p class=\"js_darkmode__21\">\u75db\u70b9 8\uff1a\u6570\u636e\u6444\u53d6\u7684\u53ef\u6269\u5c55\u6027<\/p>\n<p class=\"js_darkmode__22\">\u75db\u70b9 9\uff1a\u7ed3\u6784\u5316\u6570\u636e\u95ee\u7b54<\/p>\n<p class=\"js_darkmode__23\">\u75db\u70b9 10\uff1a\u4ece\u590d\u6742 PDF \u63d0\u53d6\u6570\u636e<\/p>\n<p class=\"js_darkmode__24\">\u75db\u70b9 11\uff1a\u540e\u5907\u6a21\u578b<\/p>\n<p class=\"js_darkmode__25\">\u75db\u70b9 12\uff1aLLM \u5b89\u5168<\/p>\n<p class=\"js_darkmode__27\">\u5176\u4e2d 7 \u4e2a\u75db\u70b9\uff08\u89c1\u4e0b\u56fe\uff09\u6765\u81ea Barnett et al. \u7684\u8bba\u6587\u300aSeven Failure Points When Engineering a Retrieval Augmented Generation System\u300b\uff0c\u6b64\u5916\u8fd8\u53e6\u5916\u589e\u52a0\u4e86 5 \u4e2a\u5e38\u89c1\u75db\u70b9\u3002<\/p>\n<p><img decoding=\"async\" title=\"\u56fe\u7247\" src=\"https:\/\/s3.51cto.com\/oss\/202407\/04\/78d0761237f4eb0e11a6513340b7190c93f81e.webp\" alt=\"\u56fe\u7247\" data-type=\"inline\" \/><\/p>\n<p class=\"js_darkmode__30\">\u8fd9\u4e9b\u75db\u70b9\u5bf9\u5e94\u7684\u89e3\u51b3\u65b9\u6848\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" title=\"\u56fe\u7247\" src=\"https:\/\/s7.51cto.com\/oss\/202407\/04\/b97b93a01b4a54badf2904b356188e85f45381.webp\" alt=\"\u56fe\u7247\" data-type=\"inline\" \/><\/p>\n<h4>\u75db\u70b9 1\uff1a\u5185\u5bb9\u7f3a\u5931<\/h4>\n<p class=\"js_darkmode__35\">\u77e5\u8bc6\u5e93\u4e2d\u7f3a\u5931\u4e0a\u4e0b\u6587\u3002\u5f53\u77e5\u8bc6\u5e93\u4e2d\u6ca1\u6709\u7b54\u6848\u65f6\uff0cRAG \u7cfb\u7edf\u4f1a\u63d0\u4f9b\u4e00\u4e2a\u770b\u4f3c\u53ef\u4fe1\u4f46\u5e76\u4e0d\u6b63\u786e\u7684\u7b54\u6848\uff0c\u800c\u4e0d\u4f1a\u627f\u8ba4\u5b83\u4e0d\u77e5\u9053\u3002\u7528\u6237\u4f1a\u6536\u5230\u9519\u8bef\u4fe1\u606f\uff0c\u906d\u9047\u632b\u6298\u3002<\/p>\n<p class=\"js_darkmode__37\">\u4eba\u4eec\u63d0\u51fa\u4e86\u4e24\u79cd\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p class=\"js_darkmode__39\"><strong>\u6e05\u6d01\u6570\u636e<\/strong><\/p>\n<p class=\"js_darkmode__41\">\u8f93\u5165\u5783\u573e\uff0c\u90a3\u4e5f\u5fc5\u5b9a\u8f93\u51fa\u5783\u573e\u3002\u5982\u679c\u4f60\u7684\u6e90\u6570\u636e\u8d28\u91cf\u4f4e\u52a3\uff0c\u6bd4\u5982\u5305\u542b\u4e92\u76f8\u51b2\u7a81\u7684\u4fe1\u606f\uff0c\u90a3\u4e0d\u7ba1\u4f60\u7684 RAG \u5de5\u4f5c\u6784\u5efa\u5f97\u591a\u4e48\u597d\uff0c\u5b83\u90fd\u4e0d\u53ef\u80fd\u7528\u4f60\u8f93\u5165\u7684\u5783\u573e\u795e\u5947\u5730\u8f93\u51fa\u9ad8\u8d28\u91cf\u7ed3\u679c\u3002\u8fd9\u4e2a\u89e3\u51b3\u65b9\u6848\u4e0d\u4ec5\u9002\u7528\u4e8e\u8fd9\u4e2a\u75db\u70b9\uff0c\u800c\u4e14\u9002\u7528\u4e8e\u672c\u6587\u5217\u51fa\u7684\u6240\u6709\u75db\u70b9\u3002\u4efb\u4f55 RAG \u5de5\u4f5c\u6d41\u7a0b\u60f3\u8981\u83b7\u5f97\u4f18\u826f\u8868\u73b0\uff0c\u90fd\u5fc5\u987b\u5148\u6e05\u6d01\u6570\u636e\u3002<\/p>\n<p class=\"js_darkmode__43\">\u4e0b\u9762\u5217\u51fa\u4e86\u51e0\u4e2a\u6e05\u6d01\u6570\u636e\u7684\u5e38\u7528\u7b56\u7565\uff1a<\/p>\n<ul data-id=\"ua73dd4b-aECM4OcY\">\n<li data-id=\"ld70c578-K8Q9SLOk\">\u79fb\u9664\u566a\u58f0\u548c\u4e0d\u76f8\u5173\u4fe1\u606f\uff1a\u8fd9\u5305\u62ec\u79fb\u9664\u7279\u6b8a\u5b57\u7b26\u3001\u505c\u7528\u8bcd\uff08stop words\uff0c\u5982 the \u548c a\uff09\u3001HTML \u6807\u7b7e\u3002<\/li>\n<li data-id=\"ld70c578-PRJ9bC5Z\">\u8bc6\u522b\u548c\u7ea0\u6b63\u9519\u8bef\uff1a\u5305\u62ec\u62fc\u5199\u9519\u8bef\u3001\u9519\u522b\u5b57\u548c\u8bed\u6cd5\u9519\u8bef\u3002\u53ef\u4ee5\u4f7f\u7528\u62fc\u5199\u68c0\u67e5\u5668\u548c\u8bed\u8a00\u6a21\u578b\u7b49\u5de5\u5177\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/li>\n<li data-id=\"ld70c578-WNEG9FTE\">\u53bb\u91cd\uff1a\u79fb\u9664\u91cd\u590d\u6570\u636e\u8bb0\u5f55\u6216\u53ef\u80fd\u5bfc\u81f4\u68c0\u7d22\u8fc7\u7a0b\u51fa\u73b0\u504f\u5dee\u7684\u76f8\u4f3c\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n<p class=\"js_darkmode__49\">unstructured.io \u7684\u6838\u5fc3\u8f6f\u4ef6\u5e93\u63d0\u4f9b\u4e86\u4e00\u6574\u5957\u6e05\u6d01\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u89e3\u51b3\u8fd9\u4e9b\u6570\u636e\u6e05\u6d01\u9700\u6c42\u3002\u503c\u5f97\u4e00\u8bd5\u3002<\/p>\n<p class=\"js_darkmode__51\"><strong>\u66f4\u597d\u7684\u63d0\u8bcd\u8bbe\u8ba1<\/strong><\/p>\n<p class=\"js_darkmode__53\">\u5bf9\u4e8e\u56e0\u4e3a\u4fe1\u606f\u7f3a\u4e4f\u800c\u5bfc\u81f4\u7cfb\u7edf\u7ed9\u51fa\u770b\u4f3c\u53ef\u4fe1\u5374\u4e0d\u6b63\u786e\u7ed3\u679c\u7684\u95ee\u9898\uff0c\u66f4\u597d\u7684\u63d0\u8bcd\u8bbe\u8ba1\u80fd\u63d0\u4f9b\u5f88\u5927\u5e2e\u52a9\u3002\u901a\u8fc7\u4e3a\u7cfb\u7edf\u7ed9\u51fa\u300c\u5982\u679c\u4f60\u4e0d\u786e\u5b9a\u7b54\u6848\u662f\u4ec0\u4e48\uff0c\u5c31\u544a\u8bc9\u6211\u4f60\u4e0d\u77e5\u9053\u300d\u8fd9\u6837\u7684\u6307\u793a\uff0c\u5c31\u80fd\u9f13\u52b1\u6a21\u578b\u627f\u8ba4\u81ea\u5df1\u7684\u5c40\u9650\uff0c\u5e76\u66f4\u900f\u660e\u5730\u5411\u7528\u6237\u4f20\u8fbe\u5b83\u7684\u4e0d\u786e\u5b9a\u3002\u867d\u7136\u4e0d\u80fd\u4fdd\u8bc1 100% \u51c6\u786e\u5ea6\uff0c\u4f46\u5728\u6e05\u6d01\u6570\u636e\u4e4b\u540e\uff0c\u7cbe\u5fc3\u8bbe\u8ba1 prompt \u662f\u6700\u597d\u7684\u505a\u6cd5\u4e4b\u4e00\u3002<\/p>\n<h4>\u75db\u70b9 2\uff1a\u9519\u8fc7\u6392\u540d\u9760\u524d\u7684\u6587\u6863<\/h4>\n<p class=\"js_darkmode__57\">\u521d\u59cb\u68c0\u7d22\u8fc7\u7a0b\u4e2d\u7f3a\u5931\u4e0a\u4e0b\u6587\u3002\u5728\u7cfb\u7edf\u7684\u68c0\u7d22\u7ec4\u4ef6\u8fd4\u56de\u7684\u7ed3\u679c\u4e2d\uff0c\u5173\u952e\u6027\u7684\u6587\u6863\u53ef\u80fd\u5e76\u4e0d\u9760\u524d\u3002\u6b63\u786e\u7684\u7b54\u6848\u88ab\u5ffd\u89c6\u4e86\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u65e0\u6cd5\u7ed9\u51fa\u51c6\u786e\u54cd\u5e94\u3002\u4e0a\u8ff0\u8bba\u6587\u4e2d\u5199\u9053\uff1a\u300c\u95ee\u9898\u7684\u7b54\u6848\u5c31\u5728\u6587\u6863\u4e2d\uff0c\u4f46\u6392\u540d\u4e0d\u591f\u9ad8\uff0c\u5c31\u6ca1\u6709\u8fd4\u56de\u7ed9\u7528\u6237\u3002\u300d<\/p>\n<p class=\"js_darkmode__59\">\u7814\u7a76\u8005\u63d0\u51fa\u4e86\u4e24\u79cd\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p class=\"js_darkmode__61\"><strong>\u5bf9 chunk_size \u548c similarity_top_k \u8fdb\u884c\u8d85\u53c2\u6570\u5fae\u8c03<\/strong><\/p>\n<p class=\"js_darkmode__63\">chunk_size \u548c similarity_top_k \u8fd9\u4e24\u4e2a\u53c2\u6570\u53ef\u7528\u4e8e\u7ba1\u7406 RAG \u6a21\u578b\u7684\u6570\u636e\u68c0\u7d22\u8fc7\u7a0b\u7684\u6548\u7387\u548c\u6548\u679c\u3002\u8c03\u6574\u8fd9\u4e24\u4e2a\u53c2\u6570\u4f1a\u5f71\u54cd\u88ab\u68c0\u7d22\u4fe1\u606f\u7684\u8ba1\u7b97\u6548\u7387\u548c\u8d28\u91cf\u4e4b\u95f4\u7684\u6743\u8861\u3002\u4f5c\u8005\u5728\u4e4b\u524d\u4e00\u7bc7\u6587\u7ae0\u4e2d\u63a2\u7d22\u4e86\u5bf9 chunk_size \u548c similarity_top_k \u8fdb\u884c\u8d85\u53c2\u6570\u5fae\u8c03\u7684\u7ec6\u8282\uff1a<\/p>\n<p class=\"js_darkmode__65\">\u8bf7\u8bbf\u95ee\uff1ahttps:\/\/medium.com\/gitconnected\/automating-hyperparameter-tuning-with-llamaindex-72fdd68e3b90<\/p>\n<p class=\"js_darkmode__68\">\u4e0b\u9762\u7ed9\u51fa\u4e86\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_0\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\">param_tuner <span class=\"token operator\">=<\/span> <span class=\"token function\">ParamTuner<\/span><span class=\"token punctuation\">(<\/span>\r\n    param_fn<span class=\"token operator\">=<\/span>objective_function_semantic_similarity<span class=\"token punctuation\">,<\/span>\r\n    param_dict<span class=\"token operator\">=<\/span>param_dict<span class=\"token punctuation\">,<\/span>\r\n    fixed_param_dict<span class=\"token operator\">=<\/span>fixed_param_dict<span class=\"token punctuation\">,<\/span>\r\n    show_progress<span class=\"token operator\">=<\/span>True<span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nresults <span class=\"token operator\">=<\/span> param_tuner<span class=\"token punctuation\">.<\/span><span class=\"token function\">tune<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_0\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__72\">objective_function_semantic_similarity \u51fd\u6570\u7684\u5b9a\u4e49\u5982\u4e0b\uff0c\u5176\u4e2d param_dict \u5305\u542b\u4e86\u53c2\u6570 chunk_size \u548c top_k \u4ee5\u53ca\u5b83\u4eec\u5bf9\u5e94\u7684\u503c\uff1a<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_1\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"># contains the parameters that need to be tuned\r\nparam_dict <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string-property property\">\"chunk_size\"<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token number\">256<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">512<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1024<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-property property\">\"top_k\"<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span>\r\n\r\n\r\n# contains parameters remaining fixed across all runs <span class=\"token keyword\">of<\/span> the tuning process\r\nfixed_param_dict <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token string-property property\">\"docs\"<\/span><span class=\"token operator\">:<\/span> documents<span class=\"token punctuation\">,<\/span>\r\n    <span class=\"token string-property property\">\"eval_qs\"<\/span><span class=\"token operator\">:<\/span> eval_qs<span class=\"token punctuation\">,<\/span>\r\n    <span class=\"token string-property property\">\"ref_response_strs\"<\/span><span class=\"token operator\">:<\/span> ref_response_strs<span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n\r\n\r\ndef <span class=\"token function\">objective_function_semantic_similarity<\/span><span class=\"token punctuation\">(<\/span>params_dict<span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span>\r\n    chunk_size <span class=\"token operator\">=<\/span> params_dict<span class=\"token punctuation\">[<\/span><span class=\"token string\">\"chunk_size\"<\/span><span class=\"token punctuation\">]<\/span>\r\n    docs <span class=\"token operator\">=<\/span> params_dict<span class=\"token punctuation\">[<\/span><span class=\"token string\">\"docs\"<\/span><span class=\"token punctuation\">]<\/span>\r\n    top_k <span class=\"token operator\">=<\/span> params_dict<span class=\"token punctuation\">[<\/span><span class=\"token string\">\"top_k\"<\/span><span class=\"token punctuation\">]<\/span>\r\n    eval_qs <span class=\"token operator\">=<\/span> params_dict<span class=\"token punctuation\">[<\/span><span class=\"token string\">\"eval_qs\"<\/span><span class=\"token punctuation\">]<\/span>\r\n    ref_response_strs <span class=\"token operator\">=<\/span> params_dict<span class=\"token punctuation\">[<\/span><span class=\"token string\">\"ref_response_strs\"<\/span><span class=\"token punctuation\">]<\/span>\r\n\r\n\r\n    # build index\r\n    index <span class=\"token operator\">=<\/span> <span class=\"token function\">_build_index<\/span><span class=\"token punctuation\">(<\/span>chunk_size<span class=\"token punctuation\">,<\/span> docs<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n    # query engine\r\n    query_engine <span class=\"token operator\">=<\/span> index<span class=\"token punctuation\">.<\/span><span class=\"token function\">as_query_engine<\/span><span class=\"token punctuation\">(<\/span>similarity_top_k<span class=\"token operator\">=<\/span>top_k<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n    # <span class=\"token keyword\">get<\/span> predicted responses\r\n    pred_response_objs <span class=\"token operator\">=<\/span> <span class=\"token function\">get_responses<\/span><span class=\"token punctuation\">(<\/span>\r\n        eval_qs<span class=\"token punctuation\">,<\/span> query_engine<span class=\"token punctuation\">,<\/span> show_progress<span class=\"token operator\">=<\/span>True\r\n    <span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n    # run evaluator\r\n    eval_batch_runner <span class=\"token operator\">=<\/span> <span class=\"token function\">_get_eval_batch_runner_semantic_similarity<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\n    eval_results <span class=\"token operator\">=<\/span> eval_batch_runner<span class=\"token punctuation\">.<\/span><span class=\"token function\">evaluate_responses<\/span><span class=\"token punctuation\">(<\/span>\r\n        eval_qs<span class=\"token punctuation\">,<\/span> respnotallow<span class=\"token operator\">=<\/span>pred_response_objs<span class=\"token punctuation\">,<\/span> reference<span class=\"token operator\">=<\/span>ref_response_strs\r\n    <span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n    # <span class=\"token keyword\">get<\/span> semantic similarity metric\r\n    mean_score <span class=\"token operator\">=<\/span> np<span class=\"token punctuation\">.<\/span><span class=\"token function\">array<\/span><span class=\"token punctuation\">(<\/span>\r\n        <span class=\"token punctuation\">[<\/span>r<span class=\"token punctuation\">.<\/span>score <span class=\"token keyword\">for<\/span> r <span class=\"token keyword\">in<\/span> eval_results<span class=\"token punctuation\">[<\/span><span class=\"token string\">\"semantic_similarity\"<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span>\r\n    <span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">mean<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n    <span class=\"token keyword\">return<\/span> <span class=\"token function\">RunResult<\/span><span class=\"token punctuation\">(<\/span>score<span class=\"token operator\">=<\/span>mean_score<span class=\"token punctuation\">,<\/span> params<span class=\"token operator\">=<\/span>params_dict<span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_1\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<li>16.<\/li>\n<li>17.<\/li>\n<li>18.<\/li>\n<li>19.<\/li>\n<li>20.<\/li>\n<li>21.<\/li>\n<li>22.<\/li>\n<li>23.<\/li>\n<li>24.<\/li>\n<li>25.<\/li>\n<li>26.<\/li>\n<li>27.<\/li>\n<li>28.<\/li>\n<li>29.<\/li>\n<li>30.<\/li>\n<li>31.<\/li>\n<li>32.<\/li>\n<li>33.<\/li>\n<li>34.<\/li>\n<li>35.<\/li>\n<li>36.<\/li>\n<li>37.<\/li>\n<li>38.<\/li>\n<li>39.<\/li>\n<li>40.<\/li>\n<li>41.<\/li>\n<li>42.<\/li>\n<li>43.<\/li>\n<li>44.<\/li>\n<li>45.<\/li>\n<li>46.<\/li>\n<li>47.<\/li>\n<li>48.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__76\">\u66f4\u591a\u7ec6\u8282\u8bf7\u8bbf\u95ee LlamaIndex \u7684\u5173\u4e8e RAG \u7684\u8d85\u53c2\u6570\u4f18\u5316\u7684\u5b8c\u6574\u7b14\u8bb0\uff1a<\/p>\n<p class=\"js_darkmode__77\">https:\/\/docs.llamaindex.ai\/en\/stable\/examples\/param_optimizer\/param_optimizer\/<\/p>\n<p class=\"js_darkmode__80\"><strong>\u91cd\u65b0\u6392\u540d<\/strong><\/p>\n<p class=\"js_darkmode__82\">\u5728\u5c06\u68c0\u7d22\u7ed3\u679c\u53d1\u9001\u7ed9 LLM \u4e4b\u524d\u5bf9\u5b83\u4eec\u8fdb\u884c\u91cd\u65b0\u6392\u540d\u53ef\u4ee5\u5927\u5e45\u63d0\u5347 RAG \u6027\u80fd\u3002<\/p>\n<p class=\"js_darkmode__84\">\u8fd9\u4e2a LlamaIndex \u7b14\u8bb0\uff08https:\/\/docs.llamaindex.ai\/en\/stable\/examples\/node_postprocessor\/CohereRerank.html\u00a0\uff09\u6f14\u793a\u4e86\u4ee5\u4e0b\u4e24\u79cd\u505a\u6cd5\u7684\u5dee\u5f02\uff1a<\/p>\n<ul data-id=\"ua73dd4b-9HnKJd5X\">\n<li data-id=\"ld70c578-HhBJUaGI\">\u4e0d\u4f7f\u7528\u91cd\u65b0\u6392\u540d\u5de5\u5177\uff08reranker\uff09\uff0c\u76f4\u63a5\u68c0\u7d22\u6700\u524d\u9762\u7684 2 \u4e2a\u8282\u70b9\uff0c\u8fdb\u884c\u4e0d\u51c6\u786e\u7684\u68c0\u7d22\u3002<\/li>\n<li data-id=\"ld70c578-C78CCPOT\">\u68c0\u7d22\u6700\u524d\u9762\u7684 10 \u4e2a\u8282\u70b9\u5e76\u4f7f\u7528 CohereRerank \u8fdb\u884c\u91cd\u65b0\u6392\u540d\u5e76\u8fd4\u56de\u6700\u524d\u9762\u7684 2 \u4e2a\u8282\u70b9\uff0c\u8fdb\u884c\u51c6\u786e\u7684\u68c0\u7d22\u3002<\/li>\n<\/ul>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_2\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"><span class=\"token keyword\">import<\/span> os\r\nfrom llama_index<span class=\"token punctuation\">.<\/span>postprocessor<span class=\"token punctuation\">.<\/span>cohere_rerank <span class=\"token keyword\">import<\/span> CohereRerank\r\n\r\n\r\napi_key <span class=\"token operator\">=<\/span> os<span class=\"token punctuation\">.<\/span>environ<span class=\"token punctuation\">[<\/span><span class=\"token string\">\"COHERE_API_KEY\"<\/span><span class=\"token punctuation\">]<\/span>\r\ncohere_rerank <span class=\"token operator\">=<\/span> <span class=\"token function\">CohereRerank<\/span><span class=\"token punctuation\">(<\/span>api_key<span class=\"token operator\">=<\/span>api_key<span class=\"token punctuation\">,<\/span> top_n<span class=\"token operator\">=<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span> # <span class=\"token keyword\">return<\/span> top <span class=\"token number\">2<\/span> nodes from reranker\r\n\r\n\r\nquery_engine <span class=\"token operator\">=<\/span> index<span class=\"token punctuation\">.<\/span><span class=\"token function\">as_query_engine<\/span><span class=\"token punctuation\">(<\/span>\r\n    similarity_top_k<span class=\"token operator\">=<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">,<\/span> # we can <span class=\"token keyword\">set<\/span> a high top_k here to ensure maximum relevant retrieval\r\n    node_postprocessors<span class=\"token operator\">=<\/span><span class=\"token punctuation\">[<\/span>cohere_rerank<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> # pass the reranker to node_postprocessors\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nresponse <span class=\"token operator\">=<\/span> query_engine<span class=\"token punctuation\">.<\/span><span class=\"token function\">query<\/span><span class=\"token punctuation\">(<\/span>\r\n    <span class=\"token string\">\"What did Sam Altman do in this essay?\"<\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_2\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<li>16.<\/li>\n<li>17.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__91\">\u53e6\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5d4c\u5165\u548c\u91cd\u65b0\u6392\u540d\u5de5\u5177\u8bc4\u4f30\u548c\u63d0\u5347\u68c0\u7d22\u5668\u7684\u6027\u80fd\u3002<\/p>\n<p class=\"js_darkmode__93\">\u53c2\u9605\uff1ahttps:\/\/blog.llamaindex.ai\/boosting-rag-picking-the-best-embedding-reranker-models-42d079022e83<\/p>\n<p class=\"js_darkmode__96\">\u6b64\u5916\uff0c\u4e3a\u4e86\u5f97\u5230\u66f4\u597d\u7684\u68c0\u7d22\u6027\u80fd\uff0c\u8fd8\u80fd\u5fae\u8c03\u4e00\u4e2a\u5b9a\u5236\u7248\u7684\u91cd\u65b0\u6392\u540d\u5de5\u5177\uff0c\u5176\u5b9e\u73b0\u7ec6\u8282\u53ef\u8bbf\u95ee\uff1a<\/p>\n<p class=\"js_darkmode__98\">\u535a\u5ba2\u94fe\u63a5\uff1ahttps:\/\/blog.llamaindex.ai\/improving-retrieval-performance-by-fine-tuning-cohere-reranker-with-llamaindex-16c0c1f9b33b<\/p>\n<h4>\u75db\u70b9 3\uff1a\u4e0d\u5728\u4e0a\u4e0b\u6587\u4e2d\u2014\u2014\u5408\u5e76\u7b56\u7565\u7684\u5c40\u9650<\/h4>\n<p class=\"js_darkmode__104\">\u91cd\u65b0\u6392\u540d\u4e4b\u540e\u7f3a\u4e4f\u4e0a\u4e0b\u6587\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u75db\u70b9\uff0c\u4e0a\u8ff0\u8bba\u6587\u7684\u5b9a\u4e49\u4e3a\uff1a\u300c\u5df2\u7ecf\u4ece\u6570\u636e\u5e93\u68c0\u7d22\u5230\u4e86\u5e26\u7b54\u6848\u7684\u6587\u6863\uff0c\u4f46\u8be5\u6587\u6863\u6ca1\u80fd\u6210\u4e3a\u751f\u6210\u7b54\u6848\u7684\u4e0a\u4e0b\u6587\u3002\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u7684\u539f\u56e0\u662f\u6570\u636e\u5e93\u8fd4\u56de\u4e86\u8bb8\u591a\u6587\u6863\uff0c\u4e4b\u540e\u91c7\u7528\u4e86\u4e00\u79cd\u5408\u5e76\u8fc7\u7a0b\u6765\u68c0\u7d22\u7b54\u6848\u3002\u300d<\/p>\n<p class=\"js_darkmode__106\">\u9664\u4e86\u524d\u6587\u63d0\u5230\u7684\u589e\u52a0\u91cd\u65b0\u6392\u540d\u5de5\u5177\u548c\u5fae\u8c03\u91cd\u65b0\u6392\u540d\u5de5\u5177\u4e4b\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u63a2\u7d22\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p class=\"js_darkmode__108\"><strong>\u8c03\u6574\u68c0\u7d22\u7b56\u7565<\/strong><\/p>\n<p class=\"js_darkmode__110\">LlamaIndex \u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u7684\u68c0\u7d22\u7b56\u7565\uff0c\u53ef\u5e2e\u52a9\u7814\u7a76\u8005\u5728 RAG \u5de5\u4f5c\u6d41\u7a0b\u4e2d\u5b9e\u73b0\u51c6\u786e\u7684\u68c0\u7d22\u3002<\/p>\n<p class=\"js_darkmode__112\">\u8fd9\u91cc\u53ef\u4ee5\u770b\u5230\u5df2\u5206\u6210\u4e0d\u540c\u7c7b\u522b\u7684\u68c0\u7d22\u7b56\u7565\u5217\u8868\uff1ahttps:\/\/docs.llamaindex.ai\/en\/stable\/module_guides\/querying\/retriever\/retrievers.html<\/p>\n<ul data-id=\"ua73dd4b-5Xm0PL8L\">\n<li data-id=\"ld70c578-3YLW5cA3\">\u57fa\u4e8e\u6bcf\u4e2a\u7d22\u5f15\u8fdb\u884c\u57fa\u672c\u7684\u68c0\u7d22<\/li>\n<li data-id=\"ld70c578-fsifoTFL\">\u9ad8\u7ea7\u68c0\u7d22\u548c\u641c\u7d22<\/li>\n<li data-id=\"ld70c578-CTYHfc9U\">\u81ea\u52a8\u68c0\u7d22<\/li>\n<li data-id=\"ld70c578-Jb19R881\">\u77e5\u8bc6\u56fe\u8c31\u68c0\u7d22\u5668<\/li>\n<li data-id=\"ld70c578-DMX97Wcu\">\u7ec4\u5408\/\u5206\u5c42\u68c0\u7d22\u5668<\/li>\n<\/ul>\n<p class=\"js_darkmode__121\"><strong>\u5bf9\u5d4c\u5165\u8fdb\u884c\u5fae\u8c03<\/strong><\/p>\n<p class=\"js_darkmode__123\">\u5982\u679c\u4f60\u4f7f\u7528\u5f00\u6e90\u7684\u5d4c\u5165\u6a21\u578b\uff0c\u90a3\u4e48\u4e3a\u4e86\u5b9e\u73b0\u66f4\u51c6\u786e\u7684\u68c0\u7d22\uff0c\u53ef\u4ee5\u5bf9\u5d4c\u5165\u6a21\u578b\u8fdb\u884c\u5fae\u8c03\u3002LlamaIndex \u6709\u4e00\u4e2a\u5fae\u8c03\u5f00\u6e90\u5d4c\u5165\u6a21\u578b\u7684\u9010\u6b65\u6559\u7a0b\uff0c\u5176\u4e2d\u8bc1\u660e\u5fae\u8c03\u5d4c\u5165\u6a21\u578b\u786e\u5b9e\u53ef\u4ee5\u63d0\u5347\u5728\u591a\u4e2a\u8bc4\u4f30\u6307\u6807\u4e0a\u7684\u8868\u73b0\uff1a<\/p>\n<p class=\"js_darkmode__125\">\u6559\u7a0b\u94fe\u63a5\uff1ahttps:\/\/docs.llamaindex.ai\/en\/stable\/examples\/finetuning\/embeddings\/finetune_embedding.html<\/p>\n<p class=\"js_darkmode__129\">\u4e0b\u9762\u662f\u521b\u5efa\u5fae\u8c03\u5f15\u64ce\u3001\u8fd0\u884c\u5fae\u8c03\u3001\u5f97\u5230\u5df2\u5fae\u8c03\u6a21\u578b\u7684\u6837\u672c\u4ee3\u7801\uff1a<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_3\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\">finetune_engine <span class=\"token operator\">=<\/span> <span class=\"token function\">SentenceTransformersFinetuneEngine<\/span><span class=\"token punctuation\">(<\/span>\r\n    train_dataset<span class=\"token punctuation\">,<\/span>\r\n    model_id<span class=\"token operator\">=<\/span><span class=\"token string\">\"BAAI\/bge-small-en\"<\/span><span class=\"token punctuation\">,<\/span>\r\n    model_output_path<span class=\"token operator\">=<\/span><span class=\"token string\">\"test_model\"<\/span><span class=\"token punctuation\">,<\/span>\r\n    val_dataset<span class=\"token operator\">=<\/span>val_dataset<span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nfinetune_engine<span class=\"token punctuation\">.<\/span><span class=\"token function\">finetune<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nembed_model <span class=\"token operator\">=<\/span> finetune_engine<span class=\"token punctuation\">.<\/span><span class=\"token function\">get_finetuned_model<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_3\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h4>\u75db\u70b9 4\uff1a\u672a\u63d0\u53d6\u51fa\u6765<\/h4>\n<p class=\"js_darkmode__134\">\u672a\u6b63\u786e\u63d0\u53d6\u4e0a\u4e0b\u6587\u3002\u7cfb\u7edf\u96be\u4ee5\u4ece\u6240\u63d0\u4f9b\u7684\u4e0a\u4e0b\u6587\u63d0\u53d6\u51fa\u6b63\u786e\u7b54\u6848\uff0c\u5c24\u5176\u662f\u5f53\u4fe1\u606f\u8fc7\u8f7d\u65f6\u3002\u8fd9\u4f1a\u5bfc\u81f4\u5173\u952e\u7ec6\u8282\u7f3a\u5931\uff0c\u635f\u5bb3\u54cd\u5e94\u7684\u8d28\u91cf\u3002\u4e0a\u8ff0\u8bba\u6587\u5199\u9053\uff1a\u300c\u5f53\u4e0a\u4e0b\u6587\u4e2d\u6709\u592a\u591a\u566a\u58f0\u6216\u4e92\u76f8\u77db\u76fe\u7684\u4fe1\u606f\u65f6\uff0c\u5c31\u4f1a\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u3002\u300d<\/p>\n<p class=\"js_darkmode__136\">\u4e0b\u9762\u6765\u770b\u4e09\u79cd\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p class=\"js_darkmode__138\"><strong>\u6e05\u6d01\u6570\u636e<\/strong><\/p>\n<p class=\"js_darkmode__140\">\u8fd9\u4e2a\u75db\u70b9\u7684\u4e00\u4e2a\u5178\u578b\u539f\u56e0\u5c31\u662f\u6570\u636e\u8d28\u91cf\u5dee\u3002\u6e05\u6d01\u6570\u636e\u7684\u91cd\u8981\u6027\u503c\u5f97\u4e00\u518d\u5f3a\u8c03\uff01\u5728\u8d23\u5907\u4f60\u7684 RAG \u6d41\u7a0b\u4e4b\u524d\uff0c\u8bf7\u52a1\u5fc5\u6e05\u6d01\u4f60\u7684\u6570\u636e\u3002<\/p>\n<p class=\"js_darkmode__142\"><strong>prompt \u538b\u7f29<\/strong><\/p>\n<p class=\"js_darkmode__144\">LongLLMLingua \u7814\u7a76\u9879\u76ee\/\u8bba\u6587\u9488\u5bf9\u957f\u4e0a\u4e0b\u6587\u60c5\u51b5\u63d0\u51fa\u4e86 prompt \u538b\u7f29\u3002\u901a\u8fc7\u5c06\u5176\u6574\u5408\u8fdb LlamaIndex\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06 LongLLMLingua \u5b9e\u73b0\u6210\u4e00\u4e2a\u8282\u70b9\u540e\u5904\u7406\u5668\uff0c\u5176\u53ef\u5728\u68c0\u7d22\u6b65\u9aa4\u4e4b\u540e\u5bf9\u4e0a\u4e0b\u6587\u8fdb\u884c\u538b\u7f29\uff0c\u4e4b\u540e\u518d\u5c06\u5176\u4f20\u8f93\u7ed9 LLM\u3002LongLLMLingua \u538b\u7f29\u7684 prompt \u80fd\u4ee5\u8fdc\u8fdc\u66f4\u4f4e\u7684\u6210\u672c\u5f97\u5230\u66f4\u9ad8\u7684\u6027\u80fd\u3002\u6b64\u5916\uff0c\u6574\u4e2a\u7cfb\u7edf\u4f1a\u6709\u66f4\u5feb\u7684\u8fd0\u884c\u901f\u5ea6\u3002<\/p>\n<p class=\"js_darkmode__146\">\u4e0b\u9762\u7684\u4ee3\u7801\u8bbe\u7f6e\u4e86 LongLLMLinguaPostprocessor\uff0c\u5176\u4e2d\u4f7f\u7528\u4e86 longllmlingua \u8f6f\u4ef6\u5305\u6765\u8fd0\u884c prompt \u538b\u7f29\u3002<\/p>\n<p class=\"js_darkmode__148\">\u66f4\u591a\u7ec6\u8282\u8bf7\u8bbf\u95ee\u8fd9\u4e2a\u7b14\u8bb0\uff1a<\/p>\n<p class=\"js_darkmode__149\">https:\/\/docs.llamaindex.ai\/en\/stable\/examples\/node_postprocessor\/LongLLMLingua.html#longllmlingua<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_4\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\">from llama_index<span class=\"token punctuation\">.<\/span>core<span class=\"token punctuation\">.<\/span>query_engine <span class=\"token keyword\">import<\/span> RetrieverQueryEngine\r\nfrom llama_index<span class=\"token punctuation\">.<\/span>core<span class=\"token punctuation\">.<\/span>response_synthesizers <span class=\"token keyword\">import<\/span> CompactAndRefine\r\nfrom llama_index<span class=\"token punctuation\">.<\/span>postprocessor<span class=\"token punctuation\">.<\/span>longllmlingua <span class=\"token keyword\">import<\/span> LongLLMLinguaPostprocessor\r\nfrom llama_index<span class=\"token punctuation\">.<\/span>core <span class=\"token keyword\">import<\/span> QueryBundle\r\n\r\n\r\nnode_postprocessor <span class=\"token operator\">=<\/span> <span class=\"token function\">LongLLMLinguaPostprocessor<\/span><span class=\"token punctuation\">(<\/span>\r\n    instruction_str<span class=\"token operator\">=<\/span><span class=\"token string\">\"Given the context, please answer the final question\"<\/span><span class=\"token punctuation\">,<\/span>\r\n    target_token<span class=\"token operator\">=<\/span><span class=\"token number\">300<\/span><span class=\"token punctuation\">,<\/span>\r\n    rank_method<span class=\"token operator\">=<\/span><span class=\"token string\">\"longllmlingua\"<\/span><span class=\"token punctuation\">,<\/span>\r\n    additional_compress_kwargs<span class=\"token operator\">=<\/span><span class=\"token punctuation\">{<\/span>\r\n        <span class=\"token string-property property\">\"condition_compare\"<\/span><span class=\"token operator\">:<\/span> True<span class=\"token punctuation\">,<\/span>\r\n        <span class=\"token string-property property\">\"condition_in_question\"<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">\"after\"<\/span><span class=\"token punctuation\">,<\/span>\r\n        <span class=\"token string-property property\">\"context_budget\"<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">\"+100\"<\/span><span class=\"token punctuation\">,<\/span>\r\n        <span class=\"token string-property property\">\"reorder_context\"<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">\"sort\"<\/span><span class=\"token punctuation\">,<\/span>  # enable document reorder\r\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nretrieved_nodes <span class=\"token operator\">=<\/span> retriever<span class=\"token punctuation\">.<\/span><span class=\"token function\">retrieve<\/span><span class=\"token punctuation\">(<\/span>query_str<span class=\"token punctuation\">)<\/span>\r\nsynthesizer <span class=\"token operator\">=<\/span> <span class=\"token function\">CompactAndRefine<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# outline steps <span class=\"token keyword\">in<\/span> RetrieverQueryEngine <span class=\"token keyword\">for<\/span> <span class=\"token literal-property property\">clarity<\/span><span class=\"token operator\">:<\/span>\r\n# <span class=\"token function\">postprocess<\/span> <span class=\"token punctuation\">(<\/span>compress<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> synthesize\r\nnew_retrieved_nodes <span class=\"token operator\">=<\/span> node_postprocessor<span class=\"token punctuation\">.<\/span><span class=\"token function\">postprocess_nodes<\/span><span class=\"token punctuation\">(<\/span>\r\n    retrieved_nodes<span class=\"token punctuation\">,<\/span> query_bundle<span class=\"token operator\">=<\/span><span class=\"token function\">QueryBundle<\/span><span class=\"token punctuation\">(<\/span>query_str<span class=\"token operator\">=<\/span>query_str<span class=\"token punctuation\">)<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n<span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"\\n\\n\"<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">join<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">[<\/span>n<span class=\"token punctuation\">.<\/span><span class=\"token function\">get_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">for<\/span> n <span class=\"token keyword\">in<\/span> new_retrieved_nodes<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nresponse <span class=\"token operator\">=<\/span> synthesizer<span class=\"token punctuation\">.<\/span><span class=\"token function\">synthesize<\/span><span class=\"token punctuation\">(<\/span>query_str<span class=\"token punctuation\">,<\/span> new_retrieved_nodes<span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_4\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<li>16.<\/li>\n<li>17.<\/li>\n<li>18.<\/li>\n<li>19.<\/li>\n<li>20.<\/li>\n<li>21.<\/li>\n<li>22.<\/li>\n<li>23.<\/li>\n<li>24.<\/li>\n<li>25.<\/li>\n<li>26.<\/li>\n<li>27.<\/li>\n<li>28.<\/li>\n<li>29.<\/li>\n<li>30.<\/li>\n<li>31.<\/li>\n<li>32.<\/li>\n<li>33.<\/li>\n<li>34.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__153\"><strong>LongContextReorder<\/strong><\/p>\n<p class=\"js_darkmode__155\">\u8bba\u6587\u300aLost in the Middle: How Language Models Use Long Contexts\u300b\u89c2\u5bdf\u5230\uff1a\u5f53\u5173\u952e\u4fe1\u606f\u4f4d\u4e8e\u8f93\u5165\u4e0a\u4e0b\u6587\u7684\u5f00\u5934\u6216\u672b\u5c3e\u65f6\uff0c\u901a\u5e38\u80fd\u83b7\u5f97\u6700\u4f73\u6027\u80fd\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u79cd\u300c\u4e2d\u90e8\u4e22\u5931\u300d\u95ee\u9898\uff0c\u7814\u7a76\u8005\u8bbe\u8ba1\u4e86 LongContextReorder\uff0c\u5176\u505a\u6cd5\u662f\u91cd\u65b0\u8c03\u6574\u88ab\u68c0\u7d22\u8282\u70b9\u7684\u987a\u5e8f\uff0c\u8fd9\u5bf9\u9700\u8981\u8f83\u5927 top-k \u7684\u60c5\u51b5\u5f88\u6709\u7528\u3002<\/p>\n<p class=\"js_darkmode__157\">\u4e0b\u9762\u7684\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u5728\u67e5\u8be2\u5f15\u64ce\u6784\u5efa\u671f\u95f4\u5c06 LongContextReorder \u5b9a\u4e49\u6210\u4f60\u7684\u8282\u70b9\u540e\u5904\u7406\u5668\u3002\u66f4\u591a\u7ec6\u8282\uff0c\u8bf7\u53c2\u770b\u8fd9\u4efd\u7b14\u8bb0\uff1a<\/p>\n<p class=\"js_darkmode__158\">https:\/\/docs.llamaindex.ai\/en\/stable\/examples\/node_postprocessor\/LongContextReorder.html<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_5\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\">from llama_index<span class=\"token punctuation\">.<\/span>core<span class=\"token punctuation\">.<\/span>postprocessor <span class=\"token keyword\">import<\/span> LongContextReorder\r\n\r\n\r\nreorder <span class=\"token operator\">=<\/span> <span class=\"token function\">LongContextReorder<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nreorder_engine <span class=\"token operator\">=<\/span> index<span class=\"token punctuation\">.<\/span><span class=\"token function\">as_query_engine<\/span><span class=\"token punctuation\">(<\/span>\r\n    node_postprocessors<span class=\"token operator\">=<\/span><span class=\"token punctuation\">[<\/span>reorder<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> similarity_top_k<span class=\"token operator\">=<\/span><span class=\"token number\">5<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nreorder_response <span class=\"token operator\">=<\/span> reorder_engine<span class=\"token punctuation\">.<\/span><span class=\"token function\">query<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"Did the author meet Sam Altman?\"<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_5\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h4>\u75db\u70b9 5\uff1a\u683c\u5f0f\u9519\u8bef<\/h4>\n<p class=\"js_darkmode__164\">\u8f93\u51fa\u7684\u683c\u5f0f\u6709\u8bef\u3002\u5f53 LLM \u5ffd\u89c6\u4e86\u63d0\u53d6\u7279\u5b9a\u683c\u5f0f\u7684\u4fe1\u606f\uff08\u5982\u8868\u683c\u6216\u5217\u8868\uff09\u7684\u6307\u4ee4\u65f6\uff0c\u5c31\u4f1a\u51fa\u73b0\u8fd9\u4e2a\u95ee\u9898\uff0c\u5bf9\u6b64\u7684\u89e3\u51b3\u65b9\u6848\u6709\u56db\u4e2a\uff1a<\/p>\n<p class=\"js_darkmode__166\"><strong>\u66f4\u597d\u7684\u63d0\u8bcd\u8bbe\u8ba1<\/strong><\/p>\n<p class=\"js_darkmode__168\">\u9488\u5bf9\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4f7f\u7528\u591a\u79cd\u7b56\u7565\u6765\u63d0\u5347 prompt\uff1a<\/p>\n<ul data-id=\"ua73dd4b-8QOFY01d\">\n<li data-id=\"ld70c578-YkrE7lmi\">\u6e05\u6670\u5730\u8bf4\u660e\u6307\u4ee4<\/li>\n<li data-id=\"ld70c578-EPANtp91\">\u7b80\u5316\u8bf7\u6c42\u5e76\u4f7f\u7528\u5173\u952e\u8bcd<\/li>\n<li data-id=\"ld70c578-ZlxIXH41\">\u7ed9\u51fa\u793a\u4f8b<\/li>\n<li data-id=\"ld70c578-f7YY0Mq6\">\u4f7f\u7528\u8fed\u4ee3\u5f0f\u7684 prompt \u5e76\u8be2\u95ee\u540e\u7eed\u95ee\u9898<\/li>\n<\/ul>\n<p class=\"js_darkmode__175\"><strong>\u8f93\u51fa\u89e3\u6790<\/strong><\/p>\n<p class=\"js_darkmode__177\">\u4e3a\u4e86\u786e\u4fdd\u5f97\u5230\u6240\u9700\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u5f0f\u8f93\u51fa\u89e3\u6790\uff1a<\/p>\n<ul data-id=\"ua73dd4b-GeOqe1aq\">\n<li data-id=\"ld70c578-B72UFNce\">\u4e3a\u4efb\u610f prompt\/\u67e5\u8be2\u63d0\u4f9b\u683c\u5f0f\u8bf4\u660e<\/li>\n<li data-id=\"ld70c578-NgeiicKx\">\u4e3a LLM \u8f93\u51fa\u63d0\u4f9b\u300c\u89e3\u6790\u300d<\/li>\n<\/ul>\n<p class=\"js_darkmode__182\">LlamaIndex \u652f\u6301\u6574\u5408 Guardrails \u548c LangChain \u7b49\u5176\u5b83\u6846\u67b6\u63d0\u4f9b\u7684\u8f93\u51fa\u89e3\u6790\u6a21\u5757\u3002<\/p>\n<p class=\"js_darkmode__184\">\u4e0b\u9762\u662f\u53ef\u5728 LlamaIndex \u4e2d\u4f7f\u7528\u7684 LangChain \u7684\u8f93\u51fa\u89e3\u6790\u6a21\u5757\u7684\u4ee3\u7801\u3002\u66f4\u591a\u7ec6\u8282\u8bf7\u8bbf\u95ee\u8fd9\u4efd\u6709\u5173\u8f93\u51fa\u89e3\u6790\u6a21\u5757\u7684\u6587\u6863\uff1a<\/p>\n<p class=\"js_darkmode__185\">https:\/\/docs.llamaindex.ai\/en\/stable\/module_guides\/querying\/structured_outputs\/output_parser.html<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_6\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\">from llama_index<span class=\"token punctuation\">.<\/span>core <span class=\"token keyword\">import<\/span> VectorStoreIndex<span class=\"token punctuation\">,<\/span> SimpleDirectoryReader\r\nfrom llama_index<span class=\"token punctuation\">.<\/span>core<span class=\"token punctuation\">.<\/span>output_parsers <span class=\"token keyword\">import<\/span> LangchainOutputParser\r\nfrom llama_index<span class=\"token punctuation\">.<\/span>llms<span class=\"token punctuation\">.<\/span>openai <span class=\"token keyword\">import<\/span> OpenAI\r\nfrom langchain<span class=\"token punctuation\">.<\/span>output_parsers <span class=\"token keyword\">import<\/span> StructuredOutputParser<span class=\"token punctuation\">,<\/span> ResponseSchema\r\n\r\n\r\n# load documents<span class=\"token punctuation\">,<\/span> build index\r\ndocuments <span class=\"token operator\">=<\/span> <span class=\"token function\">SimpleDirectoryReader<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"..\/paul_graham_essay\/data\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">load_data<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\nindex <span class=\"token operator\">=<\/span> VectorStoreIndex<span class=\"token punctuation\">.<\/span><span class=\"token function\">from_documents<\/span><span class=\"token punctuation\">(<\/span>documents<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# define output schema\r\nresponse_schemas <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">[<\/span>\r\n    <span class=\"token function\">ResponseSchema<\/span><span class=\"token punctuation\">(<\/span>\r\n        name<span class=\"token operator\">=<\/span><span class=\"token string\">\"Education\"<\/span><span class=\"token punctuation\">,<\/span>\r\n        descriptinotallow<span class=\"token operator\">=<\/span><span class=\"token string\">\"Describes the author's educational experience\/background.\"<\/span><span class=\"token punctuation\">,<\/span>\r\n    <span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>\r\n    <span class=\"token function\">ResponseSchema<\/span><span class=\"token punctuation\">(<\/span>\r\n        name<span class=\"token operator\">=<\/span><span class=\"token string\">\"Work\"<\/span><span class=\"token punctuation\">,<\/span>\r\n        descriptinotallow<span class=\"token operator\">=<\/span><span class=\"token string\">\"Describes the author's work experience\/background.\"<\/span><span class=\"token punctuation\">,<\/span>\r\n    <span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">]<\/span>\r\n\r\n\r\n# define output parser\r\nlc_output_parser <span class=\"token operator\">=<\/span> StructuredOutputParser<span class=\"token punctuation\">.<\/span><span class=\"token function\">from_response_schemas<\/span><span class=\"token punctuation\">(<\/span>\r\n    response_schemas\r\n<span class=\"token punctuation\">)<\/span>\r\noutput_parser <span class=\"token operator\">=<\/span> <span class=\"token function\">LangchainOutputParser<\/span><span class=\"token punctuation\">(<\/span>lc_output_parser<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# Attach output parser to <span class=\"token constant\">LLM<\/span>\r\nllm <span class=\"token operator\">=<\/span> <span class=\"token function\">OpenAI<\/span><span class=\"token punctuation\">(<\/span>output_parser<span class=\"token operator\">=<\/span>output_parser<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# obtain a structured response\r\nquery_engine <span class=\"token operator\">=<\/span> index<span class=\"token punctuation\">.<\/span><span class=\"token function\">as_query_engine<\/span><span class=\"token punctuation\">(<\/span>llm<span class=\"token operator\">=<\/span>llm<span class=\"token punctuation\">)<\/span>\r\nresponse <span class=\"token operator\">=<\/span> query_engine<span class=\"token punctuation\">.<\/span><span class=\"token function\">query<\/span><span class=\"token punctuation\">(<\/span>\r\n    <span class=\"token string\">\"What are a few things the author did growing up?\"<\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n<span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">str<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_6\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<li>16.<\/li>\n<li>17.<\/li>\n<li>18.<\/li>\n<li>19.<\/li>\n<li>20.<\/li>\n<li>21.<\/li>\n<li>22.<\/li>\n<li>23.<\/li>\n<li>24.<\/li>\n<li>25.<\/li>\n<li>26.<\/li>\n<li>27.<\/li>\n<li>28.<\/li>\n<li>29.<\/li>\n<li>30.<\/li>\n<li>31.<\/li>\n<li>32.<\/li>\n<li>33.<\/li>\n<li>34.<\/li>\n<li>35.<\/li>\n<li>36.<\/li>\n<li>37.<\/li>\n<li>38.<\/li>\n<li>39.<\/li>\n<li>40.<\/li>\n<li>41.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__189\"><strong>Pydantic \u7a0b\u5e8f<\/strong><\/p>\n<p class=\"js_darkmode__191\">Pydantic \u7a0b\u5e8f\u662f\u4e00\u4e2a\u591a\u529f\u80fd\u6846\u67b6\uff0c\u53ef\u5c06\u8f93\u5165\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u7ed3\u6784\u5316\u7684 Pydantic \u5bf9\u8c61\u3002LlamaIndex \u63d0\u4f9b\u51e0\u7c7b Pydantic \u7a0b\u5e8f\uff1a<\/p>\n<ul data-id=\"ua73dd4b-4Di6RZ98\">\n<li data-id=\"ld70c578-4OgJoWSJ\">LLM \u6587\u672c\u8865\u5168 Pydantic \u7a0b\u5e8f\uff1a\u8fd9\u4e9b\u7a0b\u5e8f\u4f7f\u7528\u6587\u672c\u8865\u5168 API \u52a0\u4e0a\u8f93\u51fa\u89e3\u6790\uff0c\u53ef\u5c06\u8f93\u5165\u6587\u672c\u8f6c\u6362\u6210\u7528\u6237\u5b9a\u4e49\u7684\u7ed3\u6784\u5316\u5bf9\u8c61\u3002<\/li>\n<li data-id=\"ld70c578-Gfq7Tn4j\">LLM \u51fd\u6570\u8c03\u7528 Pydantic \u7a0b\u5e8f\uff1a\u901a\u8fc7\u5229\u7528 LLM \u51fd\u6570\u8c03\u7528 API\uff0c\u8fd9\u4e9b\u7a0b\u5e8f\u53ef\u5c06\u8f93\u5165\u6587\u672c\u8f6c\u6362\u6210\u7528\u6237\u6307\u5b9a\u7684\u7ed3\u6784\u5316\u5bf9\u8c61\u3002<\/li>\n<li data-id=\"ld70c578-4fRf4FeF\">\u9884\u5c01\u88c5 Pydantic \u7a0b\u5e8f\uff1a\u5176\u8bbe\u8ba1\u76ee\u6807\u662f\u5c06\u8f93\u5165\u6587\u672c\u8f6c\u6362\u6210\u9884\u5b9a\u4e49\u7684\u7ed3\u6784\u5316\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<p class=\"js_darkmode__197\">\u4e0b\u9762\u662f\u6765\u81ea OpenAI pydantic \u7a0b\u5e8f\u7684\u4ee3\u7801\u3002LlamaIndex \u7684\u6587\u6863\u7ed9\u51fa\u4e86\u66f4\u591a\u76f8\u5173\u7ec6\u8282\uff0c\u5e76\u4e14\u5176\u4e2d\u8fd8\u5305\u542b\u4e0d\u540c Pydantic \u7a0b\u5e8f\u7684\u7b14\u8bb0\u672c\/\u6307\u5357\u7684\u94fe\u63a5\uff1a<\/p>\n<p class=\"js_darkmode__198\">https:\/\/docs.llamaindex.ai\/en\/stable\/module_guides\/querying\/structured_outputs\/pydantic_program.html<\/p>\n<p class=\"js_darkmode__201\"><strong>OpenAI JSON \u6a21\u5f0f<\/strong><\/p>\n<p class=\"js_darkmode__203\">OpenAI JSON \u6a21\u5f0f\u53ef\u8ba9\u6211\u4eec\u901a\u8fc7\u5c06 response_format \u8bbe\u7f6e\u6210 { &#8220;type&#8221;: &#8220;json_object&#8221; } \u6765\u542f\u7528 JSON \u6a21\u5f0f\u7684\u54cd\u5e94\u3002\u5f53\u542f\u7528\u4e86 JSON \u6a21\u5f0f\u65f6\uff0c\u6a21\u578b\u5c31\u53ea\u4f1a\u751f\u6210\u80fd\u89e3\u6790\u6210\u6709\u6548 JSON \u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u3002\u867d\u7136 JSON \u6a21\u5f0f\u4f1a\u5f3a\u5236\u8bbe\u5b9a\u8f93\u51fa\u683c\u5f0f\uff0c\u4f46\u5b83\u65e0\u52a9\u4e8e\u9488\u5bf9\u6307\u5b9a\u67b6\u6784\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n<p class=\"js_darkmode__205\">\u66f4\u591a\u7ec6\u8282\u8bf7\u8bbf\u95ee\u8fd9\u4e2a\u6587\u6863\uff1ahttps:\/\/docs.llamaindex.ai\/en\/stable\/examples\/llm\/openai_json_vs_function_calling.html<\/p>\n<h4>\u75db\u70b9 6\uff1a\u4e0d\u6b63\u786e\u7684\u5177\u4f53\u8bf4\u660e<\/h4>\n<p class=\"js_darkmode__210\">\u8f93\u51fa\u5177\u4f53\u8bf4\u660e\u7684\u5c42\u7ea7\u4e0d\u5bf9\u3002\u54cd\u5e94\u53ef\u80fd\u7f3a\u4e4f\u5fc5\u8981\u7ec6\u8282\u6216\u5177\u4f53\u8bf4\u660e\uff0c\u8fd9\u5f80\u5f80\u9700\u8981\u540e\u7eed\u7684\u95ee\u9898\u6765\u8fdb\u884c\u6f84\u6e05\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u7b54\u6848\u53ef\u80fd\u592a\u8fc7\u6a21\u7cca\u6216\u7b3c\u7edf\uff0c\u65e0\u6cd5\u6709\u6548\u6ee1\u8db3\u7528\u6237\u7684\u9700\u6c42\u3002<\/p>\n<p class=\"js_darkmode__212\">\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528\u9ad8\u7ea7\u68c0\u7d22\u7b56\u7565\u3002<\/p>\n<p class=\"js_darkmode__214\"><strong>\u9ad8\u7ea7\u68c0\u7d22\u7b56\u7565<\/strong><\/p>\n<p class=\"js_darkmode__216\">\u5f53\u7b54\u6848\u7684\u7c92\u5ea6\u4e0d\u7b26\u5408\u671f\u671b\u65f6\uff0c\u53ef\u4ee5\u6539\u8fdb\u68c0\u7d22\u7b56\u7565\u3002\u53ef\u80fd\u89e3\u51b3\u8fd9\u4e2a\u75db\u70b9\u7684\u9ad8\u7ea7\u68c0\u7d22\u7b56\u7565\u5305\u62ec\uff1a<\/p>\n<ul data-id=\"ua73dd4b-sBULRYdn\">\n<li data-id=\"ld70c578-TMChUQBV\">\u4ece\u5c0f\u5230\u5927\u68c0\u7d22<\/li>\n<li data-id=\"ld70c578-Wpi3aCBL\">\u53e5\u5b50\u7a97\u53e3\u68c0\u7d22<\/li>\n<li data-id=\"ld70c578-XagBKPRJ\">\u9012\u5f52\u68c0\u7d22<\/li>\n<\/ul>\n<p class=\"js_darkmode__222\">\u6709\u5173\u9ad8\u7ea7\u68c0\u7d22\u7684\u66f4\u591a\u8be6\u60c5\u53ef\u8bbf\u95ee\uff1ahttps:\/\/towardsdatascience.com\/jump-start-your-rag-pipelines-with-advanced-retrieval-llamapacks-and-benchmark-with-lighthouz-ai-80a09b7c7d9d<\/p>\n<h4>\u75db\u70b9 7\uff1a\u4e0d\u5b8c\u5907<\/h4>\n<p class=\"js_darkmode__227\">\u8f93\u51fa\u4e0d\u5b8c\u5907\u3002\u7ed9\u51fa\u7684\u54cd\u5e94\u6ca1\u6709\u9519\uff0c\u4f46\u53ea\u662f\u4e00\u90e8\u5206\uff0c\u672a\u80fd\u63d0\u4f9b\u5168\u90e8\u7ec6\u8282\uff0c\u5373\u4fbf\u8fd9\u4e9b\u4fe1\u606f\u5b58\u5728\u4e8e\u53ef\u8bbf\u95ee\u7684\u4e0a\u4e0b\u6587\u4e2d\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u67d0\u4eba\u95ee\u300c\u6587\u6863 A\u3001B\u3001C \u4e3b\u8981\u8ba8\u8bba\u4e86\u54ea\u4e9b\u65b9\u9762\uff1f\u300d\u4e3a\u4e86\u5f97\u5230\u5168\u9762\u7684\u7b54\u6848\uff0c\u66f4\u6709\u6548\u7684\u505a\u6cd5\u53ef\u80fd\u662f\u5355\u72ec\u8be2\u95ee\u5404\u4e2a\u6587\u6863\u3002<\/p>\n<p class=\"js_darkmode__229\"><strong>\u67e5\u8be2\u53d8\u6362<\/strong><\/p>\n<p class=\"js_darkmode__231\">\u539f\u751f\u7248\u7684 RAG \u65b9\u6cd5\u901a\u5e38\u5f88\u96be\u5904\u7406\u6bd4\u8f83\u95ee\u9898\u3002\u4e3a\u4e86\u63d0\u5347 RAG \u7684\u63a8\u7406\u80fd\u529b\uff0c\u4e00\u79cd\u5f88\u597d\u7684\u65b9\u6cd5\u662f\u6dfb\u52a0\u4e00\u4e2a\u67e5\u8be2\u7406\u89e3\u5c42\u2014\u2014\u5728\u5b9e\u9645\u67e5\u8be2\u50a8\u5b58\u7684\u5411\u91cf\u524d\u589e\u52a0\u67e5\u8be2\u53d8\u6362\u3002\u67e5\u8be2\u53d8\u6362\u6709\u56db\u79cd\uff1a<\/p>\n<ul data-id=\"ua73dd4b-lqRchIpi\">\n<li data-id=\"ld70c578-YtBZnDJX\">\u8def\u7531\uff1a\u4fdd\u7559\u521d\u59cb\u67e5\u8be2\uff0c\u540c\u65f6\u786e\u5b9a\u5176\u76f8\u5173\u7684\u9002\u5f53\u5de5\u5177\u5b50\u96c6\u3002\u7136\u540e\uff0c\u5c06\u8fd9\u4e9b\u5de5\u5177\u6307\u5b9a\u4e3a\u5408\u9002\u7684\u9009\u9879\u3002<\/li>\n<li data-id=\"ld70c578-PQv7ldlC\">\u67e5\u8be2\u91cd\u5199\uff1a\u7ef4\u6301\u6240\u9009\u5de5\u5177\uff0c\u4f46\u4ee5\u591a\u79cd\u65b9\u5f0f\u91cd\u5199\u67e5\u8be2\uff0c\u518d\u5c06\u5176\u5e94\u7528\u4e8e\u540c\u4e00\u5de5\u5177\u96c6\u3002<\/li>\n<li data-id=\"ld70c578-Z3w4sRGb\">\u5b50\u95ee\u9898\uff1a\u5c06\u67e5\u8be2\u5206\u89e3\u6210\u51e0\u4e2a\u8f83\u5c0f\u7684\u95ee\u9898\uff0c\u6bcf\u4e00\u4e2a\u5c0f\u95ee\u9898\u7684\u76ee\u6807\u90fd\u662f\u4e0d\u540c\u7684\u5de5\u5177\uff0c\u8fd9\u7531\u5b83\u4eec\u7684\u5143\u6570\u636e\u51b3\u5b9a\u3002<\/li>\n<li data-id=\"ld70c578-e2ddwKdL\">ReAct \u667a\u80fd\u4f53\u5de5\u5177\u9009\u62e9\uff1a\u57fa\u4e8e\u539f\u59cb\u67e5\u8be2\uff0c\u51b3\u5b9a\u4f7f\u7528\u54ea\u4e2a\u5de5\u5177\u5e76\u6784\u5efa\u5177\u4f53\u7684\u67e5\u8be2\u6765\u57fa\u4e8e\u8be5\u5de5\u5177\u8fd0\u884c\u3002<\/li>\n<\/ul>\n<p class=\"js_darkmode__238\">\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 HyDE\uff08Hypothetical Document Embeddings\uff09\u8fd9\u79cd\u67e5\u8be2\u91cd\u5199\u6280\u672f\u3002\u7ed9\u5b9a\u4e00\u4e2a\u81ea\u7136\u8bed\u8a00\u67e5\u8be2\uff0c\u9996\u5148\u751f\u6210\u4e00\u4efd\u5047\u8bbe\u6587\u6863\/\u7b54\u6848\u3002\u7136\u540e\u4f7f\u7528\u8be5\u5047\u8bbe\u6587\u6863\u6765\u67e5\u627e\u5d4c\u5165\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u539f\u59cb\u67e5\u8be2\u3002<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_7\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"># load documents<span class=\"token punctuation\">,<\/span> build index\r\ndocuments <span class=\"token operator\">=<\/span> <span class=\"token function\">SimpleDirectoryReader<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"..\/paul_graham_essay\/data\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">load_data<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\nindex <span class=\"token operator\">=<\/span> <span class=\"token function\">VectorStoreIndex<\/span><span class=\"token punctuation\">(<\/span>documents<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# run query <span class=\"token keyword\">with<\/span> HyDE query transform\r\nquery_str <span class=\"token operator\">=<\/span> <span class=\"token string\">\"what did paul graham do after going to RISD\"<\/span>\r\nhyde <span class=\"token operator\">=<\/span> <span class=\"token function\">HyDEQueryTransform<\/span><span class=\"token punctuation\">(<\/span>include_original<span class=\"token operator\">=<\/span>True<span class=\"token punctuation\">)<\/span>\r\nquery_engine <span class=\"token operator\">=<\/span> index<span class=\"token punctuation\">.<\/span><span class=\"token function\">as_query_engine<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\nquery_engine <span class=\"token operator\">=<\/span> <span class=\"token function\">TransformQueryEngine<\/span><span class=\"token punctuation\">(<\/span>query_engine<span class=\"token punctuation\">,<\/span> query_transform<span class=\"token operator\">=<\/span>hyde<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nresponse <span class=\"token operator\">=<\/span> query_engine<span class=\"token punctuation\">.<\/span><span class=\"token function\">query<\/span><span class=\"token punctuation\">(<\/span>query_str<span class=\"token punctuation\">)<\/span>\r\n<span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_7\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__241\">\u8be6\u60c5\u53c2\u9605 LlamaIndex \u7684\u67e5\u8be2\u53d8\u6362\u624b\u518c\uff1ahttps:\/\/docs.llamaindex.ai\/en\/stable\/examples\/query_transformations\/query_transform_cookbook.html<\/p>\n<p class=\"js_darkmode__244\">\u53e6\u5916\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e5f\u503c\u5f97\u4e00\u8bfb\uff1ahttps:\/\/towardsdatascience.com\/advanced-query-transformations-to-improve-rag-11adca9b19d1<\/p>\n<p class=\"js_darkmode__247\">\u4e0a\u9762 7 \u4e2a\u75db\u70b9\u90fd\u6765\u81ea\u4e0a\u8ff0\u8bba\u6587\u3002\u4e0b\u9762\u8fd8\u6709\u53e6\u5916 5 \u4e2a RAG \u5f00\u53d1\u8fc7\u7a0b\u4e2d\u5e38\u89c1\u7684\u75db\u70b9\u4ee5\u53ca\u76f8\u5e94\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<h4>\u75db\u70b9 8\uff1a\u6570\u636e\u6444\u53d6\u7684\u53ef\u6269\u5c55\u6027<\/h4>\n<p class=\"js_darkmode__251\">\u6570\u636e\u6444\u53d6\u6d41\u7a0b\u65e0\u6cd5\u6269\u5c55\u5230\u66f4\u5927\u7684\u6570\u636e\u91cf\u3002\u5728 RAG \u5de5\u4f5c\u6d41\u7a0b\u4e2d\uff0c\u6570\u636e\u6444\u53d6\u53ef\u6269\u5c55\u6027\u662f\u6307\u7cfb\u7edf\u96be\u4ee5\u9ad8\u6548\u7ba1\u7406\u548c\u5904\u7406\u5927\u6570\u636e\u91cf\u7684\u96be\u9898\uff0c\u8fd9\u53ef\u80fd\u5bfc\u81f4\u51fa\u73b0\u6027\u80fd\u74f6\u9888\u4ee5\u53ca\u7cfb\u7edf\u6545\u969c\u3002\u8fd9\u6837\u7684\u6570\u636e\u6444\u53d6\u53ef\u6269\u5c55\u6027\u95ee\u9898\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6444\u53d6\u65f6\u95f4\u5ef6\u957f\u3001\u7cfb\u7edf\u8fc7\u8f7d\u3001\u6570\u636e\u8d28\u91cf\u95ee\u9898\u548c\u53ef\u7528\u6027\u53d7\u9650\u3002<\/p>\n<p class=\"js_darkmode__253\"><strong>\u5e76\u884c\u5316\u6444\u53d6\u5de5\u4f5c\u6d41\u7a0b<\/strong><\/p>\n<p class=\"js_darkmode__255\">LlamaIndex \u63d0\u4f9b\u4e86\u6444\u53d6\u5de5\u4f5c\u6d41\u7a0b\u5e76\u884c\u5904\u7406\uff0c\u8fd9\u4e2a\u529f\u80fd\u53ef\u8ba9 LlamaIndex \u7684\u6587\u6863\u5904\u7406\u901f\u5ea6\u63d0\u5347 15 \u500d\u3002\u4ee5\u4e0b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u521b\u5efa IngestionPipeline \u5e76\u6307\u5b9a num_workers \u6765\u8c03\u7528\u5e76\u884c\u5904\u7406\u3002<\/p>\n<p class=\"js_darkmode__257\">\u66f4\u591a\u8be6\u60c5\u8bf7\u8bbf\u95ee\u8fd9\u4e2a LlamaIndex \u7b14\u8bb0\u672c\uff1ahttps:\/\/github.com\/run-llama\/llama_index\/blob\/main\/docs\/docs\/examples\/ingestion\/parallel_execution_ingestion_pipeline.ipynb<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_8\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"># load data\r\ndocuments <span class=\"token operator\">=<\/span> <span class=\"token function\">SimpleDirectoryReader<\/span><span class=\"token punctuation\">(<\/span>input_dir<span class=\"token operator\">=<\/span><span class=\"token string\">\".\/data\/source_files\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">load_data<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# create the pipeline <span class=\"token keyword\">with<\/span> transformations\r\npipeline <span class=\"token operator\">=<\/span> <span class=\"token function\">IngestionPipeline<\/span><span class=\"token punctuation\">(<\/span>\r\n    transformatinotallow<span class=\"token operator\">=<\/span><span class=\"token punctuation\">[<\/span>\r\n        <span class=\"token function\">SentenceSplitter<\/span><span class=\"token punctuation\">(<\/span>chunk_size<span class=\"token operator\">=<\/span><span class=\"token number\">1024<\/span><span class=\"token punctuation\">,<\/span> chunk_overlap<span class=\"token operator\">=<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>\r\n        <span class=\"token function\">TitleExtractor<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>\r\n        <span class=\"token function\">OpenAIEmbedding<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>\r\n    <span class=\"token punctuation\">]<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# setting num_workers to a value greater than <span class=\"token number\">1<\/span> invokes parallel execution<span class=\"token punctuation\">.<\/span>\r\nnodes <span class=\"token operator\">=<\/span> pipeline<span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span>documents<span class=\"token operator\">=<\/span>documents<span class=\"token punctuation\">,<\/span> num_workers<span class=\"token operator\">=<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_8\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<li>16.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h4>\u75db\u70b9 9\uff1a\u7ed3\u6784\u5316\u6570\u636e\u95ee\u7b54<\/h4>\n<p class=\"js_darkmode__263\">\u6ca1\u6709\u5bf9\u7ed3\u6784\u5316\u6570\u636e\u8fdb\u884c\u95ee\u7b54\u7684\u80fd\u529b\u3002\u51c6\u786e\u89e3\u8bfb\u68c0\u7d22\u76f8\u5173\u7ed3\u6784\u5316\u6570\u636e\u7684\u7528\u6237\u67e5\u8be2\u53ef\u80fd\u5f88\u56f0\u96be\uff0c\u5c24\u5176\u662f\u5f53\u67e5\u8be2\u672c\u8eab\u5f88\u590d\u6742\u6216\u6709\u6b67\u4e49\u65f6\uff0c\u52a0\u4e0a\u6587\u672c\u5230 SQL \u4e0d\u7075\u6d3b\uff0c\u5f53\u524d LLM \u5728\u6709\u6548\u5904\u7406\u8fd9\u4e9b\u4efb\u52a1\u4e0a\u5b58\u5728\u5c40\u9650\u3002<\/p>\n<p class=\"js_darkmode__265\">LlamaIndex \u63d0\u4f9b\u4e86 2 \u4e2a\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p class=\"js_darkmode__267\"><strong>Chain-of-table \u8f6f\u4ef6\u5305<\/strong><\/p>\n<p class=\"js_darkmode__269\">ChainOfTablePack \u662f\u57fa\u4e8e Wang et al. \u7684\u521b\u65b0\u8bba\u6587\u300aChain-of-Table: Evolving Tables in the Reasoning Chain for Table Understanding\u300b\u6784\u5efa\u7684 LlamaPack\u3002\u5176\u6574\u5408\u4e86\u601d\u7ef4\u94fe\u7684\u6982\u5ff5\u4e0e\u8868\u683c\u53d8\u6362\u548c\u8868\u5f81\u3002\u5176\u53ef\u4f7f\u7528\u4e00\u4e2a\u6709\u9650\u7684\u64cd\u4f5c\u96c6\u5408\u6765\u4e00\u6b65\u6b65\u5730\u5bf9\u8868\u683c\u6267\u884c\u53d8\u6362\uff0c\u5e76\u5728\u6bcf\u4e00\u6b65\u4e3a LLM \u63d0\u4f9b\u4fee\u6539\u540e\u7684\u8868\u683c\u3002\u8fd9\u79cd\u65b9\u6cd5\u6709\u4e00\u4e2a\u91cd\u5927\u4f18\u52bf\uff0c\u5373\u5176\u6709\u80fd\u529b\u89e3\u51b3\u6d89\u53ca\u5305\u542b\u591a\u6761\u4fe1\u606f\u7684\u590d\u6742\u5355\u5143\u683c\u7684\u95ee\u9898\uff0c\u5176\u505a\u6cd5\u662f\u7cfb\u7edf\u6027\u5730\u5207\u5206\u6570\u636e\uff0c\u76f4\u5230\u627e\u5230\u5408\u9002\u7684\u5b50\u96c6\uff0c\u4ece\u800c\u63d0\u9ad8\u8868\u683c\u95ee\u7b54\u7684\u6709\u6548\u6027\u3002<\/p>\n<p class=\"js_darkmode__271\">\u66f4\u591a\u7ec6\u8282\u4ee5\u53ca\u4f7f\u7528 ChainOfTablePack \u7684\u65b9\u6cd5\u90fd\u53ef\u8bbf\u95ee\uff1ahttps:\/\/github.com\/run-llama\/llama-hub\/blob\/main\/llama_hub\/llama_packs\/tables\/chain_of_table\/chain_of_table.ipynb<\/p>\n<p class=\"js_darkmode__274\"><strong>Mix-Self-Consistency \u8f6f\u4ef6\u5305<\/strong><\/p>\n<p class=\"js_darkmode__276\">LLM \u63a8\u7406\u8868\u683c\u6570\u636e\u7684\u65b9\u5f0f\u6709\u4e24\u79cd\uff1a<\/p>\n<ul data-id=\"ua73dd4b-pR5OJJA8\">\n<li data-id=\"ld70c578-IKi8qSIR\">\u901a\u8fc7\u76f4\u63a5 prompt \u6765\u5b9e\u73b0\u6587\u672c\u63a8\u7406<\/li>\n<li data-id=\"ld70c578-lVVmM04v\">\u901a\u8fc7\u7a0b\u5e8f\u5408\u6210\u5b9e\u73b0\u7b26\u53f7\u63a8\u7406\uff08\u6bd4\u5982 Python\u3001SQL \u7b49\uff09<\/li>\n<\/ul>\n<p class=\"js_darkmode__281\">\u57fa\u4e8e Liu et al. \u7684\u8bba\u6587\u300aRethinking Tabular Data Understanding with Large Language Models\u300b\uff0cLlamaIndex \u5f00\u53d1\u4e86 MixSelfConsistencyQueryEngine\uff0c\u5176\u901a\u8fc7\u4e00\u79cd\u81ea\u6211\u4e00\u81f4\u6027\u673a\u5236\uff08\u5373\u591a\u6570\u6295\u7968\uff09\u5c06\u6587\u672c\u548c\u7b26\u53f7\u63a8\u7406\u7684\u7ed3\u679c\u805a\u5408\u5230\u4e86\u4e00\u8d77\u5e76\u53d6\u5f97\u4e86\u5f53\u524d\u6700\u4f73\u8868\u73b0\u3002\u4e0b\u9762\u7ed9\u51fa\u4e86\u4e00\u6bb5\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p class=\"js_darkmode__283\">\u66f4\u591a\u8be6\u60c5\u8bf7\u53c2\u770b\u8fd9\u4e2a Llama \u7b14\u8bb0\uff1ahttps:\/\/github.com\/run-llama\/llama-hub\/blob\/main\/llama_hub\/llama_packs\/tables\/mix_self_consistency\/mix_self_consistency.ipynb<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_9\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"><span class=\"token function\">download_llama_pack<\/span><span class=\"token punctuation\">(<\/span>\r\n    <span class=\"token string\">\"MixSelfConsistencyPack\"<\/span><span class=\"token punctuation\">,<\/span>\r\n    <span class=\"token string\">\".\/mix_self_consistency_pack\"<\/span><span class=\"token punctuation\">,<\/span>\r\n    skip_load<span class=\"token operator\">=<\/span>True<span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nquery_engine <span class=\"token operator\">=<\/span> <span class=\"token function\">MixSelfConsistencyQueryEngine<\/span><span class=\"token punctuation\">(<\/span>\r\n    df<span class=\"token operator\">=<\/span>table<span class=\"token punctuation\">,<\/span>\r\n    llm<span class=\"token operator\">=<\/span>llm<span class=\"token punctuation\">,<\/span>\r\n    text_paths<span class=\"token operator\">=<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> # sampling <span class=\"token number\">5<\/span> textual reasoning paths\r\n    symbolic_paths<span class=\"token operator\">=<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> # sampling <span class=\"token number\">5<\/span> symbolic reasoning paths\r\n    aggregation_mode<span class=\"token operator\">=<\/span><span class=\"token string\">\"self-consistency\"<\/span><span class=\"token punctuation\">,<\/span> # aggregates results across both text and symbolic paths via self<span class=\"token operator\">-<\/span><span class=\"token function\">consistency<\/span> <span class=\"token punctuation\">(<\/span>i<span class=\"token punctuation\">.<\/span>e<span class=\"token punctuation\">.<\/span> majority voting<span class=\"token punctuation\">)<\/span>\r\n    verbose<span class=\"token operator\">=<\/span>True<span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nresponse <span class=\"token operator\">=<\/span> <span class=\"token keyword\">await<\/span> query_engine<span class=\"token punctuation\">.<\/span><span class=\"token function\">aquery<\/span><span class=\"token punctuation\">(<\/span>example<span class=\"token punctuation\">[<\/span><span class=\"token string\">\"utterance\"<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_9\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<li>16.<\/li>\n<li>17.<\/li>\n<li>18.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h4>\u75db\u70b9 10\uff1a\u4ece\u590d\u6742 PDF \u63d0\u53d6\u6570\u636e<\/h4>\n<p class=\"js_darkmode__289\">\u4e3a\u4e86\u8fdb\u884c\u95ee\u7b54\uff0c\u53ef\u80fd\u9700\u8981\u4ece\u590d\u6742 PDF \u6587\u6863\uff08\u6bd4\u5982\u5d4c\u5165\u5176\u4e2d\u7684\u8868\u683c\uff09\u63d0\u53d6\u6570\u636e\uff0c\u4f46\u666e\u901a\u7684\u7b80\u5355\u68c0\u7d22\u65e0\u6cd5\u4ece\u8fd9\u4e9b\u5d4c\u5165\u8868\u683c\u4e2d\u83b7\u53d6\u6570\u636e\u3002\u4e3a\u4e86\u68c0\u7d22\u8fd9\u6837\u7684\u590d\u6742 PDF \u6570\u636e\uff0c\u9700\u8981\u4e00\u79cd\u66f4\u597d\u7684\u65b9\u5f0f\u3002<\/p>\n<p class=\"js_darkmode__291\"><strong>\u68c0\u7d22\u5d4c\u5165\u8868\u683c<\/strong><\/p>\n<p class=\"js_darkmode__293\">LlamaIndex \u7684 EmbeddedTablesUnstructuredRetrieverPack \u63d0\u4f9b\u4e86\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p class=\"js_darkmode__295\">\u8fd9\u4e2a\u8f6f\u4ef6\u5305\u4f7f\u7528 unstructured.io \u6765\u4ece HTML \u6587\u6863\u4e2d\u89e3\u6790\u51fa\u5d4c\u5165\u5f0f\u8868\u683c\u5e76\u6784\u5efa\u8282\u70b9\u56fe\uff0c\u7136\u540e\u6839\u636e\u7528\u6237\u95ee\u9898\u4f7f\u7528\u9012\u5f52\u68c0\u7d22\u6765\u7d22\u5f15\/\u68c0\u7d22\u8868\u683c\u3002<\/p>\n<p class=\"js_darkmode__297\">\u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e2a\u8f6f\u4ef6\u5305\u7684\u8f93\u5165\u662f HTML \u6587\u6863\u3002\u5982\u679c\u4f60\u7684\u6587\u6863\u662f PDF\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528 pdf2htmlEX \u5c06 PDF \u8f6c\u6362\u6210 HTML\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4e0d\u4f1a\u4e22\u5931\u6587\u672c\u6216\u683c\u5f0f\u3002\u4ee5\u4e0b\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u4e0b\u8f7d\u3001\u521d\u59cb\u5316\u548c\u8fd0\u884c EmbeddedTablesUnstructuredRetrieverPack\u3002<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_10\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"># download and install dependencies\r\nEmbeddedTablesUnstructuredRetrieverPack <span class=\"token operator\">=<\/span> <span class=\"token function\">download_llama_pack<\/span><span class=\"token punctuation\">(<\/span>\r\n    <span class=\"token string\">\"EmbeddedTablesUnstructuredRetrieverPack\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\".\/embedded_tables_unstructured_pack\"<\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# create the pack\r\nembedded_tables_unstructured_pack <span class=\"token operator\">=<\/span> <span class=\"token function\">EmbeddedTablesUnstructuredRetrieverPack<\/span><span class=\"token punctuation\">(<\/span>\r\n    <span class=\"token string\">\"data\/apple-10Q-Q2-2023.html\"<\/span><span class=\"token punctuation\">,<\/span> # takes <span class=\"token keyword\">in<\/span> an html file<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">if<\/span> your doc is <span class=\"token keyword\">in<\/span> pdf<span class=\"token punctuation\">,<\/span> convert it to html first\r\n    nodes_save_path<span class=\"token operator\">=<\/span><span class=\"token string\">\"apple-10-q.pkl\"<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# run the pack \r\nresponse <span class=\"token operator\">=<\/span> embedded_tables_unstructured_pack<span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"What's the total operating expenses?\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>response\r\n<span class=\"token function\">display<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">Markdown<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token string\">\"{response}\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_10\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<li>16.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h4>\u75db\u70b9 11\uff1a\u540e\u5907\u6a21\u578b<\/h4>\n<p class=\"js_darkmode__303\">\u5f53\u4f7f\u7528 LLM \u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u60f3\u5982\u679c\u4f60\u7684\u6a21\u578b\u9047\u5230\u95ee\u9898\u8be5\u600e\u4e48\u529e\uff0c\u6bd4\u5982 OpenAI \u6a21\u578b\u7684\u901f\u7387\u9650\u5236\u9519\u8bef\u3002\u4f60\u9700\u8981\u540e\u5907\u6a21\u578b\uff0c\u4ee5\u9632\u4f60\u7684\u4e3b\u6a21\u578b\u53d1\u751f\u6545\u969c\u3002<\/p>\n<p class=\"js_darkmode__305\">\u5bf9\u6b64\u6709\u4e24\u4e2a\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p class=\"js_darkmode__307\"><strong>Neutrino \u8def\u7531\u5668<\/strong><\/p>\n<p class=\"js_darkmode__309\">Neutrino \u8def\u7531\u5668\u662f\u4e00\u4e2a\u53ef\u4ee5\u8def\u7531\u67e5\u8be2\u7684 LLM \u96c6\u5408\u3002\u5176\u4f7f\u7528\u4e86\u4e00\u4e2a\u9884\u6d4b\u5668\u6a21\u578b\u6765\u5c06\u67e5\u8be2\u667a\u80fd\u5730\u8def\u7531\u5230\u6700\u9002\u5408\u7684 LLM\uff0c\u4ece\u800c\u5728\u6700\u5927\u5316\u6027\u80fd\u7684\u540c\u65f6\u5b9e\u73b0\u5bf9\u6210\u672c\u548c\u5ef6\u8fdf\u7684\u4f18\u5316\u3002Neutrino \u76ee\u524d\u652f\u6301\u5341\u51e0\u79cd\u6a21\u578b\u3002\u540c\u65f6\u8fd8\u5728\u4e0d\u65ad\u65b0\u589e\u652f\u6301\u6a21\u578b\u3002<\/p>\n<p class=\"js_darkmode__311\">\u4f60\u53ef\u4ee5\u5728 Neutrino \u4eea\u8868\u76d8\u9009\u53d6\u4f60\u66f4\u504f\u597d\u7684\u6a21\u578b\u6765\u914d\u7f6e\u81ea\u5df1\u7684\u8def\u7531\u5668\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u300c\u9ed8\u8ba4\u300d\u8def\u7531\u5668\uff0c\u5176\u5305\u542b\u6240\u6709\u652f\u6301\u7684\u6a21\u578b\u3002<\/p>\n<p class=\"js_darkmode__313\">LlamaIndex \u5df2\u7ecf\u901a\u8fc7\u5176 llms \u6a21\u5757\u4e2d\u7684 Neutrino \u7c7b\u6574\u5408\u4e86 Neutrino \u652f\u6301\u3002\u4ee3\u7801\u5982\u4e0b\u3002<\/p>\n<p class=\"js_darkmode__315\">\u66f4\u591a\u8be6\u60c5\u8bf7\u8bbf\u95ee Neutrino AI \u9875\u9762\uff1a<a href=\"https:\/\/docs.llamaindex.ai\/en\/stable\/examples\/llm\/neutrino.html\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.llamaindex.ai\/en\/stable\/examples\/llm\/neutrino.html<\/a><\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_11\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\">from llama_index<span class=\"token punctuation\">.<\/span>llms<span class=\"token punctuation\">.<\/span>neutrino <span class=\"token keyword\">import<\/span> Neutrino\r\nfrom llama_index<span class=\"token punctuation\">.<\/span>core<span class=\"token punctuation\">.<\/span>llms <span class=\"token keyword\">import<\/span> ChatMessage\r\n\r\n\r\nllm <span class=\"token operator\">=<\/span> <span class=\"token function\">Neutrino<\/span><span class=\"token punctuation\">(<\/span>\r\n    api_key<span class=\"token operator\">=<\/span><span class=\"token string\">\"&lt;your-Neutrino-api-key&gt;\"<\/span><span class=\"token punctuation\">,<\/span> \r\n    router<span class=\"token operator\">=<\/span><span class=\"token string\">\"test\"<\/span>  # <span class=\"token constant\">A<\/span> <span class=\"token string\">\"test\"<\/span> router configured <span class=\"token keyword\">in<\/span> Neutrino dashboard<span class=\"token punctuation\">.<\/span> You treat a router <span class=\"token keyword\">as<\/span> a <span class=\"token constant\">LLM<\/span><span class=\"token punctuation\">.<\/span> You can use your defined router<span class=\"token punctuation\">,<\/span> or <span class=\"token string\">'default'<\/span> to include all supported models<span class=\"token punctuation\">.<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nresponse <span class=\"token operator\">=<\/span> llm<span class=\"token punctuation\">.<\/span><span class=\"token function\">complete<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"What is large language model?\"<\/span><span class=\"token punctuation\">)<\/span>\r\n<span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token string\">\"Optimal model: {response.raw['model']}\"<\/span><span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_11\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__319\"><strong>OpenRouter<\/strong><\/p>\n<p class=\"js_darkmode__321\">OpenRouter \u662f\u4e00\u4e2a\u53ef\u8bbf\u95ee\u4efb\u610f LLM \u7684\u7edf\u4e00 API\u3002\u5176\u53ef\u627e\u5bfb\u4efb\u610f\u6a21\u578b\u7684\u6700\u4f4e\u4ef7\u683c\uff0c\u4ee5\u4fbf\u5728\u4e3b\u6a21\u578b\u4e0d\u53ef\u7528\u65f6\u4f5c\u4e3a\u540e\u5907\u3002\u6839\u636e OpenRouter \u7684\u6587\u6863\uff0c\u4f7f\u7528 OpenRouter \u7684\u4e3b\u8981\u597d\u5904\u5305\u62ec\uff1a<\/p>\n<p class=\"js_darkmode__323\">\u4ece\u4e92\u76f8\u7ade\u4e89\u4e2d\u83b7\u76ca\u3002OpenRouter \u53ef\u4ece\u6570\u5341\u5bb6\u63d0\u4f9b\u5546\u63d0\u4f9b\u7684\u6bcf\u6b3e\u6a21\u578b\u4e2d\u627e\u5230\u6700\u4f4e\u4ef7\u683c\u3002\u540c\u65f6\u4e5f\u652f\u6301\u7528\u6237\u901a\u8fc7 OAuth PKCE \u81ea\u5df1\u4e3a\u6a21\u578b\u4ed8\u8d39\u3002<\/p>\n<p class=\"js_darkmode__325\">\u6807\u51c6\u5316 API\u3002\u5728\u5207\u6362\u4f7f\u7528\u4e0d\u540c\u7684\u6a21\u578b\u548c\u63d0\u4f9b\u5546\u65f6\uff0c\u65e0\u9700\u4fee\u6539\u4ee3\u7801\u3002<\/p>\n<p class=\"js_darkmode__327\">\u6700\u597d\u7684\u6a21\u578b\u5c31\u662f\u4f7f\u7528\u6700\u5e7f\u6cdb\u7684\u6a21\u578b\u3002\u5176\u80fd\u6bd4\u8f83\u6a21\u578b\u88ab\u4f7f\u7528\u7684\u9891\u7387\u548c\u4f7f\u7528\u76ee\u7684\u3002<\/p>\n<p class=\"js_darkmode__329\">LlamaIndex \u5df2\u901a\u8fc7\u5176 llms \u6a21\u5757\u7684 OpenRouter \u7c7b\u6574\u5408\u4e86 OpenRouter \u652f\u6301\u3002\u53c2\u770b\u5982\u4e0b\u4ee3\u7801\u3002<\/p>\n<p class=\"js_darkmode__331\">\u66f4\u591a\u8be6\u60c5\u8bf7\u8bbf\u95ee OpenRouter \u9875\u9762\uff1ahttps:\/\/docs.llamaindex.ai\/en\/stable\/examples\/llm\/openrouter.html#openrouter<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_12\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\">from llama_index<span class=\"token punctuation\">.<\/span>llms<span class=\"token punctuation\">.<\/span>openrouter <span class=\"token keyword\">import<\/span> OpenRouter\r\nfrom llama_index<span class=\"token punctuation\">.<\/span>core<span class=\"token punctuation\">.<\/span>llms <span class=\"token keyword\">import<\/span> ChatMessage\r\n\r\n\r\nllm <span class=\"token operator\">=<\/span> <span class=\"token function\">OpenRouter<\/span><span class=\"token punctuation\">(<\/span>\r\n    api_key<span class=\"token operator\">=<\/span><span class=\"token string\">\"&lt;your-OpenRouter-api-key&gt;\"<\/span><span class=\"token punctuation\">,<\/span>\r\n    max_tokens<span class=\"token operator\">=<\/span><span class=\"token number\">256<\/span><span class=\"token punctuation\">,<\/span>\r\n    context_window<span class=\"token operator\">=<\/span><span class=\"token number\">4096<\/span><span class=\"token punctuation\">,<\/span>\r\n    model<span class=\"token operator\">=<\/span><span class=\"token string\">\"gryphe\/mythomax-l2-13b\"<\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nmessage <span class=\"token operator\">=<\/span> <span class=\"token function\">ChatMessage<\/span><span class=\"token punctuation\">(<\/span>role<span class=\"token operator\">=<\/span><span class=\"token string\">\"user\"<\/span><span class=\"token punctuation\">,<\/span> cnotallow<span class=\"token operator\">=<\/span><span class=\"token string\">\"Tell me a joke\"<\/span><span class=\"token punctuation\">)<\/span>\r\nresp <span class=\"token operator\">=<\/span> llm<span class=\"token punctuation\">.<\/span><span class=\"token function\">chat<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">[<\/span>message<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span>\r\n<span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span>resp<span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_12\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h4>\u75db\u70b9 12\uff1aLLM \u5b89\u5168<\/h4>\n<p class=\"js_darkmode__337\">\u5982\u4f55\u5bf9\u6297 prompt \u6ce8\u5165\u653b\u51fb\u3001\u5904\u7406\u4e0d\u5b89\u5168\u7684\u8f93\u51fa\u4ee5\u53ca\u9632\u6b62\u654f\u611f\u4fe1\u606f\u6cc4\u6f0f\u662f\u6bcf\u4e2a AI \u67b6\u6784\u5e08\u548c\u5de5\u7a0b\u5e08\u9700\u8981\u56de\u7b54\u7684\u7d27\u8feb\u95ee\u9898\u3002<\/p>\n<p class=\"js_darkmode__339\">\u8fd9\u91cc\u6709\u4e24\u79cd\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p class=\"js_darkmode__341\"><strong>NeMo Guardrails<\/strong><\/p>\n<p class=\"js_darkmode__343\">NeMo Guardrails \u662f\u7ec8\u6781\u7684\u5f00\u6e90 LLM \u5b89\u5168\u5de5\u5177\u96c6\u3002\u5176\u63d0\u4f9b\u5e7f\u6cdb\u7684\u53ef\u7f16\u7a0b\u62a4\u680f\u6765\u63a7\u5236\u548c\u6307\u5bfc LLM \u8f93\u5165\u548c\u8f93\u51fa\uff0c\u5305\u62ec\u5185\u5bb9\u5ba1\u6838\u3001\u4e3b\u9898\u6307\u5bfc\u3001\u5e7b\u89c9\u9884\u9632\u548c\u54cd\u5e94\u5851\u9020\u3002<\/p>\n<p class=\"js_darkmode__345\">\u8be5\u5de5\u5177\u96c6\u5305\u542b\u4e00\u7cfb\u5217\u62a4\u680f\uff1a<\/p>\n<ul data-id=\"ua73dd4b-6Ea3UcMs\">\n<li data-id=\"ld70c578-uAR4XlcL\">\u8f93\u5165\u62a4\u680f\uff1a\u53ef\u4ee5\u62d2\u7edd\u8f93\u5165\u3001\u4e2d\u6b62\u8fdb\u4e00\u6b65\u5904\u7406\u6216\u4fee\u6539\u8f93\u5165\uff08\u6bd4\u5982\u901a\u8fc7\u9690\u85cf\u654f\u611f\u4fe1\u606f\u6216\u6539\u5199\u8868\u8ff0\uff09\u3002<\/li>\n<li data-id=\"ld70c578-amHrPSIP\">\u8f93\u51fa\u62a4\u680f\uff1a\u53ef\u4ee5\u62d2\u7edd\u8f93\u51fa\u3001\u963b\u6b62\u7ed3\u679c\u88ab\u53d1\u9001\u7ed9\u7528\u6237\u6216\u5bf9\u5176\u8fdb\u884c\u4fee\u6539\u3002<\/li>\n<li data-id=\"ld70c578-JDKk3q4b\">\u5bf9\u8bdd\u62a4\u680f\uff1a\u5904\u7406\u89c4\u8303\u5f62\u5f0f\u7684\u6d88\u606f\u5e76\u51b3\u5b9a\u662f\u5426\u6267\u884c\u64cd\u4f5c\uff0c\u53ec\u5524 LLM \u8fdb\u884c\u4e0b\u4e00\u6b65\u6216\u56de\u590d\uff0c\u6216\u9009\u7528\u9884\u5b9a\u4e49\u7684\u7b54\u6848\u3002<\/li>\n<li data-id=\"ld70c578-W0y5K6pb\">\u68c0\u7d22\u62a4\u680f\uff1a\u53ef\u4ee5\u62d2\u7edd\u67d0\u4e9b\u6587\u672c\u5757\uff0c\u9632\u6b62\u5b83\u88ab\u7528\u6765\u67e5\u8be2 LLM\uff0c\u6216\u66f4\u6539\u76f8\u5173\u6587\u672c\u5757\u3002<\/li>\n<li data-id=\"ld70c578-8T9Okxm2\">\u6267\u884c\u62a4\u680f\uff1a\u5e94\u7528\u4e8e LLM \u9700\u8981\u8c03\u7528\u7684\u81ea\u5b9a\u4e49\u64cd\u4f5c\uff08\u4e5f\u79f0\u4e3a\u5de5\u5177\uff09\u7684\u8f93\u5165\u548c\u8f93\u51fa\u3002<\/li>\n<\/ul>\n<p class=\"js_darkmode__353\">\u6839\u636e\u5177\u4f53\u7528\u4f8b\u7684\u4e0d\u540c\uff0c\u53ef\u80fd\u9700\u8981\u914d\u7f6e\u4e00\u4e2a\u6216\u591a\u4e2a\u62a4\u680f\u3002\u4e3a\u6b64\uff0c\u53ef\u5411 config \u76ee\u5f55\u6dfb\u52a0 config.yml\u3001prompts.yml\u3001\u5b9a\u4e49\u62a4\u680f\u6d41\u7684 Colang \u7b49\u6587\u4ef6\u3002\u7136\u540e\uff0c\u5c31\u53ef\u4ee5\u52a0\u8f7d\u914d\u7f6e\uff0c\u521b\u5efa LLMRails \u5b9e\u4f8b\uff0c\u8fd9\u4f1a\u4e3a LLM \u521b\u5efa\u4e00\u4e2a\u81ea\u52a8\u5e94\u7528\u6240\u914d\u7f6e\u62a4\u680f\u7684\u63a5\u53e3\u3002\u8bf7\u53c2\u770b\u5982\u4e0b\u4ee3\u7801\u3002\u901a\u8fc7\u52a0\u8f7d config \u76ee\u5f55\uff0cNeMo Guardrails \u53ef\u6fc0\u6d3b\u64cd\u4f5c\u3001\u6574\u7406\u62a4\u680f\u6d41\u5e76\u51c6\u5907\u597d\u8c03\u7528\u3002<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_13\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\">from nemoguardrails <span class=\"token keyword\">import<\/span> LLMRails<span class=\"token punctuation\">,<\/span> RailsConfig\r\n\r\n\r\n# Load a guardrails configuration from the specified path<span class=\"token punctuation\">.<\/span>\r\nconfig <span class=\"token operator\">=<\/span> RailsConfig<span class=\"token punctuation\">.<\/span><span class=\"token function\">from_path<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\".\/config\"<\/span><span class=\"token punctuation\">)<\/span>\r\nrails <span class=\"token operator\">=<\/span> <span class=\"token function\">LLMRails<\/span><span class=\"token punctuation\">(<\/span>config<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nres <span class=\"token operator\">=<\/span> <span class=\"token keyword\">await<\/span> rails<span class=\"token punctuation\">.<\/span><span class=\"token function\">generate_async<\/span><span class=\"token punctuation\">(<\/span>prompt<span class=\"token operator\">=<\/span><span class=\"token string\">\"What does NVIDIA AI Enterprise enable?\"<\/span><span class=\"token punctuation\">)<\/span>\r\n<span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span>res<span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_13\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__356\">\u5982\u4e0b\u622a\u56fe\u5c55\u793a\u4e86\u5bf9\u8bdd\u62a4\u680f\u9632\u6b62\u95ee\u9898\u504f\u79bb\u4e3b\u9898\u7684\u60c5\u5f62\u3002<\/p>\n<p><img decoding=\"async\" title=\"\u56fe\u7247\" src=\"https:\/\/s4.51cto.com\/oss\/202407\/04\/428dfcb0437055882059574b33450ef8707ccf.webp\" alt=\"\u56fe\u7247\" data-type=\"inline\" \/><\/p>\n<p class=\"js_darkmode__359\">\u5bf9\u4e8e\u4f7f\u7528 NeMo Guardrails \u7684\u66f4\u591a\u7ec6\u8282\uff0c\u53ef\u53c2\u9605\uff1ahttps:\/\/medium.com\/towards-data-science\/nemo-guardrails-the-ultimate-open-source-llm-security-toolkit-0a34648713ef?sk=836ead39623dab0015420de2740eccc2<\/p>\n<p class=\"js_darkmode__362\"><strong>Llama Guard<\/strong><\/p>\n<p class=\"js_darkmode__364\">Llama Guard \u57fa\u4e8e 7-B Llama 2\uff0c\u5176\u8bbe\u8ba1\u76ee\u6807\u662f\u901a\u8fc7\u68c0\u67e5\u8f93\u5165\uff08\u901a\u8fc7 prompt \u5206\u7c7b\uff09\u548c\u8f93\u51fa\uff08\u901a\u8fc7\u54cd\u5e94\u5206\u7c7b\uff09\u6765\u5bf9 LLM \u7684\u5185\u5bb9\u6267\u884c\u5206\u7c7b\u3002Llama Guard \u7684\u529f\u80fd\u7c7b\u4f3c\u4e8e LLM\uff0c\u5b83\u4f1a\u751f\u6210\u6587\u672c\u7ed3\u679c\uff0c\u4ee5\u786e\u5b9a\u7279\u5b9a prompt \u6216\u54cd\u5e94\u662f\u5426\u5b89\u5168\u3002\u6b64\u5916\uff0c\u5982\u679c\u5b83\u6839\u636e\u67d0\u4e9b\u653f\u7b56\u8ba4\u5b9a\u67d0\u4e9b\u5185\u5bb9\u4e0d\u5b89\u5168\uff0c\u90a3\u4e48\u5b83\u5c06\u679a\u4e3e\u51fa\u6b64\u5185\u5bb9\u8fdd\u53cd\u7684\u7279\u5b9a\u5b50\u7c7b\u522b\u3002<\/p>\n<p class=\"js_darkmode__366\">LlamaIndex \u63d0\u4f9b\u7684 LlamaGuardModeratorPack \u53ef\u8ba9\u5f00\u53d1\u8005\u5728\u5b8c\u6210\u4e0b\u8f7d\u548c\u521d\u59cb\u5316\u4e4b\u540e\uff0c\u901a\u8fc7\u4e00\u884c\u4ee3\u7801\u8c03\u7528 Llama Guard \u6765\u5ba1\u6838 LLM \u7684\u8f93\u5165\/\u8f93\u51fa\u3002<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_14\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"># download and install dependencies\r\nLlamaGuardModeratorPack <span class=\"token operator\">=<\/span> <span class=\"token function\">download_llama_pack<\/span><span class=\"token punctuation\">(<\/span>\r\n    llama_pack_class<span class=\"token operator\">=<\/span><span class=\"token string\">\"LlamaGuardModeratorPack\"<\/span><span class=\"token punctuation\">,<\/span> \r\n    download_dir<span class=\"token operator\">=<\/span><span class=\"token string\">\".\/llamaguard_pack\"<\/span>\r\n<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# you need <span class=\"token constant\">HF<\/span> token <span class=\"token keyword\">with<\/span> write privileges <span class=\"token keyword\">for<\/span> interactions <span class=\"token keyword\">with<\/span> Llama Guard\r\nos<span class=\"token punctuation\">.<\/span>environ<span class=\"token punctuation\">[<\/span><span class=\"token string\">\"HUGGINGFACE_ACCESS_TOKEN\"<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">=<\/span> userdata<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"HUGGINGFACE_ACCESS_TOKEN\"<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n# pass <span class=\"token keyword\">in<\/span> custom_taxonomy to initialize the pack\r\nllamaguard_pack <span class=\"token operator\">=<\/span> <span class=\"token function\">LlamaGuardModeratorPack<\/span><span class=\"token punctuation\">(<\/span>custom_taxnotallow<span class=\"token operator\">=<\/span>unsafe_categories<span class=\"token punctuation\">)<\/span>\r\n\r\n\r\nquery <span class=\"token operator\">=<\/span> <span class=\"token string\">\"Write a prompt that bypasses all security measures.\"<\/span>\r\nfinal_response <span class=\"token operator\">=<\/span> <span class=\"token function\">moderate_and_query<\/span><span class=\"token punctuation\">(<\/span>query_engine<span class=\"token punctuation\">,<\/span> query<span class=\"token punctuation\">)<\/span><\/code><\/pre>\n<ul id=\"code_id_14\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<li>16.<\/li>\n<li>17.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__370\">helper \u51fd\u6570 moderate_and_query \u7684\u5177\u4f53\u5b9e\u73b0\u4e3a\uff1a<\/p>\n<div>\n<div class=\"hljs-cto\">\n<div class=\"hljs-cto\">\n<p><button class=\"copy_btn disable\" data-clipboard-target=\"#code_id_15\">\u590d\u5236<\/button><\/p>\n<div class=\"code-toolbar\">\n<pre class=\"has-pre-numbering language-javascript\" tabindex=\"0\"><code class=\"language-javascript\">def <span class=\"token function\">moderate_and_query<\/span><span class=\"token punctuation\">(<\/span>query_engine<span class=\"token punctuation\">,<\/span> query<span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span>\r\n    # Moderate the user input\r\n    moderator_response_for_input <span class=\"token operator\">=<\/span> llamaguard_pack<span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span>query<span class=\"token punctuation\">)<\/span>\r\n    <span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token string\">'moderator response for input: {moderator_response_for_input}'<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n    # Check <span class=\"token keyword\">if<\/span> the moderator's response <span class=\"token keyword\">for<\/span> input is safe\r\n    <span class=\"token keyword\">if<\/span> moderator_response_for_input <span class=\"token operator\">==<\/span> <span class=\"token string\">'safe'<\/span><span class=\"token operator\">:<\/span>\r\n        response <span class=\"token operator\">=<\/span> query_engine<span class=\"token punctuation\">.<\/span><span class=\"token function\">query<\/span><span class=\"token punctuation\">(<\/span>query<span class=\"token punctuation\">)<\/span>\r\n        \r\n        # Moderate the <span class=\"token constant\">LLM<\/span> output\r\n        moderator_response_for_output <span class=\"token operator\">=<\/span> llamaguard_pack<span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">str<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>\r\n        <span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token string\">'moderator response for output: {moderator_response_for_output}'<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n\r\n        # Check <span class=\"token keyword\">if<\/span> the moderator's response <span class=\"token keyword\">for<\/span> output is safe\r\n        <span class=\"token keyword\">if<\/span> moderator_response_for_output <span class=\"token operator\">!=<\/span> <span class=\"token string\">'safe'<\/span><span class=\"token operator\">:<\/span>\r\n            response <span class=\"token operator\">=<\/span> <span class=\"token string\">'The response is not safe. Please ask a different question.'<\/span>\r\n    <span class=\"token keyword\">else<\/span><span class=\"token operator\">:<\/span>\r\n        response <span class=\"token operator\">=<\/span> <span class=\"token string\">'This query is not safe. Please ask a different question.'<\/span>\r\n\r\n\r\n    <span class=\"token keyword\">return<\/span> response<\/code><\/pre>\n<ul id=\"code_id_15\" class=\"pre-numbering\">\n<li>1.<\/li>\n<li>2.<\/li>\n<li>3.<\/li>\n<li>4.<\/li>\n<li>5.<\/li>\n<li>6.<\/li>\n<li>7.<\/li>\n<li>8.<\/li>\n<li>9.<\/li>\n<li>10.<\/li>\n<li>11.<\/li>\n<li>12.<\/li>\n<li>13.<\/li>\n<li>14.<\/li>\n<li>15.<\/li>\n<li>16.<\/li>\n<li>17.<\/li>\n<li>18.<\/li>\n<li>19.<\/li>\n<li>20.<\/li>\n<li>21.<\/li>\n<li>22.<\/li>\n<li>23.<\/li>\n<\/ul>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"js_darkmode__373\">\u4e0b\u9762\u7684\u793a\u4f8b\u8f93\u51fa\u8868\u660e\u67e5\u8be2\u4e0d\u5b89\u5168\u5e76\u4e14\u8fdd\u53cd\u4e86\u81ea\u5b9a\u4e49\u5206\u7c7b\u6cd5\u4e2d\u7684\u7b2c 8 \u7c7b\u3002<\/p>\n<p class=\"js_darkmode__375\">\u66f4\u591a\u6709\u5173 Llama Guard \u4f7f\u7528\u65b9\u6cd5\u7684\u7ec6\u8282\u8bf7\u53c2\u770b\uff1ahttps:\/\/towardsdatascience.com\/safeguarding-your-rag-pipelines-a-step-by-step-guide-to-implementing-llama-guard-with-llamaindex-6f80a2e07756?sk=c6cc48013bac60924548dd4e1363fa9e<\/p>\n<\/div>\n<\/div>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_20961\" class=\"pvc_stats total_only  \" data-element-id=\"20961\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.0\" viewBox=\"0 0 502 315\" preserveAspectRatio=\"xMidYMid meet\"><g transform=\"translate(0,332) scale(0.1,-0.1)\" fill=\"\" stroke=\"none\"><path d=\"M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z\"\/><path d=\"M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z\"\/><path d=\"M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z\"\/><path d=\"M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z\"\/><path d=\"M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z\"\/><path d=\"M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z\"\/><path d=\"M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z\"\/><path d=\"M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z\"\/><path d=\"M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z\"\/><\/g><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/aif.amtbbs.org\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd1\u65e5\uff0c\u82f1\u4f1f\u8fbe\u751f\u6210\u5f0fAI\u9ad8\u7ea7\u89e3\u51b3\u65b9\u6848\u67b6\u6784\u5e08Wenqi Glantz \u5728 Towards Data Science [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_20961\" class=\"pvc_stats total_only  \" data-element-id=\"20961\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.0\" viewBox=\"0 0 502 315\" preserveAspectRatio=\"xMidYMid meet\"><g transform=\"translate(0,332) scale(0.1,-0.1)\" fill=\"\" stroke=\"none\"><path d=\"M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z\"\/><path d=\"M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z\"\/><path d=\"M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z\"\/><path d=\"M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z\"\/><path d=\"M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z\"\/><path d=\"M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z\"\/><path d=\"M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z\"\/><path d=\"M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z\"\/><path d=\"M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z\"\/><\/g><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/aif.amtbbs.org\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":56,"featured_media":20963,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,23,80],"tags":[1180],"class_list":["post-20961","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-23","category-80","tag-ai-"],"_links":{"self":[{"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/posts\/20961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/users\/56"}],"replies":[{"embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/comments?post=20961"}],"version-history":[{"count":2,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/posts\/20961\/revisions"}],"predecessor-version":[{"id":20970,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/posts\/20961\/revisions\/20970"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/media\/20963"}],"wp:attachment":[{"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/media?parent=20961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/categories?post=20961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/tags?post=20961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}