{"id":14939,"date":"2024-11-28T15:53:12","date_gmt":"2024-11-28T07:53:12","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=14939"},"modified":"2024-12-08T15:59:24","modified_gmt":"2024-12-08T07:59:24","slug":"aigongchengxueyuan21-2","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/pt\/aigongchengxueyuan21-2\/","title":{"rendered":"AI\u5de5\u7a0b\u5b66\u9662\uff1a2.10\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668"},"content":{"rendered":"<h2>\u7b80\u4ecb<\/h2>\n<p>\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\u662f<strong>\u589e\u5f3a\u68c0\u7d22\u751f\u6210\uff08RAG\uff09\u6846\u67b6<\/strong>\u7684\u4e00\u79cd\u9ad8\u7ea7\u5b9e\u73b0\u3002\u8be5\u65b9\u6cd5\u65e8\u5728\u901a\u8fc7\u5c06\u53ef\u80fd\u5206\u6563\u4e14\u8f83\u5c0f\u7684\u4e0a\u4e0b\u6587\u5408\u5e76\u6210\u66f4\u5927\u4e14\u66f4\u5168\u9762\u7684\u4e0a\u4e0b\u6587\uff0c\u4ece\u800c\u589e\u5f3a AI \u751f\u6210\u54cd\u5e94\u7684\u4e0a\u4e0b\u6587\u611f\u77e5\u80fd\u529b\u548c\u8fde\u8d2f\u6027\u3002<\/p>\n<p>https:\/\/github.com\/adithya-s-k\/AI-Engineering.academy\/tree\/main\/RAG\/05_Auto_Merging_RAG<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-14940\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/a6490712acaebb9.jpg\" alt=\"\" width=\"792\" height=\"1350\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/a6490712acaebb9.jpg 1232w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/a6490712acaebb9-176x300.jpg 176w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/a6490712acaebb9-601x1024.jpg 601w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/a6490712acaebb9-768x1309.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/a6490712acaebb9-901x1536.jpg 901w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/a6490712acaebb9-1201x2048.jpg 1201w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/a6490712acaebb9-7x12.jpg 7w\" sizes=\"auto, (max-width: 792px) 100vw, 792px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>\u80cc\u666f\u52a8\u673a<\/h3>\n<p>\u4f20\u7edf\u7684\u589e\u5f3a\u68c0\u7d22\u751f\u6210\u7cfb\u7edf\u901a\u5e38\u96be\u4ee5\u5728\u8f83\u5927\u7684\u4e0a\u4e0b\u6587\u4e2d\u4fdd\u6301\u8fde\u8d2f\u6027\uff0c\u6216\u8005\u5904\u7406\u8de8\u591a\u4e2a\u6587\u672c\u7247\u6bb5\u7684\u4fe1\u606f\u65f6\u8868\u73b0\u8f83\u5dee\u3002\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\u901a\u8fc7\u9012\u5f52\u5730\u5408\u5e76\u5f15\u7528\u8d85\u51fa\u7279\u5b9a\u9608\u503c\u7684\u7236\u8282\u70b9\u7684\u5b50\u8282\u70b9\u96c6\u5408\uff0c\u89e3\u51b3\u4e86\u8fd9\u4e00\u9650\u5236\uff0c\u4ece\u800c\u5728\u68c0\u7d22\u548c\u751f\u6210\u8fc7\u7a0b\u4e2d\u63d0\u4f9b\u66f4\u5168\u9762\u3001\u66f4\u5177\u8fde\u8d2f\u6027\u7684\u4e0a\u4e0b\u6587\u3002<\/p>\n<h3>\u65b9\u6cd5\u8be6\u60c5<\/h3>\n<h4>\u6587\u6863\u9884\u5904\u7406\u4e0e\u5c42\u7ea7\u521b\u5efa<\/h4>\n<ol>\n<li><strong>\u6587\u6863\u52a0\u8f7d<\/strong>\uff1a\u52a0\u8f7d\u5e76\u5904\u7406\u8f93\u5165\u6587\u6863\uff08\u4f8b\u5982 PDF \u6587\u4ef6\uff09\u3002<\/li>\n<li><strong>\u5c42\u7ea7\u89e3\u6790<\/strong>\uff1a\u4f7f\u7528\u00a0<code>HierarchicalNodeParser<\/code>\u00a0\u4ece\u6587\u6863\u4e2d\u521b\u5efa\u8282\u70b9\u5c42\u7ea7\uff1a\n<ul>\n<li>\u7b2c\u4e00\u7ea7\uff1a\u5757\u5927\u5c0f 2048<\/li>\n<li>\u7b2c\u4e8c\u7ea7\uff1a\u5757\u5927\u5c0f 512<\/li>\n<li>\u7b2c\u4e09\u7ea7\uff1a\u5757\u5927\u5c0f 128<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8282\u70b9\u5b58\u50a8<\/strong>\uff1a\u5c06\u6240\u6709\u8282\u70b9\u5b58\u50a8\u5230\u6587\u6863\u5b58\u50a8\u4e2d\uff0c\u53f6\u5b50\u8282\u70b9\u4e5f\u88ab\u7d22\u5f15\u5230\u5411\u91cf\u5b58\u50a8\u4e2d\u3002<\/li>\n<\/ol>\n<h4>\u589e\u5f3a\u68c0\u7d22\u751f\u6210\u5de5\u4f5c\u6d41\u7a0b<\/h4>\n<ol>\n<li><strong>\u67e5\u8be2\u9884\u5904\u7406<\/strong>\uff1a\u4f7f\u7528\u4e0e\u6587\u6863\u5757\u76f8\u540c\u7684\u5d4c\u5165\u6a21\u578b\u5904\u7406\u7528\u6237\u67e5\u8be2\u3002<\/li>\n<li><strong>\u57fa\u7840\u68c0\u7d22<\/strong>\uff1a\u57fa\u7840\u68c0\u7d22\u5668\u8fdb\u884c\u521d\u6b65\u76f8\u4f3c\u6027\u641c\u7d22\uff0c\u4ee5\u627e\u5230\u76f8\u5173\u7684\u53f6\u5b50\u8282\u70b9\u3002<\/li>\n<li><strong>\u81ea\u52a8\u5408\u5e76<\/strong>\uff1a<code>AutoMergingRetriever<\/code>\u00a0\u4f1a\u5206\u6790\u68c0\u7d22\u5230\u7684\u53f6\u5b50\u8282\u70b9\u96c6\u5408\uff0c\u5e76\u9012\u5f52\u5730\u201c\u5408\u5e76\u201d\u8d85\u51fa\u7ed9\u5b9a\u9608\u503c\u7684\u5f15\u7528\u7236\u8282\u70b9\u7684\u53f6\u5b50\u8282\u70b9\u5b50\u96c6\u3002<\/li>\n<li><strong>\u4e0a\u4e0b\u6587\u6269\u5c55<\/strong>\uff1a\u5408\u5e76\u540e\u7684\u8282\u70b9\u5f62\u6210\u4e00\u4e2a\u6269\u5c55\u7684\u4e0a\u4e0b\u6587\uff0c\u5e76\u4e0e\u539f\u59cb\u67e5\u8be2\u5408\u5e76\u3002<\/li>\n<li><strong>\u751f\u6210\u54cd\u5e94<\/strong>\uff1a\u5c06\u6269\u5c55\u4e0a\u4e0b\u6587\u548c\u67e5\u8be2\u8f93\u5165\u5230\u5927\u8bed\u8a00\u6a21\u578b\uff08LLM\uff09\u4e2d\u751f\u6210\u54cd\u5e94\u3002<\/li>\n<\/ol>\n<h3>\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\u7684\u5173\u952e\u7279\u6027<\/h3>\n<ul>\n<li><strong>\u5c42\u7ea7\u5316\u6587\u6863\u8868\u793a<\/strong>\uff1a\u7ef4\u62a4\u6587\u6863\u5757\u7684\u591a\u7ea7\u5c42\u7ea7\u7ed3\u6784\u3002<\/li>\n<li><strong>\u9ad8\u6548\u57fa\u7840\u68c0\u7d22<\/strong>\uff1a\u5229\u7528\u5411\u91cf\u76f8\u4f3c\u6027\u641c\u7d22\u5b9e\u73b0\u5feb\u901f\u3001\u51c6\u786e\u7684\u521d\u6b65\u4fe1\u606f\u68c0\u7d22\u3002<\/li>\n<li><strong>\u52a8\u6001\u4e0a\u4e0b\u6587\u6269\u5c55<\/strong>\uff1a\u81ea\u52a8\u5c06\u76f8\u5173\u6587\u672c\u5757\u5408\u5e76\u4e3a\u66f4\u5927\u4e14\u66f4\u5177\u8fde\u8d2f\u6027\u7684\u4e0a\u4e0b\u6587\u3002<\/li>\n<li><strong>\u7075\u6d3b\u7684\u5b9e\u73b0\u65b9\u5f0f<\/strong>\uff1a\u53ef\u7528\u4e8e\u591a\u79cd\u6587\u6863\u7c7b\u578b\u548c\u8bed\u8a00\u6a21\u578b\u3002<\/li>\n<\/ul>\n<h3>\u672c\u65b9\u6cd5\u7684\u4f18\u52bf<\/h3>\n<ol>\n<li><strong>\u589e\u5f3a\u4e0a\u4e0b\u6587\u8fde\u8d2f\u6027<\/strong>\uff1a\u901a\u8fc7\u5408\u5e76\u76f8\u5173\u7684\u6587\u672c\u5757\uff0c\u4e3a\u5927\u8bed\u8a00\u6a21\u578b\u63d0\u4f9b\u66f4\u5177\u8fde\u8d2f\u6027\u4e14\u5b8c\u6574\u7684\u4e0a\u4e0b\u6587\u3002<\/li>\n<li><strong>\u7075\u6d3b\u7684\u68c0\u7d22\u9002\u5e94\u6027<\/strong>\uff1a\u5408\u5e76\u8fc7\u7a0b\u4f1a\u6839\u636e\u67e5\u8be2\u548c\u68c0\u7d22\u7ed3\u679c\u81ea\u52a8\u8c03\u6574\uff0c\u63d0\u4f9b\u4e0e\u4e0a\u4e0b\u6587\u76f8\u5173\u7684\u4fe1\u606f\u3002<\/li>\n<li><strong>\u9ad8\u6548\u5b58\u50a8\u7ed3\u6784<\/strong>\uff1a\u5728\u7ef4\u6301\u5c42\u7ea7\u7ed3\u6784\u7684\u540c\u65f6\uff0c\u5feb\u901f\u5b9e\u73b0\u53f6\u5b50\u8282\u70b9\u7684\u57fa\u7840\u68c0\u7d22\u3002<\/li>\n<li><strong>\u63d0\u5347\u54cd\u5e94\u8d28\u91cf\u7684\u53ef\u80fd\u6027<\/strong>\uff1a\u6269\u5c55\u7684\u4e0a\u4e0b\u6587\u6709\u671b\u5e26\u6765\u66f4\u51c6\u786e\u3001\u66f4\u8be6\u7ec6\u7684\u8bed\u8a00\u6a21\u578b\u54cd\u5e94\u3002<\/li>\n<\/ol>\n<h3>\u5b9e\u9a8c\u7ed3\u679c<\/h3>\n<p>\u5b9e\u9a8c\u7ed3\u679c\u663e\u793a\uff0c\u5c06\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\u4e0e\u57fa\u7840\u68c0\u7d22\u5668\u8fdb\u884c\u5bf9\u6bd4\uff1a<\/p>\n<ul>\n<li>\u5728\u6b63\u786e\u6027\u3001\u76f8\u5173\u6027\u3001\u51c6\u786e\u6027\u548c\u8bed\u4e49\u76f8\u4f3c\u6027\u6307\u6807\u4e0a\u8868\u73b0\u76f8\u8fd1\u3002<\/li>\n<li>\u5728\u914d\u5bf9\u6bd4\u8f83\u4e2d\uff0c\u6709 52.5% \u7684\u7528\u6237\u66f4\u504f\u597d\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\u7684\u54cd\u5e94\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u7ed3\u679c\u8868\u660e\uff0c\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\u7684\u8868\u73b0\u4e0e\u4f20\u7edf\u68c0\u7d22\u65b9\u6cd5\u76f8\u5f53\uff0c\u751a\u81f3\u7565\u6709\u4f18\u52bf\u3002<\/p>\n<h3>\u7ed3\u8bba<\/h3>\n<p>\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\u63d0\u4f9b\u4e86\u4e00\u79cd\u5148\u8fdb\u7684\u65b9\u6cd5\uff0c\u53ef\u6539\u5584 <a href=\"https:\/\/www.kdjingpai.com\/pt\/rag\/\">RAG<\/a> \u7cfb\u7edf\u4e2d\u7684\u68c0\u7d22\u8fc7\u7a0b\u3002\u901a\u8fc7\u52a8\u6001\u5408\u5e76\u76f8\u5173\u6587\u672c\u5757\u4e3a\u66f4\u5927\u3001\u66f4\u5177\u8fde\u8d2f\u6027\u7684\u4e0a\u4e0b\u6587\uff0c\u5b83\u89e3\u51b3\u4e86\u4f20\u7edf\u57fa\u4e8e\u6587\u672c\u5757\u7684\u68c0\u7d22\u65b9\u6cd5\u7684\u67d0\u4e9b\u5c40\u9650\u6027\u3002\u867d\u7136\u521d\u6b65\u7ed3\u679c\u663e\u793a\u51fa\u79ef\u6781\u524d\u666f\uff0c\u4f46\u8fdb\u4e00\u6b65\u7814\u7a76\u548c\u4f18\u5316\u6709\u671b\u663e\u8457\u63d0\u5347\u54cd\u5e94\u8d28\u91cf\u548c\u8fde\u8d2f\u6027\u3002<\/p>\n<h3>\u524d\u63d0\u6761\u4ef6<\/h3>\n<p>\u8981\u5b9e\u73b0\u6b64\u7cfb\u7edf\uff0c\u60a8\u9700\u8981\uff1a<\/p>\n<ol>\n<li>\u4e00\u4e2a\u80fd\u591f\u751f\u6210\u6587\u672c\u7684\u5927\u8bed\u8a00\u6a21\u578b\uff08\u4f8b\u5982 GPT-3.5-turbo\u3001GPT-4\uff09\u3002<\/li>\n<li>\u4e00\u4e2a\u5d4c\u5165\u6a21\u578b\uff0c\u7528\u4e8e\u5c06\u6587\u672c\u5757\u548c\u67e5\u8be2\u8f6c\u6362\u4e3a\u5411\u91cf\u8868\u793a\u3002<\/li>\n<li>\u7528\u4e8e\u9ad8\u6548\u76f8\u4f3c\u6027\u641c\u7d22\u7684\u5411\u91cf\u6570\u636e\u5e93\uff08\u4f8b\u5982 FAISS\uff09\u3002<\/li>\n<li>\u4e00\u4e2a\u6587\u6863\u5b58\u50a8\uff0c\u7528\u4e8e\u5b58\u50a8\u5b8c\u6574\u7684\u8282\u70b9\u5c42\u7ea7\u7ed3\u6784\u3002<\/li>\n<li>\u63d0\u4f9b\u00a0<code>LlamaIndex<\/code>\u00a0\u5e93\uff0c\u5b83\u5305\u542b\u00a0<code>HierarchicalNodeParser<\/code>\u00a0\u548c\u00a0<code>AutoMergingRetriever<\/code>\u00a0\u5b9e\u73b0\u3002<\/li>\n<li>\u8db3\u591f\u7684\u8ba1\u7b97\u8d44\u6e90\uff0c\u7528\u4e8e\u5904\u7406\u548c\u5b58\u50a8\u5927\u91cf\u6587\u6863\u96c6\u5408\u3002<\/li>\n<li>\u719f\u6089 Python \u7f16\u7a0b\u8bed\u8a00\uff0c\u7528\u4e8e\u5b9e\u73b0\u548c\u6d4b\u8bd5\u3002<\/li>\n<\/ol>\n<h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<pre><code>from llama_index.core import StorageContext, VectorStoreIndex\r\nfrom llama_index.core.node_parser import HierarchicalNodeParser\r\nfrom llama_index.core.retrievers import AutoMergingRetriever\r\n# \u5c06\u6587\u6863\u89e3\u6790\u4e3a\u8282\u70b9\u5c42\u7ea7\r\nnode_parser = HierarchicalNodeParser.from_defaults()\r\nnodes = node_parser.get_nodes_from_documents(docs)\r\n# \u8bbe\u7f6e\u5b58\u50a8\u4e0a\u4e0b\u6587\r\nstorage_context = StorageContext.from_defaults()\r\nstorage_context.docstore.add_documents(nodes)\r\n# \u521b\u5efa\u57fa\u7840\u7d22\u5f15\u548c\u68c0\u7d22\u5668\r\nleaf_nodes = get_leaf_nodes(nodes)\r\nbase_index = VectorStoreIndex(leaf_nodes, storage_context=storage_context)\r\nbase_retriever = base_index.as_retriever(similarity_top_k=6)\r\n# \u521b\u5efa\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\r\nretriever = AutoMergingRetriever(base_retriever, storage_context, verbose=True)\r\n# \u5728\u67e5\u8be2\u5f15\u64ce\u4e2d\u4f7f\u7528\u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\r\nquery_engine = RetrieverQueryEngine.from_args(retriever)\r\nresponse = query_engine.query(query_str)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb \u81ea\u52a8\u5408\u5e76\u68c0\u7d22\u5668\u662f\u589e\u5f3a\u68c0\u7d22\u751f\u6210\uff08RAG\uff09\u6846\u67b6\u7684\u4e00\u79cd\u9ad8\u7ea7\u5b9e\u73b0\u3002\u8be5\u65b9\u6cd5\u65e8\u5728\u901a\u8fc7\u5c06\u53ef\u80fd\u5206\u6563\u4e14\u8f83\u5c0f\u7684\u4e0a\u4e0b\u6587\u5408\u5e76\u6210\u66f4\u5927\u4e14\u66f4\u5168\u9762\u7684\u4e0a\u4e0b\u6587\uff0c\u4ece\u800c\u589e\u5f3a AI \u751f\u6210\u54cd\u5e94\u7684\u4e0a\u4e0b\u6587\u611f\u77e5\u80fd\u529b\u548c\u8fde\u8d2f\u6027\u3002 https:\/\/github.com\/adithya-s-&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-14939","post","type-post","status-publish","format-standard","hentry","category-knowledge"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/14939","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=14939"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/14939\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/media?parent=14939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/categories?post=14939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/tags?post=14939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}