{"id":2551,"date":"2025-07-22T15:28:37","date_gmt":"2025-07-22T07:28:37","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=2551"},"modified":"2025-07-22T15:28:37","modified_gmt":"2025-07-22T07:28:37","slug":"graphrag%ef%bc%9a%e8%ae%a9ai%e5%86%99%e7%a4%be%e5%8c%ba%e6%8a%a5%e5%91%8a%ef%bc%8c%e6%af%94%e4%bd%a0%e8%80%81%e6%9d%bf%e8%bf%98%e4%b8%93%e4%b8%9a%ef%bc%81","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2025\/07\/22\/graphrag%ef%bc%9a%e8%ae%a9ai%e5%86%99%e7%a4%be%e5%8c%ba%e6%8a%a5%e5%91%8a%ef%bc%8c%e6%af%94%e4%bd%a0%e8%80%81%e6%9d%bf%e8%bf%98%e4%b8%93%e4%b8%9a%ef%bc%81\/","title":{"rendered":"GraphRAG\uff1a\u8ba9AI\u5199\u201c\u793e\u533a\u62a5\u544a\u201d\uff0c\u6bd4\u4f60\u8001\u677f\u8fd8\u4e13\u4e1a\uff01"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u201c\u4f60\u89c1\u8fc7AI\u5199\u7684\u793e\u533a\u62a5\u544a\u5417\uff1f\u5b83\u4e0d\u4ec5\u4e0d\u6478\u9c7c\uff0c\u8fd8\u80fd\u5f15\u7528\u6570\u636e\u3001\u81ea\u52a8\u5206\u7ec4\u3001\u603b\u7ed3\u6d1e\u5bdf\uff0c\u8fde\u8001\u677f\u90fd\u81ea\u6127\u4e0d\u5982\uff01\u201d<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u76ee\u5f55<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"#\u9879\u76ee\u7b80\u4ecb\">\u9879\u76ee\u7b80\u4ecb<\/a><\/li>\n\n\n\n<li><a href=\"#GraphRAG\u7684\u5de5\u4f5c\u6d41\u7a0b\">GraphRAG\u7684\u5de5\u4f5c\u6d41\u7a0b<\/a><\/li>\n\n\n\n<li><a href=\"#\u793e\u533a\u62a5\u544aAI\u7684\u516b\u5366\u5c0f\u62a5\">\u793e\u533a\u62a5\u544a\uff1aAI\u7684\u201c\u516b\u5366\u5c0f\u62a5\u201d<\/a><\/li>\n\n\n\n<li><a href=\"#\u4ee3\u7801\u63ed\u79d8\u793e\u533a\u62a5\u544a\u662f\u600e\u4e48\u70bc\u6210\u7684\">\u4ee3\u7801\u63ed\u79d8\uff1a\u793e\u533a\u62a5\u544a\u662f\u600e\u4e48\u70bc\u6210\u7684\uff1f<\/a><\/li>\n\n\n\n<li><a href=\"#\u7ed3\u8bed\">\u7ed3\u8bed<\/a><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u9879\u76ee\u7b80\u4ecb<\/h2>\n\n\n\n<p>GraphRAG \u662f\u4ec0\u4e48\uff1f\u4e00\u53e5\u8bdd\uff1a<br><strong>\u5b83\u662f\u8ba9AI\u5728\u77e5\u8bc6\u56fe\u8c31\u91cc\u201c\u4e32\u95e8\u201d\uff0c\u81ea\u52a8\u53d1\u73b0\u5c0f\u56e2\u4f53\uff0c\u7136\u540e\u5199\u51fa\u4e00\u4efd\u4efd\u7ed3\u6784\u5316\u3001\u5e26\u6570\u636e\u5f15\u7528\u7684\u201c\u793e\u533a\u62a5\u544a\u201d\uff01<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u652f\u6301\u591a\u79cd\u6570\u636e\u5bfc\u5165\uff08CSV\u3001Neo4j\u7b49\uff09<\/li>\n\n\n\n<li>\u81ea\u52a8\u6784\u5efa\u77e5\u8bc6\u56fe\u8c31<\/li>\n\n\n\n<li>\u56fe\u805a\u7c7b\/\u793e\u533a\u53d1\u73b0<\/li>\n\n\n\n<li>\u6587\u672c\u5206\u5757+\u5411\u91cf\u5316+\u68c0\u7d22<\/li>\n\n\n\n<li>RAG\u589e\u5f3a\u95ee\u7b54<\/li>\n\n\n\n<li><strong>\u793e\u533a\u62a5\u544a\u81ea\u52a8\u751f\u6210<\/strong>\uff08\u4eca\u5929\u7684\u4e3b\u89d2\uff01\uff09<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">GraphRAG\u7684\u5de5\u4f5c\u6d41\u7a0b<\/h2>\n\n\n\n<p>\u8ba9\u6211\u4eec\u7528\u4e00\u5f20\u201c\u8111\u8865\u6d41\u7a0b\u56fe\u201d\u6765\u611f\u53d7\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>graph TD\n    A&#91;\u539f\u59cb\u6570\u636e] --&gt; B&#91;\u56fe\u6784\u5efa]\n    B --&gt; C&#91;\u793e\u533a\u53d1\u73b0]\n    C --&gt; D&#91;\u793e\u533a\u5185\u5bb9\u805a\u5408]\n    D --&gt; E&#91;\u793e\u533a\u62a5\u544a\u751f\u6210]\n    E --&gt; F&#91;RAG\u589e\u5f3a\u95ee\u7b54\/\u53ef\u89c6\u5316]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6570\u636e\u5bfc\u5165\u4e0e\u56fe\u6784\u5efa<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u652f\u6301CSV\u3001\u6570\u636e\u5e93\u3001Neo4j\u7b49\u591a\u79cd\u683c\u5f0f<\/li>\n\n\n\n<li>\u81ea\u52a8\u8bc6\u522b\u5b9e\u4f53\u3001\u5173\u7cfb\uff0c\u751f\u6210\u8282\u70b9\u548c\u8fb9<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u793e\u533a\u53d1\u73b0<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7528Louvain\u3001Leiden\u7b49\u7b97\u6cd5\uff0c\u628a\u5927\u56fe\u5206\u6210\u82e5\u5e72\u201c\u793e\u533a\u201d<\/li>\n\n\n\n<li>\u6bcf\u4e2a\u793e\u533a\u5c31\u662f\u4e00\u4e2a\u201c\u4e3b\u9898\u5c0f\u5708\u5b50\u201d<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u793e\u533a\u5185\u5bb9\u805a\u5408<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u628a\u6bcf\u4e2a\u793e\u533a\u7684\u8282\u70b9\u3001\u8fb9\u3001\u6587\u672c\u90fd\u6536\u96c6\u8d77\u6765<\/li>\n\n\n\n<li>\u7edf\u8ba1\u5173\u952e\u8bcd\u3001\u4ee3\u8868\u8282\u70b9\u3001\u4e3b\u8981\u5173\u7cfb<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u793e\u533a\u62a5\u544a\u751f\u6210<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7528LLM\uff08\u5927\u8bed\u8a00\u6a21\u578b\uff09+\u5b9a\u5236Prompt\uff0c\u81ea\u52a8\u5199\u201c\u793e\u533a\u62a5\u544a\u201d<\/li>\n\n\n\n<li>\u62a5\u544a\u5185\u5bb9\u5305\u62ec\uff1a\u6807\u9898\u3001\u6458\u8981\u3001\u5f71\u54cd\u529b\u8bc4\u5206\u3001\u8be6\u7ec6\u6d1e\u5bdf\u3001\u6570\u636e\u5f15\u7528<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5. RAG\u589e\u5f3a\u95ee\u7b54\/\u53ef\u89c6\u5316<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7528\u6237\u63d0\u95ee\u65f6\uff0c\u5148\u68c0\u7d22\u76f8\u5173\u793e\u533a\u548c\u62a5\u544a\uff0c\u518d\u8ba9LLM\u751f\u6210\u7b54\u6848<\/li>\n\n\n\n<li>\u652f\u6301\u793e\u533a\u7ed3\u6784\u3001\u62a5\u544a\u5185\u5bb9\u7684\u53ef\u89c6\u5316<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u793e\u533a\u62a5\u544a\uff1aAI\u7684\u201c\u516b\u5366\u5c0f\u62a5\u201d<\/h2>\n\n\n\n<p>\u4f60\u4ee5\u4e3aAI\u53ea\u4f1a\u4e00\u672c\u6b63\u7ecf\u5730\u56de\u7b54\u95ee\u9898\uff1f<br>\u9519\uff01\u5728GraphRAG\u91cc\uff0cAI\u4f1a\u81ea\u52a8\u5199\u201c\u793e\u533a\u62a5\u544a\u201d\uff0c\u800c\u4e14\u6bd4\u4f60\u8001\u677f\u8fd8\u4f1a\u603b\u7ed3\uff01<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u793e\u533a\u62a5\u544a\u957f\u5565\u6837\uff1f<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6807\u9898<\/strong>\uff1a\u4e00\u9488\u89c1\u8840\uff0c\u70b9\u540d\u9053\u59d3<\/li>\n\n\n\n<li><strong>\u6458\u8981<\/strong>\uff1a\u4e09\u8a00\u4e24\u8bed\uff0c\u6982\u62ec\u5168\u5c40<\/li>\n\n\n\n<li><strong>\u5f71\u54cd\u529b\u8bc4\u5206<\/strong>\uff1a0-10\u5206\uff0c\u8c01\u662f\u5927\u4f6c\u4e00\u76ee\u4e86\u7136<\/li>\n\n\n\n<li><strong>\u8be6\u7ec6\u6d1e\u5bdf<\/strong>\uff1a5-10\u6761\uff0c\u6bcf\u6761\u90fd\u5e26\u6570\u636e\u5f15\u7528\uff0c\u7edd\u4e0d\u7a7a\u53e3\u80e1\u8bf4<\/li>\n\n\n\n<li><strong>\u6570\u636e\u5f15\u7528<\/strong>\uff1a\u6bcf\u4e2a\u7ed3\u8bba\u90fd\u80fd\u8ffd\u6eaf\u5230\u539f\u59cb\u6570\u636e\uff0c\u8001\u677f\u518d\u4e5f\u4e0d\u80fd\u8bf4\u201c\u4f60\u8fd9\u662f\u62cd\u8111\u888b\u5199\u7684\uff01\u201d<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Prompt\u7247\u6bb5\uff08<code>graphrag\/prompts\/index\/community_report.py<\/code>\uff09\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>COMMUNITY_REPORT_PROMPT = \"\"\"\n...\nWrite a comprehensive report of a community, given a list of entities that belong to the community as well as their relationships and optional associated claims.\n...\nReturn output as a well-formed JSON-formatted string with the following format:\n    {\n        \"title\": &lt;report_title&gt;,\n        \"summary\": &lt;executive_summary&gt;,\n        \"rating\": &lt;impact_severity_rating&gt;,\n        \"rating_explanation\": &lt;rating_explanation&gt;,\n        \"findings\": &#91;\n            {\n                \"summary\":&lt;insight_1_summary&gt;,\n                \"explanation\": &lt;insight_1_explanation&gt;\n            },\n            ...\n        ]\n    }\n...\nPoints supported by data should list their data references as follows:\n\"This is an example sentence supported by multiple data references &#91;Data: &lt;dataset name&gt; (record ids); ...]\"\n...\n\"\"\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u62a5\u544a\u793a\u4f8b<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"title\": \"Verdant Oasis Plaza and Unity March\",\n    \"summary\": \"The community revolves around the Verdant Oasis Plaza, which is the location of the Unity March...\",\n    \"rating\": 5.0,\n    \"rating_explanation\": \"The impact severity rating is moderate due to the potential for unrest or conflict during the Unity March.\",\n    \"findings\": &#91;\n        {\n            \"summary\": \"Verdant Oasis Plaza as the central location\",\n            \"explanation\": \"Verdant Oasis Plaza is the central entity in this community... &#91;Data: Entities (5), Relationships (37, 38, 39, 40, 41,+more)]\"\n        },\n        ...\n    ]\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ee3\u7801\u63ed\u79d8\uff1a\u793e\u533a\u62a5\u544a\u662f\u600e\u4e48\u70bc\u6210\u7684\uff1f<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u793e\u533a\u62a5\u544a\u7684\u201c\u70bc\u91d1\u672f\u58eb\u201d\u2014\u2014<code>CommunityReportsExtractor<\/code><\/h3>\n\n\n\n<p><code>graphrag\/index\/operations\/summarize_communities\/community_reports_extractor.py<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class CommunityReportsExtractor:\n    ...\n    async def __call__(self, input_text: str):\n        # 1. \u6784\u5efaPrompt\n        prompt = self._extraction_prompt.format(\n            input_text=input_text,\n            max_report_length=str(self._max_report_length),\n        )\n        # 2. \u8c03\u7528LLM\u751f\u6210\u62a5\u544a\n        response = await self._model.achat(\n            prompt,\n            json=True,\n            name=\"create_community_report\",\n            json_model=CommunityReportResponse,\n        )\n        # 3. \u89e3\u6790\u7ed3\u6784\u5316\u8f93\u51fa\n        output = response.parsed_response\n        ...\n        return CommunityReportsResult(\n            structured_output=output,\n            output=text_output,\n        )<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u793e\u533a\u62a5\u544a\u7684\u201c\u6d41\u6c34\u7ebf\u201d\u2014\u2014<code>summarize_communities<\/code><\/h3>\n\n\n\n<p><code>graphrag\/index\/operations\/summarize_communities\/summarize_communities.py<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>async def summarize_communities(\n    nodes, communities, local_contexts, level_context_builder, ...\n):\n    # 1. \u7edf\u8ba1\u793e\u533a\u5c42\u7ea7\n    levels = get_levels(nodes)\n    # 2. \u6784\u5efa\u6bcf\u4e2a\u793e\u533a\u7684\u4e0a\u4e0b\u6587\n    for level in levels:\n        level_context = level_context_builder(...)\n        ...\n    # 3. \u5bf9\u6bcf\u4e2a\u793e\u533a\u8c03\u7528 _generate_report\n    for i, level_context in enumerate(level_contexts):\n        async def run_generate(record):\n            result = await _generate_report(\n                strategy_exec,\n                community_id=record&#91;schemas.COMMUNITY_ID],\n                community_context=record&#91;schemas.CONTEXT_STRING],\n                ...\n            )\n            return result\n        local_reports = await derive_from_rows(\n            level_context,\n            run_generate,\n            ...\n        )\n        reports.extend(&#91;lr for lr in local_reports if lr is not None])\n    return pd.DataFrame(reports)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u751f\u6210\u7684\u62a5\u544a\u53bb\u54ea\u4e86\uff1f<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b58\u5165\u6570\u636e\u5e93\/\u7f13\u5b58<\/li>\n\n\n\n<li>\u4f5c\u4e3aRAG\u68c0\u7d22\u7684\u201c\u77e5\u8bc6\u5757\u201d<\/li>\n\n\n\n<li>\u5c55\u793a\u5728Web\u754c\u9762\/Notebook\u91cc\uff0c\u4f9b\u7528\u6237\u6d4f\u89c8\u3001\u7b5b\u9009\u3001\u5bf9\u6bd4<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ed3\u8bed<\/h2>\n\n\n\n<p>GraphRAG\u7684\u201c\u793e\u533a\u62a5\u544a\u201d\u529f\u80fd\uff0c\u8ba9AI\u4e0d\u518d\u53ea\u662f\u201c\u68c0\u7d22\u5de5\u5177\u201d\uff0c\u800c\u662f\u53d8\u6210\u4e86\u4e00\u4e2a\u4f1a\u5199\u62a5\u544a\u3001\u80fd\u5f15\u7528\u6570\u636e\u3001\u81ea\u52a8\u5206\u7ec4\u3001\u7ed3\u6784\u5316\u603b\u7ed3\u7684\u201c\u77e5\u8bc6\u5206\u6790\u5e08\u201d\uff01<\/p>\n\n\n\n<p>\u4e0b\u6b21\u8001\u677f\u8ba9\u4f60\u5199\u793e\u533a\u5206\u6790\u62a5\u544a\uff0c\u4e0d\u59a8\u8ba9GraphRAG\u5e2e\u4f60\u201c\u6253\u4e2a\u8349\u7a3f\u201d\u2014\u2014<br><strong>\u5b83\u4e0d\u4ec5\u4e0d\u6478\u9c7c\uff0c\u8fd8\u80fd\u5e2e\u4f60\u627e\u5230\u4f60\u90fd\u6ca1\u53d1\u73b0\u7684\u201c\u516b\u5366\u201d\uff01<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u60f3\u6df1\u5165\u4e86\u89e3\uff1f\u5feb\u53bb\u7ffb\u7ffb <code>graphrag\/index\/operations\/summarize_communities\/<\/code> \u76ee\u5f55\u4e0b\u7684\u6e90\u7801\u5427\uff0c<br>\u8ba9AI\u548c\u4f60\u4e00\u8d77\u6210\u4e3a\u201c\u793e\u533a\u516b\u5366\u4e4b\u738b\u201d\uff01<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u201c\u4f60\u89c1\u8fc7AI\u5199\u7684\u793e\u533a\u62a5\u544a\u5417\uff1f\u5b83\u4e0d&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[73,76,75],"class_list":["post-2551","post","type-post","status-publish","format-standard","hentry","category-rag","tag-ai","tag-kag","tag-rag"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=2551"}],"version-history":[{"count":1,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2551\/revisions"}],"predecessor-version":[{"id":2552,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2551\/revisions\/2552"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=2551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=2551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=2551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}