{"id":21668,"date":"2025-02-21T12:39:41","date_gmt":"2025-02-21T04:39:41","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=21668"},"modified":"2025-07-14T10:23:43","modified_gmt":"2025-07-14T02:23:43","slug":"dsrag","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/de\/dsrag\/","title":{"rendered":"dsRAG\uff1a\u7528\u4e8e\u5904\u7406\u975e\u7ed3\u6784\u5316\u6570\u636e\u548c\u590d\u6742\u67e5\u8be2\u7684\u68c0\u7d22\u5f15\u64ce"},"content":{"rendered":"<p>dsRAG\u662f\u4e00\u6b3e\u9ad8\u6027\u80fd\u68c0\u7d22\u5f15\u64ce\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u975e\u7ed3\u6784\u5316\u6570\u636e\u7684\u590d\u6742\u67e5\u8be2\u3002\u5b83\u5728\u5904\u7406\u5bc6\u96c6\u6587\u672c\uff08\u5982\u8d22\u52a1\u62a5\u544a\u3001\u6cd5\u5f8b\u6587\u4ef6\u548c\u5b66\u672f\u8bba\u6587\uff09\u4e2d\u7684\u6311\u6218\u6027\u67e5\u8be2\u65f6\u8868\u73b0\u5c24\u4e3a\u51fa\u8272\u3002dsRAG\u91c7\u7528\u4e86\u4e09\u79cd\u5173\u952e\u65b9\u6cd5\u6765\u63d0\u9ad8\u6027\u80fd\uff1a\u8bed\u4e49\u5206\u6bb5\u3001\u4e0a\u4e0b\u6587\u81ea\u52a8\u751f\u6210\u548c\u76f8\u5173\u6bb5\u63d0\u53d6\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4f7fdsRAG\u5728\u590d\u6742\u7684\u5f00\u5377\u95ee\u7b54\u4efb\u52a1\u4e2d\u53d6\u5f97\u4e86\u663e\u8457\u9ad8\u4e8e\u4f20\u7edfRAG\u57fa\u7ebf\u7684\u51c6\u786e\u6027\u3002\u6b64\u5916\uff0cdsRAG\u652f\u6301\u591a\u79cd\u914d\u7f6e\u9009\u9879\uff0c\u53ef\u6839\u636e\u7528\u6237\u9700\u6c42\u8fdb\u884c\u81ea\u5b9a\u4e49\u3002\u5176\u6a21\u5757\u5316\u8bbe\u8ba1\u5141\u8bb8\u7528\u6237\u8f7b\u677e\u96c6\u6210\u4e0d\u540c\u7684\u7ec4\u4ef6\uff0c\u5982\u5411\u91cf\u6570\u636e\u5e93\u3001\u5d4c\u5165\u6a21\u578b\u548c\u91cd\u6392\u5e8f\u5668\uff0c\u4ece\u800c\u5b9e\u73b0\u6700\u4f73\u7684\u68c0\u7d22\u6548\u679c\u3002<\/p>\n<p>\u4e0e\u4f20\u7edf\u7684RAG\uff08Retrieval-Augmented Generation\uff09\u57fa\u7ebf\u76f8\u6bd4\uff0cdsRAG\u5728\u590d\u6742\u7684\u5f00\u653e\u4e66\u672c\u95ee\u7b54\u4efb\u52a1\u4e2d\u5b9e\u73b0\u4e86\u663e\u8457\u66f4\u9ad8\u7684\u51c6\u786e\u7387\u3002\u4f8b\u5982\uff0c\u5728FinanceBench\u57fa\u51c6\u6d4b\u8bd5\u4e2d\uff0cdsRAG\u7684\u51c6\u786e\u7387\u9ad8\u8fbe96.6%\uff0c\u800c\u4f20\u7edfRAG\u57fa\u7ebf\u4ec5\u4e3a32%\u3002dsRAG\u901a\u8fc7\u8bed\u4e49\u5206\u6bb5\u3001\u81ea\u52a8\u4e0a\u4e0b\u6587\u548c\u76f8\u5173\u6bb5\u63d0\u53d6\u7b49\u5173\u952e\u65b9\u6cd5\uff0c\u663e\u8457\u63d0\u5347\u4e86\u68c0\u7d22\u6027\u80fd\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-21669\" title=\"dsRAG\uff1a\u7528\u4e8e\u5904\u7406\u975e\u7ed3\u6784\u5316\u6570\u636e\u548c\u590d\u6742\u67e5\u8be2\u7684\u9ad8\u6027\u80fd\u68c0\u7d22\u5f15\u64ce-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/6a95239f7fc6b08.jpg\" alt=\"dsRAG\uff1a\u7528\u4e8e\u5904\u7406\u975e\u7ed3\u6784\u5316\u6570\u636e\u548c\u590d\u6742\u67e5\u8be2\u7684\u9ad8\u6027\u80fd\u68c0\u7d22\u5f15\u64ce-1\" width=\"906\" height=\"453\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/6a95239f7fc6b08.jpg 1200w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/6a95239f7fc6b08-768x384.jpg 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li><strong>\u8bed\u4e49\u5206\u6bb5<\/strong>\uff1a\u5229\u7528LLM\u5c06\u6587\u6863\u5206\u6bb5\uff0c\u63d0\u9ad8\u68c0\u7d22\u51c6\u786e\u6027\u3002<\/li>\n<li><strong>\u4e0a\u4e0b\u6587\u81ea\u52a8\u751f\u6210<\/strong>\uff1a\u751f\u6210\u5305\u542b\u6587\u6863\u548c\u6bb5\u843d\u7ea7\u4e0a\u4e0b\u6587\u7684\u5757\u5934\uff0c\u63d0\u9ad8\u5d4c\u5165\u8d28\u91cf\u3002<\/li>\n<li><strong>\u76f8\u5173\u6bb5\u63d0\u53d6<\/strong>\uff1a\u5728\u67e5\u8be2\u65f6\u667a\u80fd\u7ec4\u5408\u76f8\u5173\u7684\u6587\u672c\u5757\uff0c\u751f\u6210\u66f4\u957f\u7684\u6bb5\u843d\u3002<\/li>\n<li><strong>\u591a\u79cd\u5411\u91cf\u6570\u636e\u5e93\u652f\u6301<\/strong>\uff1a\u5982BasicVectorDB\u3001WeaviateVectorDB\u3001ChromaDB\u7b49\u3002<\/li>\n<li><strong>\u591a\u79cd\u5d4c\u5165\u6a21\u578b\u652f\u6301<\/strong>\uff1a\u5982OpenAIEmbedding\u3001CohereEmbedding\u7b49\u3002<\/li>\n<li><strong>\u591a\u79cd\u91cd\u6392\u5e8f\u5668\u652f\u6301<\/strong>\uff1a\u5982CohereReranker\u3001VoyageReranker\u7b49\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\u77e5\u8bc6\u5e93<\/strong>\uff1a\u652f\u6301\u5c06\u77e5\u8bc6\u5e93\u5bf9\u8c61\u6301\u4e45\u5316\u5230\u78c1\u76d8\uff0c\u65b9\u4fbf\u540e\u7eed\u52a0\u8f7d\u548c\u67e5\u8be2\u3002<\/li>\n<li><strong>\u591a\u79cd\u6587\u6863\u683c\u5f0f\u652f\u6301<\/strong>\uff1a\u652f\u6301PDF\u3001Markdown\u7b49\u591a\u79cd\u6587\u6863\u683c\u5f0f\u7684\u89e3\u6790\u548c\u5904\u7406\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u5b89\u88c5<\/h3>\n<p>\u8981\u5b89\u88c5dsRAG\u7684Python\u5305\uff0c\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>pip install dsrag\r\n<\/code><\/pre>\n<p>\u786e\u4fdd\u4f60\u6709OpenAI\u548cCohere\u7684API\u5bc6\u94a5\uff0c\u5e76\u5c06\u5b83\u4eec\u8bbe\u7f6e\u4e3a\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<h3>\u5feb\u901f\u5f00\u59cb<\/h3>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528<code>create_kb_from_file<\/code>\u51fd\u6570\u76f4\u63a5\u4ece\u6587\u4ef6\u521b\u5efa\u65b0\u7684\u77e5\u8bc6\u5e93\uff1a<\/p>\n<pre><code>from dsrag.create_kb import create_kb_from_file\r\nfile_path = \"dsRAG\/tests\/data\/levels_of_agi.pdf\"\r\nkb_id = \"levels_of_agi\"\r\nkb = create_kb_from_file(kb_id, file_path)\r\n<\/code><\/pre>\n<p>\u77e5\u8bc6\u5e93\u5bf9\u8c61\u4f1a\u81ea\u52a8\u6301\u4e45\u5316\u5230\u78c1\u76d8\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u663e\u5f0f\u4fdd\u5b58\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5176<code>kb_id<\/code>\u52a0\u8f7d\u77e5\u8bc6\u5e93\uff0c\u5e76\u4f7f\u7528<code>query<\/code>\u65b9\u6cd5\u8fdb\u884c\u67e5\u8be2\uff1a<\/p>\n<pre><code>from dsrag.knowledge_base import KnowledgeBase\r\nkb = KnowledgeBase(\"levels_of_agi\")\r\nsearch_queries = [\"What are the levels of AGI?\", \"What is the highest level of AGI?\"]\r\nresults = kb.query(search_queries)\r\nfor segment in results:\r\nprint(segment)\r\n<\/code><\/pre>\n<h3>\u57fa\u672c\u5b9a\u5236<\/h3>\n<p>\u4f60\u53ef\u4ee5\u81ea\u5b9a\u4e49\u77e5\u8bc6\u5e93\u7684\u914d\u7f6e\uff0c\u4f8b\u5982\u53ea\u4f7f\u7528OpenAI\uff1a<\/p>\n<pre><code>from dsrag.llm import OpenAIChatAPI\r\nfrom dsrag.reranker import NoReranker\r\nllm = OpenAIChatAPI(model='gpt-4o-mini')\r\nreranker = NoReranker()\r\nkb = KnowledgeBase(kb_id=\"levels_of_agi\", reranker=reranker, auto_context_model=llm)\r\n<\/code><\/pre>\n<p>\u7136\u540e\u4f7f\u7528<code>add_document<\/code>\u65b9\u6cd5\u6dfb\u52a0\u6587\u6863\uff1a<\/p>\n<pre><code>file_path = \"dsRAG\/tests\/data\/levels_of_agi.pdf\"\r\nkb.add_document(doc_id=file_path, file_path=file_path)\r\n<\/code><\/pre>\n<h3>\u67b6\u6784<\/h3>\n<p>\u77e5\u8bc6\u5e93\u5bf9\u8c61\u63a5\u53d7\u6587\u6863\uff08\u539f\u59cb\u6587\u672c\u5f62\u5f0f\uff09\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u5206\u5757\u548c\u5d4c\u5165\uff0c\u4ee5\u53ca\u5176\u4ed6\u9884\u5904\u7406\u64cd\u4f5c\u3002\u67e5\u8be2\u65f6\uff0c\u8f93\u5165\u67e5\u8be2\u540e\uff0c\u7cfb\u7edf\u4f1a\u8fdb\u884c\u5411\u91cf\u6570\u636e\u5e93\u641c\u7d22\u3001\u91cd\u6392\u5e8f\u548c\u76f8\u5173\u6bb5\u63d0\u53d6\uff0c\u6700\u7ec8\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n<p>\u77e5\u8bc6\u5e93\u5bf9\u8c61\u9ed8\u8ba4\u662f\u6301\u4e45\u5316\u7684\uff0c\u5176\u5b8c\u6574\u914d\u7f6e\u4f1a\u4ee5JSON\u6587\u4ef6\u5f62\u5f0f\u4fdd\u5b58\uff0c\u65b9\u4fbf\u91cd\u5efa\u548c\u66f4\u65b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>dsRAG\u662f\u4e00\u6b3e\u9ad8\u6027\u80fd\u68c0\u7d22\u5f15\u64ce\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u975e\u7ed3\u6784\u5316\u6570\u636e\u7684\u590d\u6742\u67e5\u8be2\u3002\u5b83\u5728\u5904\u7406\u5bc6\u96c6\u6587\u672c\uff08\u5982\u8d22\u52a1\u62a5\u544a\u3001\u6cd5\u5f8b\u6587\u4ef6\u548c\u5b66\u672f\u8bba\u6587\uff09\u4e2d\u7684\u6311\u6218\u6027\u67e5\u8be2\u65f6\u8868\u73b0\u5c24\u4e3a\u51fa\u8272\u3002dsRAG\u91c7\u7528\u4e86\u4e09\u79cd\u5173\u952e\u65b9\u6cd5\u6765\u63d0\u9ad8\u6027\u80fd\uff1a\u8bed\u4e49\u5206\u6bb5\u3001\u4e0a\u4e0b\u6587\u81ea\u52a8\u751f\u6210\u548c\u76f8\u5173\u6bb5\u63d0\u53d6\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4f7fds&#8230;<\/p>\n","protected":false},"author":1,"featured_media":61882,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,459],"tags":[230,243],"class_list":["post-21668","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool","category-rag-project","tag-aikaiyuanxiangmu","tag-aizhishikuyukefu"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/posts\/21668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/comments?post=21668"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/posts\/21668\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/media\/61882"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/media?parent=21668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/categories?post=21668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/de\/wp-json\/wp\/v2\/tags?post=21668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}