【GraphRAG】微软 graphrag 效果实测

GraphRAG

本文将基于以下来源,对Microsoft GraphRAG分析优缺点、以及示例实测分析。

1. Source

代码仓库:

Welcome to GraphRAGicon-default.png?t=N7T8https://microsoft.github.io/graphrag/

微软文章1(2024.2.13):GraphRAG: Unlocking LLM discovery on narrative private data

Microsoft First Blogicon-default.png?t=N7T8https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/

微软文章2(2024.7.2):GraphRAG: New tool for complex data discovery now on GitHub

Second Blogicon-default.png?t=N7T8https://www.microsoft.com/en-us/research/blog/graphrag-new-tool-for-complex-data-discovery-now-on-github/

论文:

From Local to Globalicon-default.png?t=N7T8https://arxiv.org/pdf/2404.16130

2. Advantages

使用新闻文章中的暴力事件信息(VIINA)数据集进行调查。选择此数据集是因为其复杂性以及存在不同意见和部分信息。这是一个混乱的现实世界测试用例,它是最近才出现的,不包括在LLM基础模型的训练中。

这里平分秋色,但是追加一步的提问,由于不存在对应的直接上下文,所以Baseline没检索到。

除了论文中提到的相对性比较之外,还使用SelfCheckGPT对可信度进行绝对测量,以帮助确保基于源材料的事实、连贯的结果。结果表明,GraphRAG的忠实度与基线RAG相似。

而在7月的文章中,再次强调:

当在社区层次结构的任何级别使用社区摘要时,GraphRAG在全面性和多样性方面都优于朴素的RAG(约70-80%的获胜率)。

使用中级和低级社区摘要的GraphRAG在这些指标上也比源文本摘要表现更好,token成本更低(每次查询约20-70%的令牌使用率)。性能与最高级别社区的分层源文本摘要具有竞争力,令牌成本大大降低(每次查询约2-3%的令牌使用率)。如图所示。


翻译一下就是:

问题:哪些公众人物在各种娱乐文章中被反复提及?

简单 RAG 回复

被反复提及的公众人物包括<公众人物1, 2, 3和4>。这些人物因各种原因被突出,从他们的职业成就到个人生活。

  • <公众人物1> [...]
  • <公众人物2> [...]
  • <公众人物3> [...]
  • <公众人物4> [...]

这些人物因其高调的地位和公众对其职业和个人生活的兴趣而频繁被报道。他们的活动,无论是在音乐、体育还是个人关系中,都具有显著的文化和经济影响,媒体报道和公众反应证明了这一点。

GraphRAG 回复

娱乐行业广泛且多样,涵盖电影、电视、音乐、体育和数字媒体。某些公众人物由于在这些领域中的重要贡献和影响力而脱颖而出。以下总结了在各种娱乐文章中反复提及的重要人物,反映了他们在行业中的影响力和存在感。

  • 演员和导演 [... 20个人物 ...]
  • 争议中的公众人物 [... 3个人物 ...]
  • 音乐家和高管 [... 5个人物 ...]
  • 运动员和教练 [... 7个人物 ...]
  • 影响者和企业家 [... 3个人物 ...]

这些人物在娱乐文章中反复提及,表明了他们的持续相关性以及公众对其工作的兴趣。他们的影响跨越了娱乐的各个方面,从塑造电影和电视中的文化叙事到推动音乐和数字媒体中的趋势。这些人物不仅在其各自的领域中做出贡献,而且还影响了更广泛的文化景观,常常成为社会讨论和公众话题的中心人物。


3. Limitations

Indexing is a relatively expensive operation;

虽然单次的查询成本降低了,但是建立 索引(或者说是图谱) 超级烧钱!

GraphRAG depends on a well-constructed indexing examples. For general applications (e.g. content oriented around people, places, organizations, things, etc.) we provide example indexing prompts. For unique datasets effective indexing can depend on proper identification of domain-specific concepts.

GraphRAG依赖于构造良好的索引示例。对于通用应用程序(例如,围绕人物、地点、组织、事物等进行的内容),我们提供示例索引提示。对于独特的数据集,有效的索引可能取决于对特定领域概念的适当识别。

不仅文章中提及了,论文中也有数据说明,其中的token消耗,虽然每个社区相比TS的消耗占比较少,但是每次建立索引构建出4层,消耗依旧是巨大的:


4. 示例demo 运行结果

论文的核心流程如下,使用的流程主要分为 建立索引的Indexing Time以及查询提问的Query Time.

4.1 建立索引(图谱)

我们输入约4.5万字符的《圣诞颂歌》(一本书.txt),包括空格,但是不包括空行。

《圣诞颂歌》的故事剧情在文章结尾附录处,有需要也可以先瞄一眼。

按照 chunk_size = 300 、 overlap = 100

最后拆成 230个300字符的chunk + 单个155字符chunk = 69155 字符 的文档块

抽取416个实体

分四个level,1664的最终节点,73个communities。

508条关系

我们用豆包Doubao-pro-128k替换了原本OpenAI的LLM,embedding模型选择azure_openai_embedding的text-embedding-ada-002,生成索引结束后查看了token的用量统计。

烧了95万的token!当然,也看到其他人用原生的API(加上embedding的消耗),烧了105万,7$.

根据论文生成的节点和边的关系,简单估算论文在Podcast的节点和边的数目,预计1400$ 以上?

不过文章也指出了缓解之法,就是在小规模数据集上测测性能,再迁移到大规模的数据集上。

How can users minimize the impact of GraphRAG’s limitations when using the system?

a best practice to mitigate indexing is to create a small test dataset in the target domain to ensure indexer performance prior to large indexing operations.

ps: 选择生成的LLM模型最好能够支持32k及以上的上下文,因为默认的prompt特别长,即便是chunk大小设置了300,构建节点的时候至少会出现6k的输入,一开始选择的模型能力仅有4k,导致报错。

8k的没有测试过,但是默认的entity_extraction.txt内部的prompt(few shot),算上空格空行,存在10835个字符!

4.2 全局性询问

不同query方法的框架流程介绍放在下一篇讲解,这里我们先展示效果。

我们进行了示例的全局性测试,询问两次:

python -m graphrag.query --root ./ragtest --method global "What are the top themes in this story?"

不知道是豆包能力不足还是其他原因,感觉倾向于根据节点来回复。(有点僵硬!)

method 改local,再次问询主题:

python -m graphrag.query --root ./ragtest --method local "What are the top themes in this story?"
SUCCESS: Local Search Response: In this story, several themes are prominent. One of the main themes is Scrooge's transformation. Initially, Scrooge is shown to be a harsh employer, with a negative attitude towards Christmas and his fellow human beings. However, through his encounters with various ghosts and his experiences, he undergoes a significant change and decides to improve his behavior and outlook on life [Data: Relationships (37, 72, 73, 75, 16, 18, 17, 127, 129); Entities (60)].

Another theme is the significance of Christmas. It is initially not a favored holiday by Scrooge, but his interactions with the ghosts and his various experiences lead him to have a more positive view of Christmas, emphasizing its importance as a time of kindness, forgiveness, and charity [Data: Relationships (37, 285, 286, 313, 336); Entities (60)].

The theme of death and its implications is also present. Scrooge is affected by the man's death and is shown various aspects related to it. This event has various implications and is connected to other characters and the spirit [Data: Relationships (159, 337, 376); Entities (354)].

The story also explores the theme of family and relationships. Scrooge has relationships with his nephew and other family members, and his attitude towards them changes over the course of the story. Additionally, the Cratchit family is depicted, with their interactions and celebrations around Christmas [Data: Relationships (14, 19, 286, 427, 428); Entities (60)].

Finally, the theme of employer-employee relationships is evident. Scrooge's relationship with his employees, such as Bob Cratchit, is complex. Initially, he is a harsh employer, but he later decides to improve their working conditions and salaries [Data: Relationships (127, 129)].

这个生成虽然也有根据节点关系生成的内容,但是相比global,更加自然,翻译过来如下:


在这个故事中,几个主题是突出的。其中一个主要主题是斯克鲁奇的转变。一开始,斯克鲁奇是一个严厉的雇主,对圣诞节和他的人类同胞持消极态度。然而,通过他与各种鬼魂的相遇和他的经历,他经历了一个重大的变化,并决定改善他的行为和人生观[数据:关系(37,72,73,75,16,18,17,127,129);实体(60)]。

另一个主题是圣诞节的重要性。起初,斯克鲁奇并不喜欢圣诞节,但他与鬼魂的互动以及他的各种经历使他对圣诞节有了更积极的看法,强调了圣诞节作为一个善良、宽恕和慈善的时刻的重要性[数据:关系(37,285,286,313,336);实体(60)]。

死亡的主题和它的含义也存在。斯克罗吉受到了这个人的死的影响,并被展示了与之相关的各个方面。这一事件具有各种含义,并与其他角色和精神相关联[数据:关系(159,337,376);实体(354)]。

故事还探讨了家庭和关系的主题。斯克鲁奇与他的侄子和其他家庭成员有关系,他对他们的态度随着故事的发展而改变。此外,Cratchit家族也被描绘成圣诞节前后的互动和庆祝活动[数据:Relationships (14, 19, 286, 427, 428);实体(60)]。

最后,雇主-雇员关系的主题是显而易见的。斯克鲁奇与他的雇员,如鲍勃·克拉特基特,关系复杂。最初,他是一个苛刻的雇主,但他后来决定改善他们的工作条件和工资[数据:关系(127,129)]。


4.3 局部信息提问

现在测试local的示例提问。

python -m graphrag.query \
--root ./ragtest \
--method local \
"Who is Scrooge, and what are his main relationships?"
SUCCESS: Local Search Response: Scrooge is the main character in 'A Christmas Carol'. He is initially described as a caustic, cold, grumpy, and cynical old sinner who is rich, tight-fisted, covetous, and against the celebration of Christmas. However, throughout the story, he undergoes a positive transformation.

Scrooge has several important relationships:
- **Employer-Employee Relationships**: Scrooge is the employer of Bob Cratchit. Initially, he is a harsh employer, but later decides to improve Bob's working conditions and salary [Data: Relationships (127, 129)].
- **Interaction with Ghosts**: Scrooge has significant interactions with various ghosts, including Marley's Ghost and the Ghosts of Christmas Past, Present, and Yet to Come. These encounters have a profound impact on his character and worldview [Data: Relationships (72, 73, 75, 16, 18, 17)].
- **Family Connections**: Scrooge is the uncle of his nephew (referred to as Scrooge's Nephew, Fred, Your Nephew, and The Nephew in different contexts). His initial attitude towards them is not particularly warm, but this changes over the course of his experiences [Data: Relationships (34, 14, 19, 180, 216)].
- **Relationship with Christmas**: Scrooge initially has a negative attitude towards Christmas, but his encounters with the ghosts and various experiences lead him to have a more positive view of the holiday [Data: Relationships (37, 126)].
- **Old Friend and Former Partner**: Scrooge has an old friend Belle and was a partner with Jacob Marley [Data: Relationships (116, 70, 20)].
- **Fellow Apprentice**: Scrooge was a fellow apprentice with Dick Wilkins [Data: Relationship (109)].

非常nice的回答:


斯克鲁奇是《圣诞颂歌》中的主角。他最初被描述为一个刻薄、冷漠、脾气暴躁、愤世嫉俗的老罪人,他富有、吝啬、贪婪,反对庆祝圣诞节。然而,在整个故事中,他经历了一个积极的转变。

斯克鲁奇有几个重要的关系:

  • 雇主-雇员关系:斯克罗吉是鲍勃·克拉特基特的雇主。最初,他是一个苛刻的雇主,但后来决定改善鲍勃的工作条件和工资[数据:关系(127,129)]。
  • 与鬼魂的互动:斯克鲁奇与各种鬼魂有重要的互动,包括马利的鬼魂和圣诞节过去,现在和未来的鬼魂。这些遭遇对他的性格和世界观产生了深远的影响[数据:关系(72,73,75,16,18,17)]。
  • 家庭关系:斯克鲁奇是他侄子的叔叔(在不同的语境中被称为斯克鲁奇的侄子、弗雷德、你的侄子和侄子)。他最初对他们的态度不是特别热情,但随着他的经历,这种态度发生了变化[数据:关系(34,14,19,180,216)]。
  • 与圣诞节的关系:斯克鲁奇最初对圣诞节持消极态度,但他与鬼魂的接触和各种经历使他对圣诞节有了更积极的看法[数据:关系(37,126)]。
  • 老朋友和前合伙人:斯克鲁奇有一个老朋友贝尔,是雅各布·马利的合伙人[数据:关系(116,70,20)]。
  • 徒弟:斯克罗吉是迪克威尔金斯的徒弟[数据:关系(109)]。

换成global的method进行对比:

SUCCESS: Global Search Response: **Scrooge**

Scrooge is a central figure in various communities. Here are his main relationships and associated details:

**Employer-Employee Relationships**:
- He is the employer of The Clerk [Data: Reports (43)].
- He is also the employer of Bob Cratchit [Data: Reports (61, 67, 62, 37, 44, 9) +more].

**Family Relationships**:
- He has a strained relationship with his nephew [Data: Reports (49)].
- He has a sister named Fan [Data: Reports (9, 61)].

**Business Partnerships**:
- Jacob Marley was his partner [Data: Reports (63)].

**Spiritual Encounters**:
- He is associated with the Spirit, with whom he has various discussions and is highly influenced [Data: Reports (26)].
- He has significant interactions with various ghosts, including Marley's Ghost and the Ghosts of Christmas Past, Present, and Yet to Come [Data: Reports (61, 67, 62, 37, 44, 9) +more].

**Connections to Other Characters and Events**:
- He is associated with the Cratchit family, particularly Tiny Tim [Data: Reports (34)].
- He is involved in events related to Christmas Day. He is associated with the Bakers and the Dinner-Carriers on this day [Data: Reports (31)].
- He is also connected to the Ghost of Christmas Present, who shows him the present and blesses Bob Cratchit's house [Data: Reports (24)].
- He has a former relationship with old friend Belle and fellow apprentice Dick Wilkins. The Husband saw Scrooge and informed his wife Belle [Data: Reports (9, 61)].

斯克鲁奇是多个

社区的核心人物。以下是他主要的关系及相关细节:

雇主-雇员关系:

  • 他是职员的雇主 [数据:报告 (43)]。
  • 他也是鲍勃·克拉奇特的雇主 [数据:报告 (61, 67, 62, 37, 44, 9) +更多]。

家庭关系:

  • 他与侄子的关系紧张 [数据:报告 (49)]。
  • 他有一个叫范的妹妹 [数据:报告 (9, 61)]。

商业合作关系:

  • 雅各布·马利是他的合伙人 [数据:报告 (63)]。

灵性遭遇:

  • 他与幽灵有各种讨论,并深受其影响 [数据:报告 (26)]。
  • 他与多个幽灵有重要互动,包括马利的幽灵和过去、现在及未来的圣诞幽灵 [数据:报告 (61, 67, 62, 37, 44, 9) +更多]。

与其他角色和事件的联系:

  • 他与克拉奇特一家,特别是小蒂姆有关联 [数据:报告 (34)]。
  • 他参与了与圣诞节相关的事件,特别是与当天的面包师和送餐员有关 [数据:报告 (31)]。
  • 他还与现在的圣诞幽灵有关,幽灵向他展示了现在,并祝福了鲍勃·克拉奇特的家 [数据:报告 (24)]。
  • 他与旧友贝尔和学徒迪克·威尔金斯有过往关系。丈夫见到了斯克鲁奇并告知妻子贝尔 [数据:报告 (9, 61)]。

这本书开头有一个角色表,为了验证是否是角色表泄露太多,这里也翻译看看。

CHARACTERS

Bob Cratchit, clerk to Ebenezer Scrooge.
Peter Cratchit, a son of the preceding.
Tim Cratchit ("Tiny Tim"), a cripple, youngest son of Bob Cratchit.
Mr. Fezziwig, a kind-hearted, jovial old merchant.
Fred, Scrooge's nephew.

Ghost of Christmas Past, a phantom showing things past.
Ghost of Christmas Present, a spirit of a kind, generous,and hearty nature.
Ghost of Christmas Yet to Come, an apparition showing the shadows of things which yet may happen.
Ghost of Jacob Marley, a spectre of Scrooge's former partner in business.

Joe, a marine-store dealer and receiver of stolen goods.
Ebenezer Scrooge, a grasping, covetous old man, the surviving partner of the firm of Scrooge and Marley.
Mr. Topper, a bachelor.
Dick Wilkins, a fellow apprentice of Scrooge's.

Belle, a comely matron, an old sweetheart of Scrooge's.
Caroline, wife of one of Scrooge's debtors.
Mrs. Cratchit, wife of Bob Cratchit.
Belinda and Martha Cratchit, daughters of the preceding.

Mrs. Dilber, a laundress.
Fan, the sister of Scrooge.
Mrs. Fezziwig, the worthy partner of Mr. Fezziwig.

角色

鲍勃·克拉奇特,埃比尼泽·斯克鲁奇的职员。 彼得·克拉奇特,前者之子。 蒂姆·克拉奇特(简称“小蒂姆”),一个跛子,鲍勃·克拉奇特的幼子。 费泽威格先生,一位善良、快活的老商人。 弗雷德,斯克鲁奇的侄子。

圣诞节过去的幽灵,展示过去的事物。 圣诞节现在的幽灵,一个善良、慷慨、热忱的幽灵。 圣诞节未来的幽灵,展示将来可能发生的事物。 雅各布·马利的鬼魂,斯克鲁奇生意上的前合伙人。

乔,一家船舶用品商和盗窃物品的接收人。 埃比尼泽·斯克鲁奇,一个贪婪、贪得无厌的老头,是斯克鲁奇和马利公司的幸存的合伙人。 陶普先生,一个单身汉。 迪克·威尔金斯,斯克鲁奇的一个学徒。

贝尔,一个漂亮的已婚妇女,是斯克鲁奇的一个旧情人。 卡罗琳,斯克鲁奇一个债务人的妻子。 克拉奇特夫人,鲍勃·克拉奇特夫人。 贝琳达和玛莎·克拉奇特,前者的女儿。

迪尔伯夫人,一位洗衣女工。 范,斯克鲁奇的一个妹妹。 费泽威格夫人,费泽威格先生的贤内助。


感觉除了身份定位,并不会泄露太多。

5. 总结

  • 如果不是local和global的含义错了,即便是local的似乎也能进行全局性总结?
  • local的生成比global的生成更加自然。
  • 如果以博客内容为准,也可能是因为复用同一个处理摘要总结时候的prompt,但是GPT4和豆包对这个prompt的响应敏感程度和生成倾向不同。

6. 附录-圣诞颂歌 剧情简介

《A Christmas Carol》的具体剧情分为五个部分,分别称为“五个章节”(Staves),以下是每个章节的详细剧情:

第一章:斯克鲁奇的幽灵(Marley's Ghost)

故事开始于平安夜,吝啬刻薄的商人埃比尼泽·斯克鲁奇在伦敦的办公室里。他冷酷无情,对圣诞节毫无兴趣,对慈善和人情味毫不在意。当他的侄子弗雷德(Fred)来邀请他共度圣诞节时,斯克鲁奇粗暴地拒绝了。晚上回到家后,斯克鲁奇遇到了他已故合伙人雅各布·马利(Jacob Marley)的幽灵。马利告诉斯克鲁奇,他将被三个圣诞幽灵拜访,警告他如果不改变自己的行为,将在死后面临同样的悲惨命运。

第二章:过去的圣诞幽灵(The First of the Three Spirits)

第一个幽灵出现了——过去的圣诞幽灵(Ghost of Christmas Past)。这个幽灵带着斯克鲁奇回到了他的童年、青年和早年的职业生涯。斯克鲁奇看到了自己曾经的快乐时光,尤其是与他深爱的贝尔(Belle)的关系。然而,由于对金钱的贪婪,斯克鲁奇最终失去了贝尔。看到这些往事,斯克鲁奇深感痛苦和悔恨。

第三章:现在的圣诞幽灵(The Second of the Three Spirits)

第二个幽灵——现在的圣诞幽灵(Ghost of Christmas Present)带领斯克鲁奇参观了他同时代人的圣诞节庆祝活动。斯克鲁奇看到了他的店员鲍勃·克拉奇特(Bob Cratchit)一家尽管贫穷却充满温暖和爱,尤其是病弱的小蒂姆(Tiny Tim)。幽灵还展示了他侄子弗雷德的圣诞聚会,斯克鲁奇看到了自己被嘲笑和怜悯。通过这些经历,斯克鲁奇逐渐开始理解爱与同情的重要性。

第四章:未来的圣诞幽灵(The Last of the Spirits)

最后一个幽灵——未来的圣诞幽灵(Ghost of Christmas Yet to Come)出现了。这个幽灵带斯克鲁奇看到了他可能的未来:他的死亡。没有人悲伤,没有人关心他的去世。他看到了克拉奇特一家失去小蒂姆的痛苦,也看到了自己被遗忘和被嘲笑的结局。斯克鲁奇被这些景象吓坏了,恳求有机会改变自己的命运。

第五章:终章(The End of It)

在经历了三个幽灵的拜访后,斯克鲁奇醒来发现自己仍然活着,而且是圣诞节早晨。他深受感动,决定改变自己的一生。他变得慷慨和善良,帮助了克拉奇特一家,尤其是小蒂姆,并开始积极参与慈善事业。他还与侄子弗雷德重修旧好,变成了一个受到大家喜爱和尊敬的人。

这本书以斯克鲁奇的转变为核心,展示了爱、同情和社会责任的重要性。狄更斯通过这个故事传达了善行和仁爱可以带来个人和社会的巨大变化。

相关推荐

  1. <span style='color:red;'>GraphSAGE</span>

    GraphSAGE

    2024-07-18 06:24:03      51 阅读
  2. GraphRAG实践

    2024-07-18 06:24:03       14 阅读
  3. GraphSAGE项目练手

    2024-07-18 06:24:03       22 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 06:24:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 06:24:03       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 06:24:03       58 阅读
  4. Python语言-面向对象

    2024-07-18 06:24:03       69 阅读

热门阅读

  1. mysql 安装配置 next 按钮为什么置灰点击不了

    2024-07-18 06:24:03       23 阅读
  2. Eureka: 分布式系统中的服务发现与注册中心

    2024-07-18 06:24:03       22 阅读
  3. 知识图谱数据模型

    2024-07-18 06:24:03       26 阅读
  4. 服务自旋:Eureka中实现服务的动态注册与注销

    2024-07-18 06:24:03       24 阅读
  5. kafka-client如何打印连接日志

    2024-07-18 06:24:03       27 阅读
  6. 构建Web应用的秘诀:Gradle中的Web应用插件配置

    2024-07-18 06:24:03       23 阅读