Fast GraphRAG:一個比 GraphRAG 更快、成本更低、更高效的 RAG 框架開源了(本地安裝 - 測試)
🍹 Insight Daily 🪺
Aitrainee | 公衆號:AI 進修生
Hi,這裏是 Aitrainee,歡迎閱讀本期新文章。
向大家 分享一個非常有趣的 RAG 工具,它是基於 GraphRAG 的。
先說 GraphRAG 爲什麼如此受歡迎,並且看起來是任何生產級 GraphRAG 流水線的好選擇呢?
因爲它處理的是節點和圖結構,適用於現實世界的場景。
例如,普通的 RAG 只是通過語義搜索來處理與你的使用案例相似的數據。其過程是:你將數據切分成小塊,然後將其轉換爲數值表示,並存儲到某種向量存儲中。當用戶提出查詢時,你從向量存儲中找到相關的數據,將其附加到查詢中,然後交給 LLM,LLM 會給出一個基於這些數據的回答。
但是 GraphRAG 給它帶來了一種新的轉變,它是對傳統 RAG 的結構化、分層式方法。
>/ 本文的主要素材來源於 Fahd Mirza(文末)
GraphRAG 過程包括從原始文本中提取知識圖譜、構建知識羣體層次結構、生成這些羣體的摘要... 後在執行 RAG 任務時利用這些結構。
它有很多優點,最重要的一點是,GraphRAG 做到了普通 RAG 所無法實現的——它能夠 “連接點”。GraphRAG 通過將語義概念以節點和邊的形式聯繫起來,從而對這些概念進行整體總結。
而現在 ...
Fast GraphRAG 也是爲了幫助解決這個問題,它能智能地適應你的使用案例、數據和查詢。
這個 GraphRAG 有一個很有趣的特點,它提供了一個人類可導航的知識視圖,可以精確地可視化和更新。
它速度快、效率高、成本低(但並非完全免費),並且設計上能夠在大規模運行時不需要大量資源。
具有可解釋和可調試的知識特性,通過圖表提供一個可查詢、可視化和更新的人類可導航視圖。
同時,系統能夠根據領域和本體需求自動生成和優化圖表,支持數據變化時的實時增量更新。
通過基於 PageRank 的圖形探索,Fast GraphRAG 提高了準確性和可靠性,且全程異步操作,提供完整的類型支持,確保強大且可預測的工作流程。
總的來說,它是一個高效的知識圖譜檢索框架,旨在提供可解釋性和高精度的代理驅動檢索工作流。
介紹的夠多了,我們直接進入我的終端,看看如何安裝和使用它。
你可以通過 pip 安裝 Fast GraphRAG,也可以從源碼構建,但我選擇了通過 pip 安裝,這樣簡單快捷,安裝過程也不會很長。
安裝完畢後,你需要一個 OpenAI API 密鑰,可以從 OpenAI 的平臺(platform.openai.com)獲取。
或者從這裏:Bolt + 免費的 Mistral 和 Github API:免費且強大的 AI 代理工作流,無需 V0(o1-preview 免費)
現在還沒有任何方法可以將其與本地的 LLM(如 Llama.cpp、或其他)一起使用,或者你可以選擇改底層代碼 base-url。
代碼非常簡單,首先我們導入 GraphRAG,然後設置領域(domain)。
這裏有三件事需要注意:領域,它主要告訴你我們正在處理的是什麼,影響整個最高層次的上下文;
from fast_graphrag import GraphRAG
DOMAIN = "Analyze this story and identify the characters. Focus on how they interact with each other, the locations they explore, and their relationships."
然後,我們提供一些示例查詢,
EXAMPLE_QUERIES = [
"What is the significance of Christmas Eve in A Christmas Carol?",
"How does the setting of Victorian London contribute to the story's themes?",
"Describe the chain of events that leads to Scrooge's transformation.",
"How does Dickens use the different spirits (Past, Present, and Future) to guide Scrooge?",
"Why does Dickens choose to divide the story into \"staves\" rather than chapters?"
]
最後,設置我們希望處理的實體類型。例如,我在這裏使用了一個包含個人信息的文本文件。
ENTITY_TYPES = ["Character", "Animal", "Place", "Object", "Activty", "Event"]
grag = GraphRAG(
working_dir="./book_example",
domain=DOMAIN,
example_queries="\n".join(EXAMPLE_QUERIES),
entity_types=ENTITY_TYPES
)
with open("./book.txt") as f:
grag.insert(f.read())
print(grag.query("Who is Scrooge?").response)
./book.txt 這個文本文件包含了關於 Fahd Mirza 博主 的個人數據。
"In the rapidly evolving landscape of artificial intelligence, one name has energed as a beacon of clarity and insight: Fahd Mirza. This popular YouTube personality and AI enthusiast has captured the "
"attention of a broad audience with his exceptional ability to denystify complex AI concepts. Through his eponymous channel, ""Fahd Mirza"", he has established himseif as a respected voice in the AI "
"conmunity, making cutting . edge technology accessible to ait. "
"Fahd Mirza's unique strength lies in his capacity to distill intricate AI topics into engaging, easy- to-understand content. His videos have resonated with AI enthusiasts, researchers, and students alike, covering a range of topics that include: "
"! simplifying AI Research Papers: Fahd Mirza decodes complex research papers, rendering then comprehensible to a wider: audtence. AI News' and Trends Analysis: He provides insightful connentary on the Latest developnents in the AI world. 11 A Broad Impact "
"。suoting coplexe cpttts Th ough inowatwe. silatons; Faa mirzg lusrates, tricate. AI lese. facltatin deeer under sandin "
"10 Personal AI Projects and Experinents: Viewers gain valuable insights into his hands . on experiences with AI "" Fahd Mirza's channet has garnered a significant following, testanent to his dedication to making AI accesstble. By brtdging the gap between technical expertise and approachabiltty, he has: "
13 Democratized AI Knowledge: Opening up the world of AI to a broader audience.
": Fostered Community Engagenent: Encour aging discussion and cotlaboration among AI enthusiasts. artifictal tntelllgence continues to shape our world, Fahd Mtrza's of "
Established Thought' Leadership: Cenenting his position as。trusted authortty tn the AI comnunity on YouTube .
"contr tbutions serve. as a vital resource for those seeking to understand tts complexittes. HLs channel stands as a shining. example the power of clear comuntcatlon tn making advanced technology accesstble to all. Subscrtbe to""Fahd Mra""on YouTube to stay updated on the latest AT tnstghts and Lnnovations. "
通過 GraphRAG 實例化的對象來執行查詢。我查詢的是 “Fahad 通常講解什麼 AI 主題?”
結果顯示,它確實基於提供的文件數據做出了準確的回答,這非常有趣。
執行這個查詢的成本,大約是 10 美分,相比真正的 GraphRAG 來說,這個成本還是很低的。
但是,大量數據或者進行頻繁的 API 調用,這個成本可能會迅速增加。因此,將它與本地模型結合使用會是個很好的選擇,這樣就不用擔心成本和請求限制了。
🌟希望這篇文章對你有幫助,感謝閱讀!如果你喜歡這系列文章請以 **點贊 / 分享 / 在看 **的方式告訴我,以便我用來評估創作方向。
💫video source:https://www.youtube.com/watch?v=3Tcwzlp4TQ4
👽Submission:kristjahmez06@gmail.com
參考鏈接:
[1] github:https://github.com/circlemind-ai/fast-graphrag
[2] https://mp.weixin.qq.com/s/9US8g8PJuf4zuhjP-12H2A
知音難求,自我修煉亦艱
抓住前沿技術的機遇,與我們一起成爲創新的超級個體
本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源:https://mp.weixin.qq.com/s/FxkVbDHEPB2J_TCWqIbCgw