精品欧美一区二区三区在线观看 _久久久久国色av免费观看性色_国产精品久久在线观看_亚洲第一综合网站_91精品又粗又猛又爽_小泽玛利亚一区二区免费_91亚洲精品国偷拍自产在线观看 _久久精品视频在线播放_美女精品久久久_欧美日韩国产成人在线

GraphRAG結(jié)合普通RAG,打造Hybrid RAG

發(fā)布于 2024-12-17 13:12
瀏覽
0收藏

RAG在生成式AI領(lǐng)域取得了重大進(jìn)展,用戶可以將自己的個人文檔,比如文本文件、PDF、視頻等,與大型語言模型(LLMs)連接起來進(jìn)行互動。最近,RAG的進(jìn)階版GraphRAG也亮相了,它通過知識圖譜和LLMs來執(zhí)行RAG的檢索任務(wù)。

RAG和GraphRAG各有所長,也各有局限。RAG擅長利用向量相似性技術(shù),而GraphRAG則依賴圖分析和知識圖譜來提供更精確的答案。那么,如果將兩者結(jié)合起來進(jìn)行檢索,會擦出怎樣的火花呢?

1 HybridRAG

HybridRAG是一個高級框架,它合并了RAG和GraphRAG。這種集成旨在提高信息檢索的準(zhǔn)確性和上下文相關(guān)性。簡單來說,HybridRAG使用來自兩個檢索系統(tǒng)(RAG和GraphRAG)的上下文,最終輸出是兩個系統(tǒng)的混合。

2 HybridRAG的優(yōu)勢

  • 提高準(zhǔn)確性:通過利用結(jié)構(gòu)化推理和靈活檢索,HybridRAG提供的答案比單獨(dú)使用VectorRAG或GraphRAG更精確。
  • 增強(qiáng)上下文理解:通過整合不同系統(tǒng),HybridRAG能更深入地理解實(shí)體間的關(guān)系及其出現(xiàn)的上下文。
  • 動態(tài)推理能力:知識圖譜可以動態(tài)更新,使系統(tǒng)能夠適應(yīng)新信息的可用性。

3 使用LangChain來構(gòu)建HybridRAG系統(tǒng)

這里使用一個名為“Moon.txt”的文件進(jìn)行這個演示,這是一個超級英雄故事。請查看以下內(nèi)容。

In the bustling city of Lunaris, where the streets sparkled with neon lights and the moon hung low in the sky, lived an unassuming young man named Max. By day, he was a mild-mannered astronomer, spending his hours studying the stars and dreaming of adventures beyond Earth. But as the sun dipped below the horizon, Max transformed into something extraordinary—Moon Man, the guardian of the night sky.
Max’s transformation began with a mysterious encounter. One fateful evening, while gazing through his telescope, a brilliant flash of light erupted from the moon. A celestial being, shimmering with silver light, descended and bestowed upon him a magical amulet. “With this, you shall harness the power of the moon,” the being declared. “Use it wisely, for the night sky needs a hero.”
With the amulet around his neck, Max felt energy coursing through him. He could leap great distances, manipulate moonlight, and even communicate with nocturnal creatures. He vowed to protect his city from the shadows that lurked in the night.
As Moon Man, Max donned a sleek, silver suit adorned with celestial patterns that glimmered like the stars. With his newfound abilities, he patrolled the city, rescuing lost pets, helping stranded motorists, and even thwarting petty criminals. The citizens of Lunaris began to whisper tales of their mysterious hero, who appeared under the glow of the moon.
One night, as he soared through the sky, he encountered a gang of thieves attempting to steal a priceless artifact from the Lunaris Museum. With a flick of his wrist, he summoned a beam of moonlight that blinded the thieves, allowing him to swoop in and apprehend them. The city erupted in cheers, and Moon Man became a beloved figure.
However, peace in Lunaris was short-lived. A dark force emerged from the depths of the cosmos—an evil sorceress named Umbra, who sought to extinguish the moon’s light and plunge the world into eternal darkness. With her army of shadow creatures, she began to wreak havoc, stealing the moon’s energy and spreading fear among the citizens.
Moon Man knew he had to confront this new threat. He gathered his courage and sought the wisdom of the celestial being who had granted him his powers. “To defeat Umbra, you must harness the full power of the moon,” the being advised. “Only then can you restore balance to the night sky.”
With determination in his heart, Moon Man prepared for the ultimate battle. He climbed to the highest peak in Lunaris, where the moon shone brightest, and focused on channeling its energy. As Umbra and her shadow creatures descended upon the city, Moon Man unleashed a magnificent wave of moonlight, illuminating the darkness.
The battle raged on, with Umbra conjuring storms of shadows and Moon Man countering with beams of silver light. The clash of powers lit up the night sky, creating a dazzling display that captivated the citizens below. In a final, desperate move, Moon Man summoned all his strength and unleashed a powerful blast of moonlight that enveloped Umbra, banishing her to the farthest reaches of the cosmos.
With Umbra defeated, the moon’s light returned to its full glory, and the city of Lunaris rejoiced. Max, still in his Moon Man guise, stood atop the highest building, watching as the citizens celebrated their hero. They had learned the importance of hope and courage, even in the darkest of times.
From that day forward, Moon Man became a symbol of resilience and bravery. Max continued to protect Lunaris, knowing that as long as the moon shone brightly, he would always be there to guard the night sky. And so, the legend of Moon Man lived on, inspiring generations to look up at the stars and believe in the extraordinary.
As the years passed, stories of Moon Man spread beyond Lunaris, becoming a beacon of hope for those who felt lost in the darkness. Children would gaze at the moon, dreaming of adventures, and Max would smile, knowing that he had made a difference. For in the heart of every dreamer, the spirit of Moon Man lived on, reminding them that even the smallest light can shine brightly against the shadows.

導(dǎo)入包并設(shè)置LLM端嵌入模型(用于標(biāo)準(zhǔn)RAG)

import os
from langchain_experimental.graph_transformers import LLMGraphTransformer
from langchain_core.documents import Document
from langchain_community.graphs.networkx_graph import NetworkxEntityGraph
from langchain.chains import GraphQAChain
from langchain.text_splitter import CharacterTextSplitter
from langchain.document_loaders import TextLoader
from langchain.chains import RetrievalQA
from langchain.vectorstores import Chroma
from langchain_google_genai import GoogleGenerativeAI,GoogleGenerativeAIEmbeddings

GOOGLE_API_KEY=''

embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001",google_api_key=GOOGLE_API_KEY)
llm = GoogleGenerativeAI(model="gemini-pro",google_api_key=GOOGLE_API_KEY)

接者,為GraphRAG實(shí)現(xiàn)(鏈對象)創(chuàng)建函數(shù),覆蓋文件“Moon.txt”

def graphrag():
    with open('Moon.txt', 'r') as file:
        content = file.read()

    documents = [Document(page_content=content)]
    llm_transformer = LLMGraphTransformer(llm=llm)
    graph_documents = llm_transformer.convert_to_graph_documents(documents)

    graph = NetworkxEntityGraph()

    # 添加節(jié)點(diǎn)到圖
    for node in graph_documents[0].nodes:
        graph.add_node(node.id)

    # 添加邊到圖
    for edge in graph_documents[0].relationships:
        graph._graph.add_edge(
                edge.source.id,
                edge.target.id,
                relation=edge.type,
            )

        graph._graph.add_edge(
                edge.target.id,
                edge.source.id,
                relation=edge.type+" by",
            )

    chain = GraphQAChain.from_llm(
        llm=llm, 
        graph=graph, 
        verbose=True
    )
        
    return chain

同樣,為同一文件實(shí)現(xiàn)標(biāo)準(zhǔn)RAG創(chuàng)建函數(shù)

def rag():
    # 文檔加載器
    loader = TextLoader('Moon.txt')
    data = loader.load()

    # 文檔轉(zhuǎn)換器
    text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
    texts = text_splitter.split_documents(data)

    # 向量數(shù)據(jù)庫
    docsearch = Chroma.from_documents(texts, embeddings)

    # 需要知道的超參數(shù)
    retriever = docsearch.as_retriever(search_type='similarity_score_threshold',search_kwargs={"k": 7,"score_threshold":0.3})
    qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)
        
    return qa

為兩種類型的RAG創(chuàng)建對象

standard_rag = rag()
graph_rag = graphrag()

現(xiàn)在是時候?qū)崿F(xiàn)HybridRAG了

def hybrid_rag(query,standard_rag,graph_rag):
    result1 = standard_rag.run(query)
    
    print("Standard RAG:",result1)
    result2 = graph_rag.run(query)
    
    
    print("Graph RAG:",result2)
    prompt = "Generate a final answer using the two context given : Context 1: {} \n Context 2: {} \n Question: {}".format(result1,result2,query)
    return llm(prompt)

query = "Some characteristics of Moon Man"
hybrid = hybrid_rag(query,standard_rag,graph_rag)
print("Hybrid:",hybrid)

如你所見,我們對給定的提示分別獨(dú)立執(zhí)行了標(biāo)準(zhǔn)RAG和GraphRAG。一旦找到答案,我們就會利用這兩個響應(yīng)作為上下文,來生成最終的答案。

談到輸出,最終的HybridRAG確實(shí)從兩次檢索中獲取了上下文,并產(chǎn)生了更好的結(jié)果。有些點(diǎn)被兩個RAG系統(tǒng) 遺漏了,但最終HybridRAG結(jié)合并給出了完美的答案。

STANDARD RAG: 
 Here are some characteristics of Moon Man, based on the story:

* **Brave:** He confronts danger and fights villains like Umbra.
* **Powerful:** He has superhuman abilities granted by the amulet.
* **Protective:** He safeguards Lunaris and its citizens.
* **Determined:** He doesn't give up, even when facing powerful enemies.
* **Compassionate:** He helps those in need, like rescuing lost pets.
* **Humble:** Despite his powers, he remains grounded and dedicated to his city. 



> Entering new GraphQAChain chain...
Entities Extracted:
Moon Man

Full Context:
Moon Man PROTECTS night sky
Moon Man WEARS silver suit
Moon Man PROTECTED Lunaris
Moon Man CAPTURED thieves
Moon Man DEFEATED Umbra
Moon Man INSPIRES hope
Moon Man INSPIRES courage

> Finished chain.

 @@ 
 GRAPH RAG: 
 Helpful Answer: 
* Protective (protects night sky, protected Lunaris)
* Courageous and Inspiring (inspires hope, inspires courage)
* Strong (captured thieves, defeated Umbra) 


 @@ 
 HYBRID RAG: 
 Moon Man is the **protective** champion of Lunaris, using his **strength** and **courage** to def

本文轉(zhuǎn)載自 ??AI科技論談??,作者: AI科技論談

標(biāo)簽
收藏
回復(fù)
舉報(bào)
回復(fù)
相關(guān)推薦
日韩欧美一区二区免费| 国产精品无码永久免费888| 欧美激情精品久久久久久黑人 | 亚州av一区二区| 99久久久久久久久久| 国产精品4hu.www| 一区二区三区在线影院| 麻豆av一区| 国产丝袜在线视频| 国产欧美大片| 久久视频在线观看免费| 日韩 中文字幕| 国产95亚洲| 精品久久久久久国产91| 一区二区在线不卡| 91激情在线观看| 亚洲精品看片| 色爱精品视频一区| 日本r级电影在线观看| 春暖花开亚洲一区二区三区| 亚洲男同1069视频| 欧洲精品久久| 樱花视频在线免费观看| 国语精品一区| 亚洲高清久久网| 99re6在线观看| 美女18一级毛片一品久道久久综合| 91麻豆免费看| 91丨九色丨国产| 亚洲欧美一区二区三区四区五区| 免费看日产一区二区三区| 欧美性69xxxx肥| 超碰97在线看| 秋霞网一区二区| 久久成人免费日本黄色| 欧美最近摘花xxxx摘花| 免费一级片视频| 亚洲九九视频| 日韩在线观看高清| 日本理论中文字幕| www 久久久| 欧美日韩国产精品成人| 免费午夜视频在线观看| 欧美gv在线观看| 亚洲愉拍自拍另类高清精品| 熟女视频一区二区三区| 风流老熟女一区二区三区| 久久99久久久久| 高清一区二区三区四区五区| 黄瓜视频污在线观看| www.丝袜精品| 精品福利av导航| caopor在线| 激情亚洲另类图片区小说区| 亚洲第一级黄色片| 亚洲一级Av无码毛片久久精品| 神马久久午夜| 欧美午夜激情在线| 国模吧无码一区二区三区| 少妇视频一区| 色综合中文综合网| 熟妇人妻va精品中文字幕 | 99热只有这里有精品| 欧美亚洲在线日韩| 色噜噜国产精品视频一区二区| 岛国大片在线免费观看| 午夜日韩影院| 亚洲国产精品字幕| 黄瓜视频污在线观看| 精品视频免费在线观看| 中文字幕一区二区三区电影| 朝桐光av一区二区三区| 在线成人动漫av| 欧美成人video| 深田咏美中文字幕| 色婷婷久久久| 日韩网站在线观看| 欧美成人三级视频| 国产精品亚洲综合久久| 欧美大尺度激情区在线播放| 清纯粉嫩极品夜夜嗨av| 亚洲国产一区二区精品专区| 欧美自拍大量在线观看| 中国一区二区视频| 国产精品一区二区视频| 国产精品一区二区三区观看| 欧洲亚洲精品视频| 狠狠色综合日日| 国产精品免费一区二区三区观看| 成人黄色免费网| 国产在线视频一区二区| 国产麻豆乱码精品一区二区三区 | 蜜乳av一区| 欧美性生活大片免费观看网址| 五月天激情图片| 男人影院在线观看| 亚洲一区二区三区自拍| 日本中文字幕一级片| 亚洲黄色免费av| 欧美高清视频一二三区| 给我免费观看片在线电影的| 精品国产午夜| 九九热这里只有在线精品视| 97久久久久久久| 99在线精品视频在线观看| 欧美黑人视频一区| 波多野结衣视频在线看| 国产成人精品亚洲777人妖| 5g国产欧美日韩视频| 神马亚洲视频| 亚洲日韩欧美一区二区在线| 99热成人精品热久久66| 日韩av福利| 欧美mv日韩mv亚洲| 午夜性福利视频| aiai久久| 色久欧美在线视频观看| 天堂网视频在线| 成人午夜精品在线| 亚洲第一精品区| 香蕉成人av| 日韩高清中文字幕| 久久国产精品二区| 国产日本精品| 国产91亚洲精品一区二区三区| 黄色一级大片在线免费看国产| 成人av在线影院| 久久综合九色综合久99| 日本一级理论片在线大全| 欧美日韩中文另类| 欧美老熟妇乱大交xxxxx| 韩国亚洲精品| 7777精品久久久大香线蕉小说| 亚洲成人久久精品| 综合久久久久久| 加勒比av中文字幕| 日韩情爱电影在线观看| 国产精品aaaa| 久青草国产在线| 一本久久综合亚洲鲁鲁五月天| 成人中文字幕av| 亚洲裸色大胆大尺寸艺术写真| 在线观看成人黄色| 亚洲成人av网址| 国产亚洲精品免费| 国产成人综合一区| 久久爱www成人| 日本国产一区二区三区| 91久久久久国产一区二区| 国产日韩欧美电影| 午夜免费一区二区| 激情五月综合网| 国产精品国产自产拍高清av水多 | 日韩精品中文字幕在线不卡尤物| 最新中文字幕视频| 久久精品卡一| 日韩精品不卡| 日本欧美在线| 久久视频在线播放| 亚洲成人中文字幕在线| 午夜精品久久久| 中文字幕乱码一区| 西西人体一区二区| 日本一区二区三区免费观看| 在线免费观看污| 亚洲国产精品yw在线观看 | 中文字幕免费高清在线观看| gogo大胆日本视频一区| 国产素人在线观看| 婷婷精品在线观看| 国产精品黄视频| 天天操天天干天天插| 中文字幕视频一区| 视频区 图片区 小说区| 狠狠综合久久| 91精品国产综合久久香蕉最新版 | 国产一区二区久久精品| 中文字幕在线观看欧美| 综合分类小说区另类春色亚洲小说欧美| 人妻熟妇乱又伦精品视频| 精品久久免费| 2020久久国产精品| 99re热久久这里只有精品34| 日韩一级二级三级| 日本午夜视频在线观看| 成人av网站在线| 日本一极黄色片| 欧美大片一区| 欧美一区二区综合| 国产精一区二区| 久久精品免费电影| 婷婷丁香一区二区三区| 欧美亚一区二区| 欧美偷拍一区二区三区| 噜噜噜久久亚洲精品国产品小说| 久久亚裔精品欧美| 亚洲视频自拍| 日韩av手机在线看| 女囚岛在线观看| 亚洲成人黄色网址| 中文字幕一区二区三区人妻四季 | 国语对白在线播放| 91小视频在线| 久久人人爽人人片| 日韩经典一区二区| 男女猛烈激情xx00免费视频| 色135综合网| 久中文字幕一区| 美脚恋feet久草欧美| 欧美精品日韩www.p站| 韩国福利在线| 亚洲成人黄色网| 国产女人高潮的av毛片| 日本精品一区二区三区四区的功能| 可以直接看的无码av| 国产精品一区二区在线看| 无人在线观看的免费高清视频| av中文字幕一区二区| 国产精品有限公司| 亚洲伊人伊成久久人综合网| 日韩av免费在线看| 久久影院午夜精品| 欧美激情2020午夜免费观看| 在线日本中文字幕| 亚洲深夜福利在线| 11024精品一区二区三区日韩| 亚洲欧洲精品一区二区精品久久久| 四虎成人在线播放| 蜜桃免费网站一区二区三区| 亚洲乱码中文字幕久久孕妇黑人| 久久福利综合| 欧美日韩国产一二| 台湾佬综合网| 精品产品国产在线不卡| 亚洲专区**| 99r国产精品视频| 国产精品亚洲欧美一级在线 | 日本高清一二三区| 中文字幕在线一区免费| 日本一道本视频| 国产欧美精品区一区二区三区 | 日韩精品一区二区三| 亚洲一区成人在线| 精国产品一区二区三区a片| 337p粉嫩大胆噜噜噜噜噜91av| 亚洲综合欧美在线| 轻轻草成人在线| 久久99爱视频| 精品一区二区三区在线观看| 欧美午夜性视频| 欧美激情电影| 国产精品美女在线播放| 羞羞答答成人影院www| 黄色网络在线观看| 欧美深夜福利| 18禁免费观看网站| 国产精品久久777777毛茸茸| 日韩激情免费视频| 丝袜脚交一区二区| 天堂在线资源视频| 国产在线国偷精品产拍免费yy| 欧洲av无码放荡人妇网站| 免费在线日韩av| 嫩草影院国产精品| 国产一区在线观看麻豆| 一区二区三区四区影院| 不卡视频免费播放| 中文字幕乱码在线人视频| 成人午夜视频免费看| 国产精品探花一区二区在线观看| 国产精品88av| 亚洲国产精品自拍视频| 久久久不卡网国产精品二区| 久久日免费视频| 亚洲精品国产高清久久伦理二区| 色撸撸在线视频| 亚洲欧美日韩在线| 亚洲国产综合久久| 欧洲国内综合视频| 国产av一区二区三区| 亚洲精品短视频| 69xxxx欧美| 久久久久久久一| 国产成人免费9x9x人网站视频| 5566成人精品视频免费| 粉嫩av一区二区三区四区五区| 国产精彩精品视频| 国产视频一区二| 六十路精品视频| 亚洲91精品| 日韩av黄色网址| 精品一区免费av| 天天做天天干天天操| 波多野结衣在线一区| 老熟妇精品一区二区三区| 国产亚洲精品精华液| 激情综合网五月天| 欧美日韩在线精品一区二区三区激情| 免费视频网站在线观看入口| 欧美一区二区在线免费播放| 色视频免费在线观看| 亚洲精品中文字| 国产一二在线观看| 欧美极品欧美精品欧美视频 | 亚洲一区二区视频在线| 黄色大全在线观看| 亚洲第一综合天堂另类专| 免费人成在线观看播放视频| 69视频在线免费观看| 91精品一区| 99久久无色码| 激情小说亚洲色图| 亚洲成人动漫在线| 日本不卡一二三区黄网| www.51色.com| 国产日韩综合av| 91久久国产视频| 欧美va亚洲va| 男人的天堂在线视频| 中国日韩欧美久久久久久久久 | 欧美激情手机在线视频| 国产精品99久久久久久董美香 | 日韩三级毛片| www.男人天堂网| 亚洲在线网站| 最新中文字幕日本| 亚洲欧美日韩在线播放| 日韩无码精品一区二区三区| 欧美一区二区三区在线| 污视频在线免费观看| 欧美成人四级hd版| 亚洲精品69| 一区二区三区四区免费视频| 国内在线观看一区二区三区| 国产探花在线观看视频| 91丨porny丨最新| 国产一级性生活| 亚洲国产97在线精品一区| 羞羞的视频在线观看| 国产专区精品视频| 欧美高清在线| 欧美视频国产视频| www.亚洲人| 97人人澡人人爽人人模亚洲| 亚洲第一福利在线观看| 在线播放麻豆| 国产精品丝袜白浆摸在线| 欧美一区二区三区高清视频| 男人添女人荫蒂免费视频| 国产精品18久久久久久vr| 青娱乐国产盛宴| 精品欧美黑人一区二区三区| 俺来俺也去www色在线观看| 国产超碰91| 一区二区三区福利| 国产成人美女视频| 国产亚洲欧美日韩日本| 国产午夜精品无码一区二区| 欧美精选午夜久久久乱码6080| 欧美人体大胆444www| 国产成人一区二区三区| 日韩电影二区| 午夜激情视频网| 日本一区二区成人| 一区二区日韩在线观看| 色综合91久久精品中文字幕| 成人在线tv视频| 免费无码av片在线观看| 国产日产欧美一区二区三区| 中文字幕日本人妻久久久免费| 精品裸体舞一区二区三区| 91超碰在线免费| 欧美日韩亚洲免费| 日本亚洲欧美天堂免费| 玖玖爱这里只有精品| 亚洲激情国产精品| 少妇精品视频一区二区免费看| 国产女主播一区二区三区| 亚洲一区成人| 久久久久麻豆v国产| 日韩欧美成人激情| 制服丝袜专区在线| 在线不卡视频一区二区| 成人久久视频在线观看| 国产少妇在线观看| 日韩精品在线观看网站| 日韩精品一页| 2018国产在线| 中文字幕一区二区日韩精品绯色| 中文在线观看av| 欧美激情在线观看| 你懂的一区二区三区| 亚洲精品一区二区18漫画| 欧美视频国产精品| 51xtv成人影院| 日韩久久久久久久久久久久久| 日韩一区精品视频| 国产a免费视频| 自拍视频国产精品| 欧美1区2区3区4区|