{"id":69,"date":"2026-06-29T10:21:39","date_gmt":"2026-06-29T02:21:39","guid":{"rendered":"https:\/\/genetop.top\/index.php\/2026\/06\/29\/graphrag-entity-extraction-alias-limitation\/"},"modified":"2026-06-29T10:21:39","modified_gmt":"2026-06-29T02:21:39","slug":"graphrag-entity-extraction-alias-limitation","status":"publish","type":"post","link":"https:\/\/genetop.top\/index.php\/2026\/06\/29\/graphrag-entity-extraction-alias-limitation\/","title":{"rendered":"GraphRAG \u5b9e\u4f53\u63d0\u53d6\u7684\u522b\u540d\u5c40\u9650\u6027\u5206\u6790"},"content":{"rendered":"<h2 id=\"1\">1. \u95ee\u9898\u6982\u8ff0<\/h2>\n<p>GraphRAG \u5728\u5b9e\u4f53\u63d0\u53d6\u9636\u6bb5\uff0c\u5c06\u540c\u4e00\u5b9e\u4f53\u7684\u4e0d\u540c\u522b\u540d\u89c6\u4e3a<strong>\u72ec\u7acb\u5b9e\u4f53<\/strong>\uff0c\u5bfc\u81f4\u77e5\u8bc6\u56fe\u8c31\u4e2d\u51fa\u73b0\u5b9e\u4f53\u788e\u7247\u5316\u3002\u4ee5&#8221;\u5b59\u609f\u7a7a&#8221;\u4e3a\u4f8b\uff1a<\/p>\n<pre><code>\u6587\u672cA: &quot;\u5b59\u609f\u7a7a\u5927\u95f9\u5929\u5bab&quot;        \u2192 \u5b9e\u4f53: \u5b59\u609f\u7a7a\n\u6587\u672cB: &quot;\u5b59\u884c\u8005\u4e09\u6253\u767d\u9aa8\u7cbe&quot;      \u2192 \u5b9e\u4f53: \u5b59\u884c\u8005\n\u6587\u672cC: &quot;\u9f50\u5929\u5927\u5723\u88ab\u538b\u4e94\u884c\u5c71\u4e0b&quot;  \u2192 \u5b9e\u4f53: \u9f50\u5929\u5927\u5723\n<\/code><\/pre>\n<p>\u6700\u7ec8\u56fe\u8c31\u4e2d\u51fa\u73b0\u4e09\u4e2a\u72ec\u7acb\u8282\u70b9\uff0c\u5b83\u4eec\u4e4b\u95f4<strong>\u6ca1\u6709\u4efb\u4f55\u5173\u8054<\/strong>\u3002\u67e5\u8be2&#8221;\u5b59\u609f\u7a7a\u505a\u4e86\u4ec0\u4e48&#8221;\u65f6\uff0c\u53ea\u80fd\u627e\u5230&#8221;\u5927\u95f9\u5929\u5bab&#8221;\uff0c\u800c&#8221;\u4e09\u6253\u767d\u9aa8\u7cbe&#8221;\u548c&#8221;\u88ab\u538b\u4e94\u884c\u5c71\u4e0b&#8221;\u7684\u5173\u7cfb\u94fe\u5b8c\u5168\u65ad\u88c2\u3002<\/p>\n<h2 id=\"2-graphrag\">2. \u5f53\u524d GraphRAG \u7684\u5904\u7406\u65b9\u5f0f<\/h2>\n<h3 id=\"21\">2.1 \u5b9e\u4f53\u63d0\u53d6\u9636\u6bb5<\/h3>\n<p><strong>\u6e90\u7801<\/strong>: <code>packages\/graphrag\/graphrag\/index\/operations\/extract_graph\/graph_extractor.py<\/code><\/p>\n<p>LLM \u4ece\u6bcf\u4e2a text unit \u4e2d\u63d0\u53d6\u5b9e\u4f53\uff0c\u6838\u5fc3\u903b\u8f91\uff1a<\/p>\n<pre><code class=\"language-python\"># graph_extractor.py \u2192 _process_result()\nif record_type == '&quot;entity&quot;' and len(record_attributes) &gt;= 4:\n    entity_name = clean_str(record_attributes[1].upper())  # \u540d\u79f0\u7edf\u4e00\u5927\u5199\n    entity_type = clean_str(record_attributes[2].upper())\n    entity_description = clean_str(record_attributes[3])\n    entities.append({\n        &quot;title&quot;: entity_name,\n        &quot;type&quot;: entity_type,\n        &quot;description&quot;: entity_description,\n        &quot;source_id&quot;: source_id,\n    })\n<\/code><\/pre>\n<p>\u5173\u952e\u70b9\uff1a<br \/>\n&#8211; \u5b9e\u4f53\u540d\u79f0\u4ec5\u505a <code>clean_str()<\/code> + <code>upper()<\/code> \u5904\u7406\uff08\u53bb\u9664 HTML \u8f6c\u4e49\u548c\u63a7\u5236\u5b57\u7b26\uff0c\u8f6c\u5927\u5199\uff09<br \/>\n&#8211; <strong>\u6ca1\u6709\u4efb\u4f55\u522b\u540d\u8bc6\u522b\u6216\u5f52\u4e00\u5316\u903b\u8f91<\/strong><br \/>\n&#8211; LLM \u63d0\u53d6\u4ec0\u4e48\u540d\u5b57\uff0c\u5c31\u539f\u6837\u8bb0\u5f55\u4ec0\u4e48\u540d\u5b57<\/p>\n<h3 id=\"22\">2.2 \u5b9e\u4f53\u5408\u5e76\u9636\u6bb5<\/h3>\n<p><strong>\u6e90\u7801<\/strong>: <code>packages\/graphrag\/graphrag\/index\/operations\/extract_graph\/extract_graph.py<\/code><\/p>\n<p>\u591a\u4e2a text unit \u63d0\u53d6\u7684\u5b9e\u4f53\u901a\u8fc7 <code>_merge_entities()<\/code> \u5408\u5e76\uff1a<\/p>\n<pre><code class=\"language-python\">def _merge_entities(entity_dfs) -&gt; pd.DataFrame:\n    all_entities = pd.concat(entity_dfs, ignore_index=True)\n    return (\n        all_entities\n        .groupby([&quot;title&quot;, &quot;type&quot;], sort=False)  # \u2190 \u4ec5\u6309 title + type \u5206\u7ec4\n        .agg(\n            description=(&quot;description&quot;, list),\n            text_unit_ids=(&quot;source_id&quot;, list),\n            frequency=(&quot;source_id&quot;, &quot;count&quot;),\n        )\n        .reset_index()\n    )\n<\/code><\/pre>\n<p>\u5408\u5e76\u7b56\u7565\u662f <strong>\u7cbe\u786e\u5b57\u7b26\u4e32\u5339\u914d<\/strong>\uff1a\u53ea\u6709 <code>title<\/code>\uff08\u540d\u79f0\uff09\u548c <code>type<\/code>\uff08\u7c7b\u578b\uff09\u5b8c\u5168\u76f8\u540c\u7684\u5b9e\u4f53\u624d\u4f1a\u88ab\u5408\u5e76\u3002<\/p>\n<p>\u8fd9\u610f\u5473\u7740\uff1a<br \/>\n&#8211; <code>\u5b59\u609f\u7a7a<\/code> \u548c <code>\u5b59\u884c\u8005<\/code> \u2192 <strong>\u4e0d\u5408\u5e76<\/strong>\uff08title \u4e0d\u540c\uff09<br \/>\n&#8211; <code>SUN WUKONG<\/code> \u548c <code>MONKEY KING<\/code> \u2192 <strong>\u4e0d\u5408\u5e76<\/strong><br \/>\n&#8211; <code>TechGlobal<\/code> \u548c <code>TG<\/code> \u2192 <strong>\u4e0d\u5408\u5e76<\/strong>\uff08\u7f29\u5199 vs \u5168\u79f0\uff09<\/p>\n<h3 id=\"23\">2.3 \u63cf\u8ff0\u6458\u8981\u9636\u6bb5<\/h3>\n<p><strong>\u6e90\u7801<\/strong>: <code>packages\/graphrag\/graphrag\/index\/operations\/summarize_descriptions\/<\/code><\/p>\n<p>\u5408\u5e76\u540e\uff0c\u540c\u4e00\u5b9e\u4f53\uff08title \u76f8\u540c\uff09\u7684\u591a\u6761 description \u4f1a\u901a\u8fc7 LLM \u6c47\u603b\u4e3a\u4e00\u6761\uff1a<\/p>\n<pre><code class=\"language-python\"># description_summary_extractor.py\nasync def __call__(self, id, descriptions):\n    if len(descriptions) == 0:\n        result = &quot;&quot;\n    elif len(descriptions) == 1:\n        result = descriptions[0]  # \u53ea\u6709\u4e00\u6761\u63cf\u8ff0\uff0c\u76f4\u63a5\u4f7f\u7528\n    else:\n        result = await self._summarize_descriptions(id, descriptions)  # \u591a\u6761\u63cf\u8ff0\uff0cLLM \u6c47\u603b\n<\/code><\/pre>\n<p>\u6458\u8981 prompt \u7684\u8bbe\u8ba1\uff1a<\/p>\n<pre><code>Given one or more entities, and a list of descriptions, all related to the same entity\nor group of entities. Please concatenate all of these into a single, comprehensive\ndescription. If the provided descriptions are contradictory, please resolve the\ncontradictions and provide a single, coherent summary.\n<\/code><\/pre>\n<p><strong>\u95ee\u9898<\/strong>\uff1a\u8fd9\u4e2a\u6458\u8981\u6b65\u9aa4\u53ea\u5904\u7406\u5df2\u7ecf\u88ab <code>_merge_entities()<\/code> \u5408\u5e76\u5230\u4e00\u8d77\u7684\u63cf\u8ff0\u3002\u7531\u4e8e\u522b\u540d\u5b9e\u4f53\u6839\u672c\u6ca1\u6709\u88ab\u5408\u5e76\uff0c\u5b83\u4eec\u7684\u63cf\u8ff0\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u653e\u5728\u4e00\u8d77\u6458\u8981\u3002<\/p>\n<h3 id=\"24\">2.4 \u5173\u7cfb\u7684\u8fde\u5e26\u65ad\u88c2<\/h3>\n<p><strong>\u6e90\u7801<\/strong>: <code>extract_graph.py \u2192 _merge_relationships()<\/code><\/p>\n<pre><code class=\"language-python\">def _merge_relationships(relationship_dfs) -&gt; pd.DataFrame:\n    all_relationships = pd.concat(relationship_dfs, ignore_index=False)\n    return (\n        all_relationships\n        .groupby([&quot;source&quot;, &quot;target&quot;], sort=False)  # \u2190 \u6309 source + target \u7cbe\u786e\u5339\u914d\n        .agg(\n            description=(&quot;description&quot;, list),\n            text_unit_ids=(&quot;source_id&quot;, list),\n            weight=(&quot;weight&quot;, &quot;sum&quot;),\n        )\n        .reset_index()\n    )\n<\/code><\/pre>\n<p>\u5173\u7cfb\u5408\u5e76\u540c\u6837\u4f9d\u8d56\u7cbe\u786e\u5b57\u7b26\u4e32\u5339\u914d\u3002\u5047\u8bbe\uff1a<\/p>\n<pre><code>\u6587\u672cA \u63d0\u53d6: (\u5b59\u609f\u7a7a) --\u5e08\u5f92--&gt; (\u5510\u50e7)\n\u6587\u672cB \u63d0\u53d6: (\u5b59\u884c\u8005) --\u5e08\u5f92--&gt; (\u5510\u50e7)\n<\/code><\/pre>\n<p>\u8fd9\u4e24\u6761\u5173\u7cfb <strong>\u4e0d\u4f1a\u5408\u5e76<\/strong>\uff0c\u56e0\u4e3a source \u4e0d\u540c\u3002\u6700\u7ec8\u56fe\u8c31\u4e2d\uff1a<br \/>\n&#8211; <code>\u5b59\u609f\u7a7a \u2192 \u5510\u50e7<\/code> (weight=1)<br \/>\n&#8211; <code>\u5b59\u884c\u8005 \u2192 \u5510\u50e7<\/code> (weight=1)<\/p>\n<p>\u800c\u6b63\u786e\u7684\u7ed3\u679c\u5e94\u8be5\u662f\u4e00\u6761 weight=2 \u7684\u5173\u7cfb\u3002\u66f4\u4e25\u91cd\u7684\u662f\uff0c\u5982\u679c\u67d0\u4e9b\u5173\u7cfb\u53ea\u51fa\u73b0\u5728\u522b\u540d\u4e0a\u4e0b\u6587\u4e2d\uff0c\u67e5\u8be2\u4e3b\u540d\u79f0\u65f6\u5b8c\u5168\u627e\u4e0d\u5230\u3002<\/p>\n<h3 id=\"25\">2.5 \u67e5\u8be2\u9636\u6bb5\u7684\u5f71\u54cd<\/h3>\n<p><strong>\u6e90\u7801<\/strong>: <code>packages\/graphrag\/graphrag\/query\/context_builder\/entity_extraction.py<\/code><\/p>\n<p>\u67e5\u8be2\u65f6\u901a\u8fc7 embedding \u5411\u91cf\u76f8\u4f3c\u5ea6\u5339\u914d\u5b9e\u4f53\uff1a<\/p>\n<pre><code class=\"language-python\">def map_query_to_entities(query, text_embedding_vectorstore, text_embedder, ...):\n    search_results = text_embedding_vectorstore.similarity_search_by_text(\n        text=query,\n        text_embedder=lambda t: text_embedder.embedding(input=[t]).first_embedding,\n        k=k * oversample_scaler,\n    )\n<\/code><\/pre>\n<p>\u67e5\u8be2&#8221;\u5b59\u609f\u7a7a&#8221;\u65f6\uff0cembedding \u76f8\u4f3c\u5ea6\u53ef\u80fd\u5339\u914d\u5230&#8221;\u5b59\u609f\u7a7a&#8221;\u8282\u70b9\uff0c\u4f46&#8221;\u5b59\u884c\u8005&#8221;\u548c&#8221;\u9f50\u5929\u5927\u5723&#8221;\u8282\u70b9\u7684 embedding \u8ddd\u79bb\u8f83\u8fdc\uff0c\u53ef\u80fd\u4e0d\u5728 top-k \u7ed3\u679c\u4e2d\u3002\u5373\u4f7f\u5339\u914d\u5230\u4e86\uff0c\u5b83\u4eec\u4f5c\u4e3a\u72ec\u7acb\u8282\u70b9\uff0c\u5404\u81ea\u7684\u5173\u7cfb\u5b50\u56fe\u4e5f\u662f\u5272\u88c2\u7684\u3002<\/p>\n<h2 id=\"3\">3. \u6839\u672c\u539f\u56e0\u603b\u7ed3<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u73af\u8282<\/th>\n<th>\u5f53\u524d\u884c\u4e3a<\/th>\n<th>\u95ee\u9898<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>LLM \u63d0\u53d6<\/td>\n<td>\u6309\u6587\u672c\u4e2d\u51fa\u73b0\u7684\u540d\u79f0\u539f\u6837\u63d0\u53d6<\/td>\n<td>\u4e0d\u540c\u522b\u540d\u4ea7\u751f\u4e0d\u540c entity title<\/td>\n<\/tr>\n<tr>\n<td>\u5b9e\u4f53\u5408\u5e76<\/td>\n<td><code>groupby([\"title\", \"type\"])<\/code> \u7cbe\u786e\u5339\u914d<\/td>\n<td>\u522b\u540d\u5b9e\u4f53\u65e0\u6cd5\u5408\u5e76<\/td>\n<\/tr>\n<tr>\n<td>\u63cf\u8ff0\u6458\u8981<\/td>\n<td>\u53ea\u6458\u8981\u5df2\u5408\u5e76\u5b9e\u4f53\u7684\u63cf\u8ff0<\/td>\n<td>\u522b\u540d\u5b9e\u4f53\u7684\u63cf\u8ff0\u6c38\u8fdc\u5206\u79bb<\/td>\n<\/tr>\n<tr>\n<td>\u5173\u7cfb\u5408\u5e76<\/td>\n<td><code>groupby([\"source\", \"target\"])<\/code> \u7cbe\u786e\u5339\u914d<\/td>\n<td>\u522b\u540d\u5bfc\u81f4\u5173\u7cfb\u788e\u7247\u5316<\/td>\n<\/tr>\n<tr>\n<td>\u67e5\u8be2\u5339\u914d<\/td>\n<td>embedding \u76f8\u4f3c\u5ea6\u641c\u7d22<\/td>\n<td>\u522b\u540d\u8282\u70b9\u53ef\u80fd\u4e0d\u5728 top-k \u4e2d<\/td>\n<\/tr>\n<tr>\n<td>Prompt<\/td>\n<td>\u65e0\u522b\u540d\u8bc6\u522b\u6307\u4ee4<\/td>\n<td>LLM \u6ca1\u6709\u88ab\u5f15\u5bfc\u53bb\u7edf\u4e00\u522b\u540d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"4-llm\">4. \u89e3\u51b3\u65b9\u6848\uff1aLLM \u522b\u540d\u53d1\u73b0 + \u5916\u90e8\u77e5\u8bc6\u5e93\u786e\u5b9a\u6027\u5408\u5e76<\/h2>\n<p>\u6574\u4f53\u601d\u8def\uff1a<strong>\u4e24\u5c42\u4fdd\u969c<\/strong>\u3002LLM \u5728\u63d0\u53d6\u65f6\u53d1\u73b0\u522b\u540d\u5173\u7cfb\uff0c\u8986\u76d6\u5927\u90e8\u5206\u60c5\u51b5\uff1b\u5916\u90e8\u77e5\u8bc6\u5e93\u5bf9\u7279\u522b\u5173\u5fc3\u7684\u5b9e\u4f53\u63d0\u4f9b\u786e\u5b9a\u6027\u515c\u5e95\uff0c\u786e\u4fdd\u5173\u952e\u5b9e\u4f53\u4e0d\u4f1a\u56e0 LLM \u4e0d\u4e00\u81f4\u800c\u9057\u6f0f\u3002<\/p>\n<h3 id=\"41\">4.1 \u6574\u4f53\u6d41\u7a0b<\/h3>\n<pre><code>                    \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n                    \u2502  \u5916\u90e8\u522b\u540d\u77e5\u8bc6\u5e93       \u2502\n                    \u2502  (JSON\/DB, \u4eba\u5de5\u7ef4\u62a4)  \u2502\n                    \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n                               \u2502 \u52a0\u8f7d\n                               \u25bc\ntext units \u2500\u2500\u2192 LLM \u63d0\u53d6(\u542baliases) \u2500\u2500\u2192 \u522b\u540d\u5f52\u4e00\u5316 \u2500\u2500\u2192 _merge_entities \u2500\u2500\u2192 \u540e\u7eed\u6d41\u7a0b\n                                         \u25b2\n                                         \u2502\n                              \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n                              \u2502 1. \u5916\u90e8\u77e5\u8bc6\u5e93\u4f18\u5148\u5339\u914d  \u2502\n                              \u2502 2. LLM aliases \u8865\u5145   \u2502\n                              \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n<\/code><\/pre>\n<h3 id=\"42\">4.2 \u5916\u90e8\u522b\u540d\u77e5\u8bc6\u5e93<\/h3>\n<p>\u7528\u6237\u7ef4\u62a4\u4e00\u4efd\u522b\u540d\u6620\u5c04\u6587\u4ef6\uff0c\u5b9a\u4e49\u7279\u522b\u5173\u5fc3\u7684\u5b9e\u4f53\u7684 canonical name \u548c\u6240\u6709\u5df2\u77e5\u522b\u540d\uff1a<\/p>\n<pre><code class=\"language-json\">\/\/ alias_kb.json\n[\n  {\n    &quot;canonical&quot;: &quot;\u5b59\u609f\u7a7a&quot;,\n    &quot;aliases&quot;: [&quot;\u5b59\u884c\u8005&quot;, &quot;\u9f50\u5929\u5927\u5723&quot;, &quot;\u7f8e\u7334\u738b&quot;, &quot;\u6597\u6218\u80dc\u4f5b&quot;]\n  },\n  {\n    &quot;canonical&quot;: &quot;\u732a\u516b\u6212&quot;,\n    &quot;aliases&quot;: [&quot;\u5929\u84ec\u5143\u5e05&quot;, &quot;\u732a\u609f\u80fd&quot;, &quot;\u732a\u521a\u9b23&quot;, &quot;\u5446\u5b50&quot;, &quot;\u4e8c\u5e08\u5144&quot;]\n  }\n]\n<\/code><\/pre>\n<p>\u7279\u70b9\uff1a<br \/>\n&#8211; <strong>\u786e\u5b9a\u6027<\/strong>\uff1a\u77e5\u8bc6\u5e93\u4e2d\u7684\u6620\u5c04\u662f\u786c\u89c4\u5219\uff0c\u4e0d\u4f9d\u8d56 LLM \u5224\u65ad\uff0c100% \u4fdd\u8bc1\u5408\u5e76<br \/>\n&#8211; <strong>\u53ef\u63a7<\/strong>\uff1a\u53ea\u9700\u8986\u76d6\u4e1a\u52a1\u4e0a\u7279\u522b\u5173\u5fc3\u7684\u5b9e\u4f53\uff0c\u4e0d\u9700\u8981\u7a77\u4e3e\u6240\u6709\u5b9e\u4f53<br \/>\n&#8211; <strong>\u53ef\u589e\u91cf\u7ef4\u62a4<\/strong>\uff1a\u53d1\u73b0\u65b0\u7684\u6f0f\u5408\u5e76\u65f6\uff0c\u52a0\u4e00\u6761\u8bb0\u5f55\u5373\u53ef<\/p>\n<h3 id=\"43-llm-aliases\">4.3 LLM \u63d0\u53d6\u9636\u6bb5\u589e\u52a0 aliases \u5b57\u6bb5<\/h3>\n<p>\u4fee\u6539\u63d0\u53d6 prompt\uff08<code>prompts\/index\/extract_graph.py<\/code>\uff09\uff0c\u8ba9 LLM \u5728\u63d0\u53d6\u5b9e\u4f53\u65f6\u540c\u65f6\u8f93\u51fa\u522b\u540d\uff1a<\/p>\n<pre><code>1. Identify all entities. For each identified entity, extract the following information:\n- entity_name: Name of the entity, capitalized\n- entity_type: One of the following types: [{entity_types}]\n- entity_description: Comprehensive description of the entity's attributes and activities\n- aliases: Other names, abbreviations, or titles for this entity found in the text.\n  If none, leave empty.\nFormat each entity as (&quot;entity&quot;&lt;|&gt;&lt;entity_name&gt;&lt;|&gt;&lt;entity_type&gt;&lt;|&gt;&lt;entity_description&gt;&lt;|&gt;&lt;aliases&gt;)\n<\/code><\/pre>\n<p>\u5728 <code>graph_extractor.py<\/code> \u7684 <code>_process_result()<\/code> \u4e2d\u89e3\u6790 aliases\uff1a<\/p>\n<pre><code class=\"language-python\">if record_type == '&quot;entity&quot;' and len(record_attributes) &gt;= 4:\n    entity_name = clean_str(record_attributes[1].upper())\n    entity_type = clean_str(record_attributes[2].upper())\n    entity_description = clean_str(record_attributes[3])\n    aliases = []\n    if len(record_attributes) &gt;= 5:\n        aliases = [clean_str(a.upper()) for a in record_attributes[4].split(&quot;,&quot;) if a.strip()]\n    entities.append({\n        &quot;title&quot;: entity_name,\n        &quot;type&quot;: entity_type,\n        &quot;description&quot;: entity_description,\n        &quot;source_id&quot;: source_id,\n        &quot;aliases&quot;: aliases,\n    })\n<\/code><\/pre>\n<p>LLM \u53d1\u73b0\u7684\u522b\u540d\u8986\u76d6\u5916\u90e8\u77e5\u8bc6\u5e93\u672a\u6536\u5f55\u7684\u957f\u5c3e\u60c5\u51b5\u3002\u4f8b\u5982\u6587\u672c\u4e2d\u51fa\u73b0&#8221;\u7334\u54e5&#8221;\u6307\u4ee3\u5b59\u609f\u7a7a\uff0c\u77e5\u8bc6\u5e93\u6ca1\u6536\u5f55\uff0c\u4f46 LLM \u80fd\u8bc6\u522b\u5e76\u8f93\u51fa <code>aliases: \u7334\u54e5<\/code>\u3002<\/p>\n<h3 id=\"44\">4.4 \u522b\u540d\u5f52\u4e00\u5316\uff1a\u4e24\u5c42\u5408\u5e76<\/h3>\n<p>\u5728 <code>_merge_entities()<\/code> \u4e4b\u524d\uff0c\u5148\u6784\u5efa\u7edf\u4e00\u7684 alias \u2192 canonical \u6620\u5c04\uff0c\u5916\u90e8\u77e5\u8bc6\u5e93\u4f18\u5148\uff1a<\/p>\n<pre><code class=\"language-python\">def _build_alias_map(entity_dfs, alias_kb_path=None):\n    &quot;&quot;&quot;\u6784\u5efa alias \u2192 canonical \u6620\u5c04\u3002\u5916\u90e8\u77e5\u8bc6\u5e93\u4f18\u5148\uff0cLLM aliases \u8865\u5145\u3002&quot;&quot;&quot;\n    alias_to_canonical = {}\n\n    # \u7b2c\u4e00\u5c42\uff1a\u5916\u90e8\u77e5\u8bc6\u5e93\uff08\u786e\u5b9a\u6027\uff0c\u4f18\u5148\u7ea7\u6700\u9ad8\uff09\n    if alias_kb_path:\n        import json\n        with open(alias_kb_path) as f:\n            kb_entries = json.load(f)\n        for entry in kb_entries:\n            canonical = entry[&quot;canonical&quot;].upper()\n            for alias in entry[&quot;aliases&quot;]:\n                alias_to_canonical[alias.upper()] = canonical\n\n    # \u7b2c\u4e8c\u5c42\uff1aLLM \u63d0\u53d6\u7684 aliases\uff08\u8865\u5145\u77e5\u8bc6\u5e93\u672a\u8986\u76d6\u7684\uff09\n    all_entities = pd.concat(entity_dfs, ignore_index=True)\n    name_freq = all_entities[&quot;title&quot;].value_counts()\n\n    for _, row in all_entities.iterrows():\n        title = row[&quot;title&quot;]\n        for alias in row.get(&quot;aliases&quot;, []):\n            if not alias or alias == title:\n                continue\n            # \u5916\u90e8\u77e5\u8bc6\u5e93\u5df2\u6709\u6620\u5c04\u7684\uff0c\u4e0d\u8986\u76d6\n            if alias in alias_to_canonical or title in alias_to_canonical:\n                continue\n            # LLM aliases\uff1a\u9891\u7387\u9ad8\u7684\u4f5c\u4e3a canonical\n            if name_freq.get(alias, 0) &gt; name_freq.get(title, 0):\n                alias_to_canonical[title] = alias\n            else:\n                alias_to_canonical[alias] = title\n\n    # \u4f20\u9012\u95ed\u5305\uff1aA\u2192B, B\u2192C \u5219 A\u2192C\n    def resolve(name):\n        visited = set()\n        while name in alias_to_canonical and name not in visited:\n            visited.add(name)\n            name = alias_to_canonical[name]\n        return name\n\n    return resolve\n<\/code><\/pre>\n<p>\u5728 <code>extract_graph()<\/code> \u4e2d\uff0c\u5408\u5e76\u524d\u7edf\u4e00\u91cd\u5199\u5b9e\u4f53\u548c\u5173\u7cfb\u4e2d\u7684\u540d\u79f0\uff1a<\/p>\n<pre><code class=\"language-python\">async def extract_graph(...) -&gt; tuple[pd.DataFrame, pd.DataFrame]:\n    # ... LLM \u63d0\u53d6 ...\n    results = await derive_from_rows(...)\n\n    entity_dfs = [r[0] for r in results if r]\n    relationship_dfs = [r[1] for r in results if r]\n\n    # \u522b\u540d\u5f52\u4e00\u5316\uff08\u65b0\u589e\uff09\n    resolve = _build_alias_map(entity_dfs, alias_kb_path=config.alias_kb_path)\n    for df in entity_dfs:\n        df[&quot;title&quot;] = df[&quot;title&quot;].map(resolve)\n    for df in relationship_dfs:\n        df[&quot;source&quot;] = df[&quot;source&quot;].map(resolve)\n        df[&quot;target&quot;] = df[&quot;target&quot;].map(resolve)\n\n    # \u539f\u6709\u5408\u5e76\u903b\u8f91\uff08\u73b0\u5728\u80fd\u6b63\u786e\u5408\u5e76\u522b\u540d\u5b9e\u4f53\uff09\n    entities = _merge_entities(entity_dfs)\n    relationships = _merge_relationships(relationship_dfs)\n    relationships = filter_orphan_relationships(relationships, entities)\n\n    return (entities, relationships)\n<\/code><\/pre>\n<h3 id=\"45\">4.5 \u6548\u679c\u5bf9\u6bd4<\/h3>\n<p>\u4ee5&#8221;\u5b59\u609f\u7a7a&#8221;\u4e3a\u4f8b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u573a\u666f<\/th>\n<th>\u5f53\u524d\u884c\u4e3a<\/th>\n<th>\u6539\u8fdb\u540e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u6587\u672cA\u63d0\u5230&#8221;\u5b59\u609f\u7a7a&#8221;\uff0c\u6587\u672cB\u63d0\u5230&#8221;\u5b59\u884c\u8005&#8221;<\/td>\n<td>\u4e24\u4e2a\u72ec\u7acb\u8282\u70b9\uff0c\u5173\u7cfb\u65ad\u88c2<\/td>\n<td>\u5916\u90e8\u77e5\u8bc6\u5e93\u547d\u4e2d\uff0c\u7edf\u4e00\u4e3a&#8221;\u5b59\u609f\u7a7a&#8221;<\/td>\n<\/tr>\n<tr>\n<td>\u6587\u672cC\u63d0\u5230&#8221;\u7334\u54e5&#8221;\uff08\u77e5\u8bc6\u5e93\u672a\u6536\u5f55\uff09<\/td>\n<td>\u72ec\u7acb\u8282\u70b9<\/td>\n<td>LLM aliases \u53d1\u73b0\uff0c\u5f52\u4e00\u5316\u5230&#8221;\u5b59\u609f\u7a7a&#8221;<\/td>\n<\/tr>\n<tr>\n<td>\u6587\u672cD\u63d0\u5230&#8221;\u5929\u84ec\u5143\u5e05&#8221;\uff08\u77e5\u8bc6\u5e93\u6709\uff09<\/td>\n<td>\u72ec\u7acb\u8282\u70b9<\/td>\n<td>\u5916\u90e8\u77e5\u8bc6\u5e93\u547d\u4e2d\uff0c\u7edf\u4e00\u4e3a&#8221;\u732a\u516b\u6212&#8221;<\/td>\n<\/tr>\n<tr>\n<td>\u6587\u672cE\u63d0\u5230\u67d0\u4e2a\u51b7\u95e8\u7f29\u5199\uff08\u4e24\u5c42\u90fd\u6ca1\u8986\u76d6\uff09<\/td>\n<td>\u72ec\u7acb\u8282\u70b9<\/td>\n<td>\u4ecd\u4e3a\u72ec\u7acb\u8282\u70b9\uff0c\u53d1\u73b0\u540e\u52a0\u5165\u77e5\u8bc6\u5e93\u5373\u53ef<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"6\">6. \u6e90\u7801\u6587\u4ef6\u7d22\u5f15<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u6587\u4ef6<\/th>\n<th>\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>prompts\/index\/extract_graph.py<\/code><\/td>\n<td>\u5b9e\u4f53\u63d0\u53d6 prompt \u5b9a\u4e49<\/td>\n<\/tr>\n<tr>\n<td><code>index\/operations\/extract_graph\/graph_extractor.py<\/code><\/td>\n<td>LLM \u63d0\u53d6\u7ed3\u679c\u89e3\u6790\uff0c\u5b9e\u4f53\/\u5173\u7cfb\u6784\u5efa<\/td>\n<\/tr>\n<tr>\n<td><code>index\/operations\/extract_graph\/extract_graph.py<\/code><\/td>\n<td>\u5b9e\u4f53\/\u5173\u7cfb\u5408\u5e76\u903b\u8f91\uff08<code>_merge_entities<\/code>, <code>_merge_relationships<\/code>\uff09<\/td>\n<\/tr>\n<tr>\n<td><code>index\/operations\/extract_graph\/utils.py<\/code><\/td>\n<td>\u5b64\u513f\u5173\u7cfb\u8fc7\u6ee4<\/td>\n<\/tr>\n<tr>\n<td><code>index\/operations\/summarize_descriptions\/<\/code><\/td>\n<td>\u63cf\u8ff0\u6458\u8981\uff08\u4ec5\u5904\u7406\u5df2\u5408\u5e76\u5b9e\u4f53\uff09<\/td>\n<\/tr>\n<tr>\n<td><code>index\/workflows\/extract_graph.py<\/code><\/td>\n<td>\u63d0\u53d6 workflow \u7f16\u6392<\/td>\n<\/tr>\n<tr>\n<td><code>index\/workflows\/finalize_graph.py<\/code><\/td>\n<td>\u56fe\u8c31\u6700\u7ec8\u5316\uff08degree \u8ba1\u7b97\u3001\u53bb\u91cd\uff09<\/td>\n<\/tr>\n<tr>\n<td><code>index\/operations\/finalize_entities.py<\/code><\/td>\n<td>\u5b9e\u4f53\u6700\u7ec8\u5316\uff08\u6309 title \u53bb\u91cd\uff09<\/td>\n<\/tr>\n<tr>\n<td><code>query\/context_builder\/entity_extraction.py<\/code><\/td>\n<td>\u67e5\u8be2\u65f6\u5b9e\u4f53\u5339\u914d<\/td>\n<\/tr>\n<tr>\n<td><code>index\/utils\/string.py<\/code><\/td>\n<td><code>clean_str()<\/code> \u5b57\u7b26\u4e32\u6e05\u6d17<\/td>\n<\/tr>\n<tr>\n<td><code>prompt_tune\/template\/extract_graph.py<\/code><\/td>\n<td>\u53ef\u8c03\u4f18\u7684\u63d0\u53d6 prompt \u6a21\u677f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>1. \u95ee\u9898\u6982\u8ff0 GraphRAG \u5728\u5b9e\u4f53\u63d0\u53d6\u9636\u6bb5\uff0c\u5c06\u540c\u4e00\u5b9e\u4f53\u7684\u4e0d\u540c\u522b\u540d\u89c6\u4e3a\u72ec\u7acb\u5b9e\u4f53\uff0c\u5bfc\u81f4\u77e5\u8bc6\u56fe\u8c31\u4e2d\u51fa\u73b0\u5b9e\u4f53\u788e\u7247 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[60,68,67,61,104,103,62],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-graphrag","tag-graphrag","tag-llm","tag-ner","tag-rag","tag-104","tag-103","tag-62"],"_links":{"self":[{"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":0,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"wp:attachment":[{"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}