{"id":28966,"date":"2025-03-18T03:06:41","date_gmt":"2025-03-17T19:06:41","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=28966"},"modified":"2025-03-18T03:06:41","modified_gmt":"2025-03-17T19:06:41","slug":"dify-lianjiewaibuzhi","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/pt\/dify-lianjiewaibuzhi\/","title":{"rendered":"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b"},"content":{"rendered":"<p>\u4e3a\u4e86\u65b9\u4fbf\u533a\u5206\uff0c\u672c\u6587\u5c06 <a href=\"https:\/\/www.kdjingpai.com\/de\/dify\/\">Dify<\/a> \u5e73\u53f0\u4e4b\u5916\u7684\u77e5\u8bc6\u5e93\u7edf\u79f0\u4e3a\u201c\u5916\u90e8\u77e5\u8bc6\u5e93\u201d\u3002<\/p>\n<h2>\u529f\u80fd\u7b80\u4ecb<\/h2>\n<p>Dify \u5185\u7f6e\u7684\u77e5\u8bc6\u5e93\u529f\u80fd\u548c\u6587\u672c\u68c0\u7d22\u673a\u5236\u53ef\u80fd\u65e0\u6cd5\u6ee1\u8db3\u90e8\u5206\u9ad8\u7ea7\u5f00\u53d1\u8005\u7684\u9700\u6c42\uff0c\u4ed6\u4eec\u53ef\u80fd\u9700\u8981\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u6587\u672c\u53ec\u56de\u7ed3\u679c\u3002<\/p>\n<p>\u6709\u4e9b\u56e2\u961f\u4f1a\u9009\u62e9\u81ea\u7814 <a href=\"https:\/\/www.kdjingpai.com\/de\/rag\/\">RAG<\/a> \u7b97\u6cd5\u5e76\u72ec\u7acb\u7ef4\u62a4\u6587\u672c\u53ec\u56de\u7cfb\u7edf\uff0c\u6216\u8005\u4f7f\u7528\u4e91\u670d\u52a1\u5546\u63d0\u4f9b\u7684\u77e5\u8bc6\u5e93\u670d\u52a1\uff08\u5982\u00a0AWS Bedrock\uff09\u3002<\/p>\n<p>Dify \u4f5c\u4e3a\u4e00\u4e2a\u5f00\u653e\u7684 LLM \u5e94\u7528\u5f00\u53d1\u5e73\u53f0\uff0c\u5e0c\u671b\u7ed9\u5f00\u53d1\u8005\u63d0\u4f9b\u66f4\u591a\u7684\u9009\u62e9\u3002<\/p>\n<p>\u901a\u8fc7\u201c\u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u201d\u529f\u80fd\uff0cDify \u53ef\u4ee5\u4e0e\u5916\u90e8\u77e5\u8bc6\u5e93\u5efa\u7acb\u8fde\u63a5\u3002\u8fd9\u6837\uff0cAI \u5e94\u7528\u5c31\u80fd\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\u6765\u6e90\u3002<\/p>\n<p>\u5177\u4f53\u6765\u8bf4\uff0c\u6709\u4ee5\u4e0b\u4f18\u52bf\uff1a<\/p>\n<ul>\n<li>Dify \u53ef\u4ee5\u76f4\u63a5\u83b7\u53d6\u6258\u7ba1\u5728\u4e91\u670d\u52a1\u5546\u77e5\u8bc6\u5e93\u5185\u7684\u6587\u672c\uff0c\u5f00\u53d1\u8005\u65e0\u9700\u5c06\u5185\u5bb9\u590d\u5236\u5230 Dify \u7684\u77e5\u8bc6\u5e93\u4e2d\u3002<\/li>\n<li>Dify \u53ef\u4ee5\u76f4\u63a5\u83b7\u53d6\u81ea\u5efa\u77e5\u8bc6\u5e93\u4e2d\u7ecf\u8fc7\u7b97\u6cd5\u5904\u7406\u540e\u7684\u6587\u672c\uff0c\u5f00\u53d1\u8005\u53ea\u9700\u4e13\u6ce8\u4e8e\u4f18\u5316\u4fe1\u606f\u68c0\u7d22\u673a\u5236\uff0c\u63d0\u9ad8\u53ec\u56de\u51c6\u786e\u5ea6\u3002<\/li>\n<li>\u76f8\u6bd4\u76f4\u63a5\u4f7f\u7528\u4e91\u5382\u5546\u7684\u77e5\u8bc6\u5e93\u670d\u52a1\uff0cDify \u63d0\u4f9b\u4e86\u66f4\u7075\u6d3b\u7684\u5e94\u7528\u5c42\u96c6\u6210\u80fd\u529b\uff0c\u65b9\u4fbf\u5f00\u53d1\u8005\u6784\u5efa\u591a\u6837\u5316\u7684 AI \u5e94\u7528\u3002<\/li>\n<\/ul>\n<p>\u4e0b\u56fe\u5c55\u793a\u4e86\u5916\u90e8\u77e5\u8bc6\u5e93\u7684\u8fde\u63a5\u539f\u7406\uff1a<\/p>\n<p><img decoding=\"async\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/b9aee02fb251448.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u8fde\u63a5\u6b65\u9aa4<\/h2>\n<h4>1. \u5efa\u7acb\u7b26\u5408\u8981\u6c42\u7684\u5916\u90e8\u77e5\u8bc6\u5e93 API<\/h4>\n<p>\u5728\u5efa\u7acb API \u670d\u52a1\u4e4b\u524d\uff0c\u8bf7\u52a1\u5fc5\u4ed4\u7ec6\u9605\u8bfb Dify \u7f16\u5199\u7684\u5916\u90e8\u77e5\u8bc6\u5e93 API \u89c4\u8303\u3002<\/p>\n<h4>2. \u5173\u8054\u5916\u90e8\u77e5\u8bc6\u5e93 API<\/h4>\n<p>\u8bf7\u6ce8\u610f\uff0cDify \u76ee\u524d\u4ec5\u652f\u6301\u5bf9\u5916\u90e8\u77e5\u8bc6\u5e93\u8fdb\u884c\u68c0\u7d22\uff0c\u4e0d\u652f\u6301\u4fee\u6539\u3002\u5f00\u53d1\u8005\u9700\u8981\u81ea\u884c\u7ef4\u62a4\u5916\u90e8\u77e5\u8bc6\u5e93\u3002<\/p>\n<p>\u8fdb\u5165\u201c\u77e5\u8bc6\u5e93\u201d\u9875\u9762\uff0c\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u201c\u5916\u90e8\u77e5\u8bc6\u5e93 API\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u6dfb\u52a0\u5916\u90e8\u77e5\u8bc6\u5e93 API\u201d\u3002<\/p>\n<p>\u6839\u636e\u9875\u9762\u63d0\u793a\u586b\u5199\uff1a<\/p>\n<ul>\n<li><strong>\u77e5\u8bc6\u5e93\u540d\u79f0\uff1a<\/strong>\u00a0\u53ef\u4ee5\u81ea\u5b9a\u4e49\uff0c\u7528\u4e8e\u533a\u5206\u4e0d\u540c\u7684\u5916\u90e8\u77e5\u8bc6\u5e93 API\u3002<\/li>\n<li><strong>API \u63a5\u53e3\u5730\u5740\uff1a<\/strong>\u00a0\u5916\u90e8\u77e5\u8bc6\u5e93\u7684\u8fde\u63a5\u5730\u5740\uff0c\u4f8b\u5982\u00a0<code>api-endpoint\/retrieval<\/code>\u3002\u8be6\u7ec6\u8bf4\u660e\u8bf7\u53c2\u8003\u5916\u90e8\u77e5\u8bc6\u5e93 API\u3002<\/li>\n<li><strong>API Key\uff1a<\/strong>\u00a0\u5916\u90e8\u77e5\u8bc6\u5e93\u7684\u8fde\u63a5\u5bc6\u94a5\uff0c\u8be6\u7ec6\u8bf4\u660e\u8bf7\u53c2\u8003\u5916\u90e8\u77e5\u8bc6\u5e93 API\u3002<\/li>\n<\/ul>\n<p><img decoding=\"async\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/80a872036a4394a.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" \/><\/p>\n<h4>3. \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93<\/h4>\n<p>\u5728\u201c\u77e5\u8bc6\u5e93\u201d\u9875\u9762\uff0c\u70b9\u51fb\u201c\u6dfb\u52a0\u77e5\u8bc6\u5e93\u201d\u4e0b\u65b9\u7684\u201c\u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u201d\uff0c\u8fdb\u5165\u53c2\u6570\u914d\u7f6e\u9875\u9762\u3002<\/p>\n<p><img decoding=\"async\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/e74999b7c8facc3.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" \/><\/p>\n<p>\u586b\u5199\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<ul>\n<li><strong>\u77e5\u8bc6\u5e93\u540d\u79f0\u4e0e\u63cf\u8ff0<\/strong><\/li>\n<li><strong>\u5916\u90e8\u77e5\u8bc6\u5e93 API\uff1a<\/strong>\u00a0\u9009\u62e9\u5728\u7b2c\u4e8c\u6b65\u4e2d\u5173\u8054\u7684\u5916\u90e8\u77e5\u8bc6\u5e93 API\u3002 Dify \u5c06\u901a\u8fc7 API \u8fde\u63a5\u8c03\u7528\u5916\u90e8\u77e5\u8bc6\u5e93\u7684\u6587\u672c\u5185\u5bb9\u3002<\/li>\n<li><strong>\u5916\u90e8\u77e5\u8bc6\u5e93 ID\uff1a<\/strong>\u00a0\u6307\u5b9a\u9700\u8981\u5173\u8054\u7684\u5916\u90e8\u77e5\u8bc6\u5e93 ID\uff0c\u8be6\u7ec6\u8bf4\u660e\u8bf7\u53c2\u8003\u5916\u90e8\u77e5\u8bc6\u5e93 API\u3002<\/li>\n<li><strong>\u8c03\u6574\u53ec\u56de\u8bbe\u7f6e\uff1a<\/strong>\n<ul>\n<li><strong>Top K\uff1a<\/strong>\u00a0\u503c\u8d8a\u5927\uff0c\u53ec\u56de\u7684\u6587\u672c\u7247\u6bb5\u8d8a\u591a\u3002\u5efa\u8bae\u4ece\u8f83\u5c0f\u7684\u503c\u5f00\u59cb\u5c1d\u8bd5\uff0c\u9010\u6b65\u589e\u52a0\uff0c\u76f4\u5230\u627e\u5230\u6700\u4f73\u5e73\u8861\u70b9\u3002<\/li>\n<li><strong>Score \u9608\u503c\uff1a<\/strong>\u00a0\u503c\u8d8a\u9ad8\uff0c\u53ec\u56de\u7684\u6587\u672c\u7247\u6bb5\u4e0e\u95ee\u9898\u7684\u76f8\u5173\u6027\u8d8a\u9ad8\uff0c\u4f46\u6570\u91cf\u4f1a\u51cf\u5c11\u3002\u5efa\u8bae\u4ece\u8f83\u9ad8\u7684\u503c\u5f00\u59cb\uff0c\u9010\u6b65\u964d\u4f4e\uff0c\u4ee5\u83b7\u53d6\u8db3\u591f\u6570\u91cf\u7684\u76f8\u5173\u6587\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/4becd3d28d699b3.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" \/><\/p>\n<h4>4. \u6d4b\u8bd5\u8fde\u63a5\u4e0e\u53ec\u56de<\/h4>\n<p>\u8fde\u63a5\u5efa\u7acb\u540e\uff0c\u53ef\u4ee5\u5728\u201c\u53ec\u56de\u6d4b\u8bd5\u201d\u4e2d\u6a21\u62df\u95ee\u9898\u5173\u952e\u8bcd\uff0c\u9884\u89c8\u4ece\u5916\u90e8\u77e5\u8bc6\u5e93\u53ec\u56de\u7684\u6587\u672c\u7247\u6bb5\u3002\u5982\u679c\u5bf9\u7ed3\u679c\u4e0d\u6ee1\u610f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4fee\u6539\u53ec\u56de\u53c2\u6570\u6216\u8c03\u6574\u5916\u90e8\u77e5\u8bc6\u5e93\u7684\u68c0\u7d22\u8bbe\u7f6e\u3002<\/p>\n<p><img decoding=\"async\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/07a6a767395efa8.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" \/><\/p>\n<h4>5. \u5728\u5e94\u7528\u5185\u96c6\u6210<\/h4>\n<ul>\n<li><strong>Chatbot \/ Agent \u7c7b\u578b\u5e94\u7528\uff1a<\/strong>\u00a0\u5728\u7f16\u6392\u9875\u9762\u7684\u201c\u4e0a\u4e0b\u6587\u201d\u4e2d\uff0c\u9009\u62e9\u5e26\u6709\u00a0<code>EXTERNAL<\/code>\u00a0\u6807\u7b7e\u7684\u5916\u90e8\u77e5\u8bc6\u5e93\u3002<\/li>\n<\/ul>\n<p><img decoding=\"async\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/25b78d601e63bf9.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" \/><\/p>\n<ul>\n<li><strong>Chatflow \/ Workflow \u7c7b\u578b\u5e94\u7528\uff1a<\/strong>\u00a0\u6dfb\u52a0\u201c\u77e5\u8bc6\u68c0\u7d22\u201d\u8282\u70b9\uff0c\u9009\u62e9\u5e26\u6709\u00a0<code>EXTERNAL<\/code>\u00a0\u6807\u7b7e\u7684\u5916\u90e8\u77e5\u8bc6\u5e93\u3002<\/li>\n<\/ul>\n<p><img decoding=\"async\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/e294c7957b69728.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" \/><\/p>\n<h4>6. \u7ba1\u7406\u5916\u90e8\u77e5\u8bc6\u5e93<\/h4>\n<p>\u5728\u201c\u77e5\u8bc6\u5e93\u201d\u9875\u9762\uff0c\u5916\u90e8\u77e5\u8bc6\u5e93\u5361\u7247\u53f3\u4e0a\u89d2\u4f1a\u6709\u00a0<code>EXTERNAL<\/code>\u00a0\u6807\u7b7e\u3002\u8fdb\u5165\u9700\u8981\u4fee\u6539\u7684\u77e5\u8bc6\u5e93\uff0c\u70b9\u51fb\u201c\u8bbe\u7f6e\u201d\u53ef\u4ee5\u4fee\u6539\uff1a<\/p>\n<ul>\n<li>\u77e5\u8bc6\u5e93\u540d\u79f0\u548c\u63cf\u8ff0<\/li>\n<li>\u53ef\u89c1\u8303\u56f4\uff08\u201c\u53ea\u6709\u6211\u201d\u3001\u201c\u6240\u6709\u56e2\u961f\u6210\u5458\u201d\u548c\u201c\u90e8\u5206\u56e2\u961f\u6210\u5458\u201d\uff09\u3002\u6ca1\u6709\u6743\u9650\u7684\u6210\u5458\u65e0\u6cd5\u8bbf\u95ee\u8be5\u77e5\u8bc6\u5e93\u3002<\/li>\n<li>\u53ec\u56de\u8bbe\u7f6e\uff08Top K \u548c Score \u9608\u503c\uff09<\/li>\n<\/ul>\n<p>\u6ce8\u610f\uff1a\u65e0\u6cd5\u4fee\u6539\u5df2\u5173\u8054\u7684\u201c\u5916\u90e8\u77e5\u8bc6\u5e93 API\u201d\u548c\u201c\u5916\u90e8\u77e5\u8bc6 ID\u201d\uff0c\u5982\u9700\u4fee\u6539\uff0c\u8bf7\u5173\u8054\u65b0\u7684\u201c\u5916\u90e8\u77e5\u8bc6\u5e93 API\u201d\u5e76\u91cd\u65b0\u8fde\u63a5\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3>\u8fde\u63a5\u793a\u4f8b\uff1a\u5982\u4f55\u8fde\u63a5 AWS Bedrock \u77e5\u8bc6\u5e93\uff1f<\/h3>\n<p>\u672c\u6587\u5c06\u7b80\u8981\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u5916\u90e8\u77e5\u8bc6\u5e93 API \u5c06 Dify \u5e73\u53f0\u4e0e AWS Bedrock \u77e5\u8bc6\u5e93\u76f8\u8fde\u63a5\uff0c\u4f7f\u5f97 Dify \u5e73\u53f0\u5185\u7684 AI \u5e94\u7528\u80fd\u591f\u76f4\u63a5\u83b7\u53d6\u5b58\u50a8\u5728 AWS Bedrock \u77e5\u8bc6\u5e93\u4e2d\u7684\u5185\u5bb9\uff0c\u6269\u5c55\u65b0\u7684\u4fe1\u606f\u6765\u6e90\u6e20\u9053\u3002<\/p>\n<p><strong>\u524d\u7f6e\u51c6\u5907<\/strong><\/p>\n<ul>\n<li>AWS Bedrock Knowledge Base<\/li>\n<li>Dify SaaS \u670d\u52a1 \/ Dify \u793e\u533a\u7248<\/li>\n<li>\u540e\u7aef API \u5f00\u53d1\u57fa\u7840\u77e5\u8bc6<\/li>\n<\/ul>\n<p><strong>1. \u6ce8\u518c\u5e76\u521b\u5efa AWS Bedrock Knowledge Base<\/strong><\/p>\n<p>\u8bbf\u95ee AWS Bedrock\uff0c\u521b\u5efa Knowledge Base \u670d\u52a1\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28974\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/5f27d30181f582a.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" width=\"1200\" height=\"637\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/5f27d30181f582a.jpg 1200w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/5f27d30181f582a-768x408.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/5f27d30181f582a-18x10.jpg 18w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<picture>\u521b\u5efa AWS Bedrock Knowledge Base<\/picture>\n<p><strong>2. \u6784\u5efa\u540e\u7aef API \u670d\u52a1<\/strong><\/p>\n<p>Dify \u5e73\u53f0\u5c1a\u4e0d\u80fd\u76f4\u63a5\u8fde\u63a5 AWS Bedrock Knowledge Base\uff0c\u9700\u8981\u5f00\u53d1\u56e2\u961f\u53c2\u8003 Dify \u5173\u4e8e\u5916\u90e8\u77e5\u8bc6\u5e93\u8fde\u63a5\u7684 API \u5b9a\u4e49\uff0c\u624b\u52a8\u521b\u5efa\u540e\u7aef API \u670d\u52a1\uff0c\u5efa\u7acb\u4e0e AWS Bedrock \u7684\u8fde\u63a5\u3002\u5177\u4f53\u67b6\u6784\u793a\u610f\u56fe\u8bf7\u53c2\u8003\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28975\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/dd6c38dd9c4b9c8.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" width=\"1200\" height=\"441\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/dd6c38dd9c4b9c8.jpg 1200w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/dd6c38dd9c4b9c8-768x282.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/dd6c38dd9c4b9c8-18x7.jpg 18w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<picture>\u6784\u5efa\u540e\u7aef API \u670d\u52a1<\/picture>\n<p>\u4f60\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b 2 \u4e2a\u4ee3\u7801\u6587\u4ef6\uff0c\u6784\u5efa\u540e\u7aef\u670d\u52a1 API\u3002<\/p>\n<p><code>knowledge.py<\/code><\/p>\n<pre><code>from flask import request\r\nfrom flask_restful import Resource, reqparse\r\n\r\nfrom bedrock.knowledge_service import ExternalDatasetService\r\n\r\nclass BedrockRetrievalApi(Resource):\r\n    # url : &lt;your-endpoint&gt;\/retrieval\r\n    def post(self):\r\n        parser = reqparse.RequestParser()\r\n        parser.add_argument(\"retrieval_setting\", nullable=False, required=True, type=dict, location=\"json\")\r\n        parser.add_argument(\"query\", nullable=False, required=True, type=str,)\r\n        parser.add_argument(\"knowledge_id\", nullable=False, required=True, type=str)\r\n        args = parser.parse_args()\r\n\r\n        # Authorization check\r\n        auth_header = request.headers.get(\"Authorization\")\r\n        if \" \" not in auth_header:\r\n            return {\r\n                \"error_code\": 1001,\r\n                \"error_msg\": \"Invalid Authorization header format. Expected 'Bearer &lt;api-key&gt;' format.\"\r\n            }, 403\r\n        auth_scheme, auth_token = auth_header.split(None, 1)\r\n        auth_scheme = auth_scheme.lower()\r\n        if auth_scheme != \"bearer\":\r\n            return {\r\n                \"error_code\": 1001,\r\n                \"error_msg\": \"Invalid Authorization header format. Expected 'Bearer &lt;api-key&gt;' format.\"\r\n            }, 403\r\n        if auth_token:\r\n            # process your authorization logic here\r\n            pass\r\n\r\n        # Call the knowledge <a href=\"https:\/\/www.kdjingpai.com\/de\/retrieval\/\">retrieval<\/a> service\r\n        result = ExternalDatasetService.knowledge_retrieval(\r\n            args[\"retrieval_setting\"], args[\"query\"], args[\"knowledge_id\"]\r\n        )\r\n        return result, 200<\/code><\/pre>\n<p><code>knowledge_service.py<\/code><\/p>\n<pre><code>import boto3\r\n\r\nclass ExternalDatasetService:\r\n    @staticmethod\r\n    def knowledge_retrieval(retrieval_setting: dict, query: str, knowledge_id: str):\r\n        # get bedrock client\r\n        client = boto3.client(\r\n            \"bedrock-agent-runtime\",\r\n            aws_secret_access_key=\"AWS_SECRET_ACCESS_KEY\",\r\n            aws_access_key_id=\"AWS_ACCESS_KEY_ID\",\r\n            # example: us-east-1\r\n            region_name=\"AWS_REGION_NAME\",\r\n        )\r\n        # fetch external knowledge retrieval\r\n        response = client.retrieve(\r\n            knowledgeBaseId=knowledge_id,\r\n            retrievalConfiguration={\r\n                \"vectorSearchConfiguration\": {\"numberOfResults\": retrieval_setting.get(\"top_k\"), \"overrideSearchType\": \"HYBRID\"}\r\n            },\r\n            retrievalQuery={\"text\": query},\r\n        )\r\n        # parse response\r\n        results = []\r\n        if response.get(\"ResponseMetadata\") and response.get(\"ResponseMetadata\").get(\"HTTPStatusCode\") == 200:\r\n            if response.get(\"retrievalResults\"):\r\n                retrieval_results = response.get(\"retrievalResults\")\r\n                for retrieval_result in retrieval_results:\r\n                    # filter out results with score less than threshold\r\n                    if retrieval_result.get(\"score\") &lt; retrieval_setting.get(\"score_threshold\", .0):\r\n                        <a href=\"https:\/\/www.kdjingpai.com\/de\/continue\/\">continue<\/a>\r\n                    result = {\r\n                        \"metadata\": retrieval_result.get(\"metadata\"),\r\n                        \"score\": retrieval_result.get(\"score\"),\r\n                        \"title\": retrieval_result.get(\"metadata\").get(\"x-amz-bedrock-kb-source-uri\"),\r\n                        \"content\": retrieval_result.get(\"content\").get(\"text\"),\r\n                    }\r\n                    results.append(result)\r\n        return {\r\n            \"records\": results\r\n        }<\/code><\/pre>\n<p>\u5728\u6b64\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6784\u5efa API \u63a5\u53e3\u5730\u5740\u4ee5\u53ca\u7528\u4e8e\u9274\u6743\u7684 API Key \u5e76\u7528\u4e8e\u540e\u7eed\u7684\u8fde\u63a5\u3002<\/p>\n<p><strong>3. \u83b7\u53d6 AWS Bedrock Knowledge Base ID<\/strong><\/p>\n<p>\u767b\u5f55 AWS Bedrock Knowledge \u540e\u53f0\uff0c\u83b7\u53d6\u5df2\u521b\u5efa Knowledge Base \u7684 ID\u3002\u6b64\u53c2\u6570\u5c06\u4f1a\u5728\u540e\u7eed\u6b65\u9aa4\u7528\u4e8e\u4e0e Dify \u5e73\u53f0\u7684\u8fde\u63a5\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28976\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/6d2a5ccc0cc2d23.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" width=\"1200\" height=\"700\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/6d2a5ccc0cc2d23.jpg 1200w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/6d2a5ccc0cc2d23-768x448.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/6d2a5ccc0cc2d23-18x12.jpg 18w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<picture>\u83b7\u53d6 AWS Bedrock Knowledge Base ID<\/picture>\n<p><strong>4. \u5173\u8054\u5916\u90e8\u77e5\u8bc6 API<\/strong><\/p>\n<p>\u524d\u5f80 Dify \u5e73\u53f0\u4e2d\u7684 <strong>\u201c\u77e5\u8bc6\u5e93\u201d<\/strong> \u9875\uff0c\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684 <strong>\u201c\u5916\u90e8\u77e5\u8bc6\u5e93 API\u201d<\/strong>\uff0c\u8f7b\u70b9 <strong>\u201c\u6dfb\u52a0\u5916\u90e8\u77e5\u8bc6\u5e93 API\u201d<\/strong>\u3002<\/p>\n<p>\u6309\u7167\u9875\u9762\u63d0\u793a\uff0c\u4f9d\u6b21\u586b\u5199\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<ul>\n<li>\u77e5\u8bc6\u5e93\u7684\u540d\u79f0\uff0c\u5141\u8bb8\u81ea\u5b9a\u4e49\u540d\u79f0\uff0c\u7528\u4e8e\u533a\u5206 Dify \u5e73\u53f0\u5185\u6240\u8fde\u63a5\u7684\u4e0d\u540c\u5916\u90e8\u77e5\u8bc6 API\uff1b<\/li>\n<li>API \u63a5\u53e3\u5730\u5740\uff0c\u5916\u90e8\u77e5\u8bc6\u5e93\u7684\u8fde\u63a5\u5730\u5740\uff0c\u53ef\u5728\u7b2c\u4e8c\u6b65\u4e2d\u81ea\u5b9a\u4e49\u3002\u793a\u4f8b <code>api-endpoint\/retrieval<\/code>\uff1b<\/li>\n<li>API Key\uff0c\u5916\u90e8\u77e5\u8bc6\u5e93\u8fde\u63a5\u5bc6\u94a5\uff0c\u53ef\u5728\u7b2c\u4e8c\u6b65\u4e2d\u81ea\u5b9a\u4e49\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28977\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/0af0c9c78446ffe.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" width=\"1200\" height=\"633\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/0af0c9c78446ffe.jpg 1200w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/0af0c9c78446ffe-768x405.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/0af0c9c78446ffe-18x9.jpg 18w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><br \/>\n<strong>5. \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93<\/strong><\/p>\n<p>\u524d\u5f80 <strong>\u201c\u77e5\u8bc6\u5e93\u201d<\/strong> \u9875\uff0c\u70b9\u51fb\u6dfb\u52a0\u77e5\u8bc6\u5e93\u5361\u7247\u4e0b\u65b9\u7684 <strong>\u201c\u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u201d<\/strong> \u8df3\u8f6c\u81f3\u53c2\u6570\u914d\u7f6e\u9875\u9762\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28978\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/a7dd356d9db7956.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" width=\"1200\" height=\"447\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/a7dd356d9db7956.jpg 1200w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/a7dd356d9db7956-768x286.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/a7dd356d9db7956-18x7.jpg 18w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>\u586b\u5199\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<ul>\n<li><strong>\u77e5\u8bc6\u5e93\u540d\u79f0\u4e0e\u63cf\u8ff0<\/strong><\/li>\n<li><strong>\u5916\u90e8\u77e5\u8bc6\u5e93 API<\/strong>\u9009\u62e9\u5728\u7b2c\u56db\u6b65\u4e2d\u5173\u8054\u7684\u5916\u90e8\u77e5\u8bc6\u5e93 API<\/li>\n<li><strong>\u5916\u90e8\u77e5\u8bc6\u5e93 ID<\/strong>\u586b\u5199\u5728\u7b2c\u4e09\u6b65\u4e2d\u83b7\u53d6\u7684 AWS Bedrock knowledge base ID<\/li>\n<li><strong>\u8c03\u6574\u53ec\u56de\u8bbe\u7f6e<\/strong>Top K\uff1a\u7528\u6237\u53d1\u8d77\u63d0\u95ee\u65f6\uff0c\u5c06\u8bf7\u6c42\u5916\u90e8\u77e5\u8bc6 API \u83b7\u53d6\u76f8\u5173\u6027\u8f83\u9ad8\u7684\u5185\u5bb9\u5206\u6bb5\u3002\u8be5\u53c2\u6570\u7528\u4e8e\u7b5b\u9009\u4e0e\u7528\u6237\u95ee\u9898\u76f8\u4f3c\u5ea6\u8f83\u9ad8\u7684\u6587\u672c\u7247\u6bb5\u3002\u9ed8\u8ba4\u503c\u4e3a 3\uff0c\u6570\u503c\u8d8a\u9ad8\uff0c\u53ec\u56de\u5b58\u5728\u76f8\u5173\u6027\u7684\u6587\u672c\u5206\u6bb5\u4e5f\u5c31\u8d8a\u591a\u3002\n<p>Score \u9608\u503c\uff1a\u6587\u672c\u7247\u6bb5\u7b5b\u9009\u7684\u76f8\u4f3c\u5ea6\u9608\u503c\uff0c\u53ea\u53ec\u56de\u8d85\u8fc7\u8bbe\u7f6e\u5206\u6570\u7684\u6587\u672c\u7247\u6bb5\uff0c\u9ed8\u8ba4\u503c\u4e3a 0.5\u3002\u6570\u503c\u8d8a\u9ad8\u8bf4\u660e\u5bf9\u4e8e\u6587\u672c\u4e0e\u95ee\u9898\u8981\u6c42\u7684\u76f8\u4f3c\u5ea6\u8d8a\u9ad8\uff0c\u9884\u671f\u88ab\u53ec\u56de\u7684\u6587\u672c\u6570\u91cf\u4e5f\u8d8a\u5c11\uff0c\u7ed3\u679c\u4e5f\u4f1a\u76f8\u5bf9\u800c\u8a00\u66f4\u52a0\u7cbe\u51c6\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28979\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/dcf9d8f5f8f785c.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" width=\"1200\" height=\"656\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/dcf9d8f5f8f785c.jpg 1200w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/dcf9d8f5f8f785c-768x420.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/dcf9d8f5f8f785c-18x10.jpg 18w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>\u8bbe\u7f6e\u5b8c\u6210\u540e\u5373\u53ef\u5efa\u7acb\u4e0e\u5916\u90e8\u77e5\u8bc6\u5e93 API \u7684\u8fde\u63a5\u3002<\/p>\n<p><strong>6. \u6d4b\u8bd5\u5916\u90e8\u77e5\u8bc6\u5e93\u8fde\u63a5\u4e0e\u53ec\u56de<\/strong><\/p>\n<p>\u5efa\u7acb\u4e0e\u5916\u90e8\u77e5\u8bc6\u5e93\u7684\u8fde\u63a5\u540e\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5728 <strong>\u201c\u53ec\u56de\u6d4b\u8bd5\u201d<\/strong> \u4e2d\u6a21\u62df\u53ef\u80fd\u7684\u95ee\u9898\u5173\u952e\u8bcd\uff0c\u9884\u89c8\u4ece AWS Bedrock Knowledge Base \u53ec\u56de\u7684\u6587\u672c\u5206\u6bb5\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28980\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/4b620525038e6d2.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" width=\"1200\" height=\"730\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/4b620525038e6d2.jpg 1200w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/4b620525038e6d2-768x467.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/4b620525038e6d2-18x12.jpg 18w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<picture>\u6d4b\u8bd5\u5916\u90e8\u77e5\u8bc6\u5e93\u7684\u8fde\u63a5\u4e0e\u53ec\u56de<\/picture>\n<p>\u82e5\u5bf9\u4e8e\u53ec\u56de\u7ed3\u679c\u4e0d\u6ee1\u610f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4fee\u6539\u53ec\u56de\u53c2\u6570\u6216\u81ea\u884c\u8c03\u6574 AWS Bedrock Knowledge Base \u7684\u68c0\u7d22\u8bbe\u7f6e\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28981\" title=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/cbe6357fed4475f.jpg\" alt=\"Dify \u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u6559\u7a0b-1\" width=\"1200\" height=\"695\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/cbe6357fed4475f.jpg 1200w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/cbe6357fed4475f-768x445.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/03\/cbe6357fed4475f-18x10.jpg 18w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<picture>\u8c03\u6574 AWS Bedrock Knowledge Base \u6587\u672c\u5904\u7406\u53c2\u6570<\/picture>\n<p>&nbsp;<\/p>\n<h3>\u5e38\u89c1\u95ee\u9898<\/h3>\n<p><strong>\u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93 API \u65f6\u51fa\u73b0\u9519\u8bef\u600e\u4e48\u529e\uff1f<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u9519\u8bef\u7801\u53ca\u5bf9\u5e94\u7684\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u9519\u8bef\u7801<\/th>\n<th>\u9519\u8bef\u63d0\u793a<\/th>\n<th>\u89e3\u51b3\u529e\u6cd5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1001<\/td>\n<td>\u65e0\u6548\u7684 Authorization header \u683c\u5f0f<\/td>\n<td>\u68c0\u67e5\u8bf7\u6c42\u7684 Authorization header \u683c\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>1002<\/td>\n<td>\u9a8c\u8bc1\u5f02\u5e38<\/td>\n<td>\u68c0\u67e5 API Key \u662f\u5426\u6b63\u786e<\/td>\n<\/tr>\n<tr>\n<td>2001<\/td>\n<td>\u77e5\u8bc6\u5e93\u4e0d\u5b58\u5728<\/td>\n<td>\u68c0\u67e5\u5916\u90e8\u77e5\u8bc6\u5e93<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h2>\u5916\u90e8\u77e5\u8bc6\u5e93 API \u89c4\u8303<\/h2>\n<h3>\u7aef\u70b9<\/h3>\n<pre><code>POST &lt;your-endpoint&gt;\/retrieval\r\n<\/code><\/pre>\n<h3>\u8bf7\u6c42\u5934<\/h3>\n<p>\u8be5 API \u7528\u4e8e\u8fde\u63a5\u56e2\u961f\u5185\u72ec\u7acb\u7ef4\u62a4\u7684\u77e5\u8bc6\u5e93\u3002\u66f4\u591a\u64cd\u4f5c\u6307\u5f15\uff0c\u8bf7\u53c2\u8003\u8fde\u63a5\u5916\u90e8\u77e5\u8bc6\u5e93\u3002<\/p>\n<p>\u53ef\u4ee5\u5728 HTTP \u8bf7\u6c42\u5934\u7684\u00a0<code>Authorization<\/code>\u00a0\u5b57\u6bb5\u4e2d\u4f7f\u7528\u00a0<code>API-Key<\/code>\u00a0\u6765\u9a8c\u8bc1\u6743\u9650\u3002\u8eab\u4efd\u9a8c\u8bc1\u903b\u8f91\u7531\u4f60\u5728\u68c0\u7d22 API \u4e2d\u5b9a\u4e49\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>Authorization: Bearer {API_KEY}\r\n<\/code><\/pre>\n<h3>\u8bf7\u6c42\u4f53<\/h3>\n<p>\u8bf7\u6c42\u63a5\u53d7\u4ee5\u4e0b JSON \u683c\u5f0f\u7684\u6570\u636e\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u5fc5\u586b<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<th>\u793a\u4f8b\u503c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>knowledge_id<\/td>\n<td>\u662f<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<td>\u77e5\u8bc6\u5e93\u552f\u4e00 ID<\/td>\n<td>AAA-BBB-CCC<\/td>\n<\/tr>\n<tr>\n<td>query<\/td>\n<td>\u662f<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<td>\u7528\u6237\u7684\u67e5\u8be2<\/td>\n<td>Dify \u662f\u4ec0\u4e48\uff1f<\/td>\n<\/tr>\n<tr>\n<td>retrieval_setting<\/td>\n<td>\u662f<\/td>\n<td>\u5bf9\u8c61<\/td>\n<td>\u77e5\u8bc6\u68c0\u7d22\u53c2\u6570<\/td>\n<td>\u89c1\u4e0b\u6587<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>retrieval_setting<\/code>\u00a0\u5c5e\u6027\u5305\u542b\u4ee5\u4e0b\u952e\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u5fc5\u586b<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<th>\u793a\u4f8b\u503c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>top_k<\/td>\n<td>\u662f<\/td>\n<td>\u6574\u6570<\/td>\n<td>\u68c0\u7d22\u7ed3\u679c\u7684\u6700\u5927\u6570\u91cf<\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<td>score_threshold<\/td>\n<td>\u662f<\/td>\n<td>\u6d6e\u70b9\u6570<\/td>\n<td>\u7ed3\u679c\u4e0e\u67e5\u8be2\u76f8\u5173\u6027\u7684\u5206\u6570\u9650\u5236\uff0c\u8303\u56f4\uff1a0~1<\/td>\n<td>0.5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u8bf7\u6c42\u793a\u4f8b<\/h3>\n<pre><code>POST &lt;your-endpoint&gt;\/retrieval HTTP\/1.1\r\nContent-Type: application\/json\r\nAuthorization: Bearer your-api-key\r\n{\r\n\"knowledge_id\": \"your-knowledge-id\",\r\n\"query\": \"\u4f60\u7684\u95ee\u9898\",\r\n\"retrieval_setting\": {\r\n\"top_k\": 2,\r\n\"score_threshold\": 0.5\r\n}\r\n}\r\n<\/code><\/pre>\n<h3>\u54cd\u5e94\u4f53<\/h3>\n<p>\u5982\u679c\u64cd\u4f5c\u6210\u529f\uff0c\u670d\u52a1\u5c06\u8fd4\u56de HTTP 200 \u54cd\u5e94\uff0c\u5e76\u4ee5 JSON \u683c\u5f0f\u8fd4\u56de\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u5fc5\u586b<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<th>\u793a\u4f8b\u503c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>records<\/td>\n<td>\u662f<\/td>\n<td>\u5bf9\u8c61\u5217\u8868<\/td>\n<td>\u4ece\u77e5\u8bc6\u5e93\u67e5\u8be2\u7684\u8bb0\u5f55\u5217\u8868<\/td>\n<td>\u89c1\u4e0b\u6587<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>records<\/code>\u00a0\u5c5e\u6027\u662f\u4e00\u4e2a\u5bf9\u8c61\u5217\u8868\uff0c\u5305\u542b\u4ee5\u4e0b\u952e\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u5fc5\u586b<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<th>\u793a\u4f8b\u503c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>content<\/td>\n<td>\u662f<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<td>\u77e5\u8bc6\u5e93\u4e2d\u6587\u672c\u5757<\/td>\n<td>Dify\uff1aGenAI \u5e94\u7528\u5f00\u53d1\u5e73\u53f0<\/td>\n<\/tr>\n<tr>\n<td>score<\/td>\n<td>\u662f<\/td>\n<td>\u6d6e\u70b9\u6570<\/td>\n<td>\u7ed3\u679c\u4e0e\u67e5\u8be2\u7684\u76f8\u5173\u6027\u5206\u6570\uff0c\u8303\u56f4\uff1a0~1<\/td>\n<td>0.98<\/td>\n<\/tr>\n<tr>\n<td>title<\/td>\n<td>\u662f<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<td>\u6587\u6863\u6807\u9898<\/td>\n<td>Dify \u7b80\u4ecb<\/td>\n<\/tr>\n<tr>\n<td>metadata<\/td>\n<td>\u5426<\/td>\n<td>JSON<\/td>\n<td>\u6570\u636e\u6e90\u4e2d\u6587\u6863\u7684\u5143\u6570\u636e\u5c5e\u6027\u53ca\u5176\u503c<\/td>\n<td>\u89c1\u793a\u4f8b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u54cd\u5e94\u793a\u4f8b<\/h3>\n<pre><code>HTTP\/1.1 200\r\nContent-Type: application\/json\r\n{\r\n\"records\": [\r\n{\r\n\"metadata\": {\r\n\"path\": \"s3:\/\/dify\/knowledge.txt\",\r\n\"description\": \"dify \u77e5\u8bc6\u6587\u6863\"\r\n},\r\n\"score\": 0.98,\r\n\"title\": \"knowledge.txt\",\r\n\"content\": \"\u8fd9\u662f\u5916\u90e8\u77e5\u8bc6\u7684\u6587\u6863\u3002\"\r\n},\r\n{\r\n\"metadata\": {\r\n\"path\": \"s3:\/\/dify\/introduce.txt\",\r\n\"description\": \"dify \u4ecb\u7ecd\"\r\n},\r\n\"score\": 0.66,\r\n\"title\": \"introduce.txt\",\r\n\"content\": \"GenAI \u5e94\u7528\u7a0b\u5e8f\u7684\u521b\u65b0\u5f15\u64ce\"\r\n}\r\n]\r\n}\r\n<\/code><\/pre>\n<h3>\u9519\u8bef<\/h3>\n<p>\u5982\u679c\u64cd\u4f5c\u5931\u8d25\uff0c\u670d\u52a1\u5c06\u8fd4\u56de\u4ee5\u4e0b\u9519\u8bef\u4fe1\u606f\uff08JSON \u683c\u5f0f\uff09\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u5fc5\u586b<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<th>\u793a\u4f8b\u503c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>error_code<\/td>\n<td>\u662f<\/td>\n<td>\u6574\u6570<\/td>\n<td>\u9519\u8bef\u4ee3\u7801<\/td>\n<td>1001<\/td>\n<\/tr>\n<tr>\n<td>error_msg<\/td>\n<td>\u662f<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<td>API \u5f02\u5e38\u63cf\u8ff0<\/td>\n<td>\u65e0\u6548\u7684 Authorization \u5934\u683c\u5f0f\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>error_code<\/code>\u00a0\u5c5e\u6027\u7c7b\u578b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u4ee3\u7801<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1001<\/td>\n<td>\u65e0\u6548\u7684 Authorization \u5934\u683c\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>1002<\/td>\n<td>\u6388\u6743\u5931\u8d25<\/td>\n<\/tr>\n<tr>\n<td>2001<\/td>\n<td>\u77e5\u8bc6\u5e93\u4e0d\u5b58\u5728<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>HTTP \u72b6\u6001\u7801<\/h3>\n<ul>\n<li><strong>AccessDeniedException\uff1a<\/strong>\u00a0\u7f3a\u5c11\u8bbf\u95ee\u6743\u9650\u3002 (HTTP \u72b6\u6001\u7801\uff1a403)<\/li>\n<li><strong>InternalServerException\uff1a<\/strong>\u00a0\u5185\u90e8\u670d\u52a1\u5668\u9519\u8bef\u3002 (HTTP \u72b6\u6001\u7801\uff1a500)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4e86\u65b9\u4fbf\u533a\u5206\uff0c\u672c\u6587\u5c06 Dify \u5e73\u53f0\u4e4b\u5916\u7684\u77e5\u8bc6\u5e93\u7edf\u79f0\u4e3a\u201c\u5916\u90e8\u77e5\u8bc6\u5e93\u201d\u3002 \u529f\u80fd\u7b80\u4ecb Dify \u5185\u7f6e\u7684\u77e5\u8bc6\u5e93\u529f\u80fd\u548c\u6587\u672c\u68c0\u7d22\u673a\u5236\u53ef\u80fd\u65e0\u6cd5\u6ee1\u8db3\u90e8\u5206\u9ad8\u7ea7\u5f00\u53d1\u8005\u7684\u9700\u6c42\uff0c\u4ed6\u4eec\u53ef\u80fd\u9700\u8981\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u6587\u672c\u53ec\u56de\u7ed3\u679c\u3002 \u6709\u4e9b\u56e2\u961f\u4f1a\u9009\u62e9\u81ea\u7814 RAG \u7b97\u6cd5\u5e76\u72ec\u7acb\u7ef4\u62a4\u6587&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182],"tags":[],"class_list":["post-28966","post","type-post","status-publish","format-standard","hentry","category-shicao"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/28966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/comments?post=28966"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/28966\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/media?parent=28966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/categories?post=28966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/tags?post=28966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}