paint-brush
Dhisidda Wakiilka Isku-dhafka ah ee RAG oo wata Sawirro Neo4j ah iyo Raadinta Milvus Vectorby@neo4j
Taariikh cusub

Dhisidda Wakiilka Isku-dhafka ah ee RAG oo wata Sawirro Neo4j ah iyo Raadinta Milvus Vector

by Neo4j8m2024/11/05
Read on Terminal Reader

Aad u dheer; In la akhriyo

Hagahan waxa uu sahaminayaa dhisidda wakiilka isku-dhafan ee RAG iyadoo la adeegsanayo Neo4j iyo Milvus si looga faa'iidaysto garaafyada iyo xogta xogta vector labadaba, kor u qaadista saxnaanta jawaabta iyo ku habboonaanta iyada oo loo marayo habab goobid oo isku dhafan iyo hababka is-sixitaanka.
featured image - Dhisidda Wakiilka Isku-dhafka ah ee RAG oo wata Sawirro Neo4j ah iyo Raadinta Milvus Vector
Neo4j HackerNoon profile picture
0-item
1-item


Boostada balooggani waxay faahfaahinaysaa sida loo dhiso wakiilka GraphRAG iyadoo la adeegsanayo xogta garaafyada Neo4j iyo xogta xogta Milvus vector. Wakiilkani waxa uu isku daraa awooda xogta garaafyada iyo raadinta vector si ay u bixiso jawaabo sax ah oo ku haboon waydiimaha isticmaalaha. Tusaalahan, waxaan u adeegsan doonaa LangGraph, Llama 3.1 8B oo wata Ollama iyo GPT-4o.


Nidaamyada Jiilka La Kordhiyay ee Soo Celinta Dhaqanka ( RAG ) waxay ku tiirsan yihiin oo keliya xogta xogta vector si loo soo saaro dukumeenti khuseeya Habkayagu wuu sii socdaa anagoo ku daraya Neo4j si aan u qabsano xiriirka ka dhexeeya hay'adaha iyo fikradaha, anagoo siinaya faham qotodheer oo macluumaadka ah. Waxaan rabnaa inaan abuurno nidaam RAG ka sii adag oo xog badan annagoo isku darka labadan farsamo.

Dhismaha Wakiilka RAG

Wakiilkayagu waxa uu raacayaa saddex fikradood oo muhiim ah: jiheynta, hababka dib u dhaca, iyo is saxid. Mabaadi'dan waxaa lagu hirgeliyay qaybo taxane ah oo LangGraph ah:


  • Jideynta – Habka habaynta u go'an ayaa go'aamiya haddii la isticmaalayo xogta xogta vector, garaafka aqoonta, ama isku darka labadaba ku salaysan weydiinta.
  • Dib-u-dhac - Xaaladaha marka dib-u-soo-celinta bilowga ahi ku filnayn, wakiilku wuxuu dib ugu soo noqdaa raadinta shabakadda isagoo isticmaalaya Tavily.
  • Is saxid – Wakiilku waxa uu qiimeeyaa jawaabihiisa oo isku dayo in uu saxo dhalanteedka ama khaladaadka.


Waxaan markaa leenahay qaybo kale, sida:


  • Soo Celinta - Waxaan isticmaalnaa Milvus, xog-ururin furan iyo waxqabad sare, si aan u kaydiyo oo u soo saarno qaybo dukumeenti ah oo ku salaysan macnaha macnaha ee la mid ah weydiinta isticmaalaha.
  • Wanaajinta garaafka - Neo4j waxaa loo isticmaalaa in lagu dhiso garaafka aqoonta dukumeentiyada la soo saaray, iyadoo lagu kobcinayo macnaha guud ee xidhiidhada iyo hay'adaha.
  • LLMs dhexgalka - Llama 3.1 8B, LLM maxalli ah, waxaa loo isticmaalaa soo saarista jawaabaha iyo qiimaynta ku haboon iyo saxnaanta macluumaadka la soo saaray, halka GPT-4o loo isticmaalo in lagu dhaliyo Cypher, luqada weydiinta isticmaalo Neo4j.

Dhismaha GraphRAG

Qaab dhismeedka wakiilkayaga GraphRAG waxa loo sawiri karaa socod shaqo oo leh dhawr noodood oo isku xidhan:


  • Dariiqinta su'aalaha - Wakiilku wuxuu marka hore falanqeeyaa su'aasha si uu u go'aamiyo istaraatiijiyada dib u soo celinta ugu fiican (raadinta vector, garaaf raadinta, ama labadaba).
  • Soo-celinta - Iyada oo ku saleysan go'aanka dariiqa, dukumeentiyada khuseeya waxaa laga soo saaray Milvus, ama macluumaadka waxaa laga soo saaray garaafka Neo4j.
  • Jiilka – LLM waxa ay dhalisaa jawaab iyada oo la isticmaalayo macnaha guud.
  • Qiimaynta – Wakiilku waxa uu qiimeeyaa jawaabta la soo saaray ee ku habboonaanta, saxnaanta, iyo dhalanteedka iman kara.
  • Sifaynta (haddii loo baahdo) - Haddii jawaabta loo arko mid aan ku qanacsanayn, wakiilku wuxuu hagaajin karaa raadintiisa ama isku dayo inuu saxo khaladaadka.

Tusaalooyinka Wakiilada

Si aan u muujino awoodaha wakiiladeena LLM, aynu eegno laba qaybood oo kala duwan: Graph Generation iyo Composite Agent .

Iyadoo koodka buuxa laga heli karo dhinaca hoose ee boostadan, qaybahan ayaa bixin doona faham wanaagsan oo ku saabsan sida wakiiladan ay ugu shaqeeyaan qaabka LangChain.

Jiilka garaafka

Qaybtan waxaa loogu talagalay in lagu hagaajiyo habka su'aalaha-jawaabista iyadoo la adeegsanayo awoodaha Neo4j. Waxay ka jawaabaysaa su'aalaha iyadoo ka faa'iidaysanaysa aqoonta ku dhex jirta xogta garaafyada Neo4j. Waa kan sida ay u shaqeyso:


  1. GraphCypherQAChain - Waxay u ogolaataa LLM inay la falgasho xogta garaafyada Neo4j. Waxay u isticmaashaa LLM laba siyaabood:

    • cypher_llm – Tusaalahan LLM ayaa mas'uul ka ah soo saarista weydiimaha Cypher si looga soo saaro macluumaadka khuseeya garaafka iyadoo lagu salaynayo su'aasha isticmaalaha.

    • Xaqiijinta - Waxay hubisaa in weydiimaha Cypher la ansixiyay si loo hubiyo inay si isku mid ah sax u yihiin.


  2. Soo celinta macnaha guud - Weydiimaha la ansaxiyay waxaa lagu fuliyay garaafka Neo4j si loo soo ceshado macnaha guud.


  3. Jiilka jawaabta – Qaabka luqaddu waxa uu adeegsadaa macnaha la soo saaray si uu u dhaliyo jawaabta su'aasha isticmaalaha.


 ### Generate Cypher Query llm = ChatOllama(model=local_llm, temperature=0) # Chain graph_rag_chain = GraphCypherQAChain.from_llm( cypher_llm=llm, qa_llm=llm, validate_cypher=True, graph=graph, verbose=True, return_intermediate_steps=True, return_direct=True, ) # Run question = "agent memory" generation = graph_rag_chain.invoke({"query": question})


Qaybtani waxay awood u siinaysaa nidaamka RAG inuu taabto Neo4j, kaas oo gacan ka geysan kara bixinta jawaabo dhammaystiran oo sax ah.

Wakiilka Isku-dhafka ah, Sawirka iyo Vector 🪄

Tani waa halka ay sixirku ka dhaco: Wakiilkeenu wuxuu isku dari karaa natiijooyinka Milvus iyo Neo4j, taas oo u oggolaanaysa in si fiican loo fahmo macluumaadka una horseedaya jawaabo sax ah oo qotodheer. Waa kan sida ay u shaqeyso:


  1. Dalabyo - Waxaan qeexnay degdeg ah oo faraya LLM inay isticmaalaan macnaha guud ee labada Milvus iyo Neo4j si ay uga jawaabaan su'aasha.
  2. Soo Celinta – Wakiilku waxa uu ka soo qaataa macluumaadka la xidhiidha Milvus (iyaga oo isticmaalaya raadinta vector) iyo Neo4j (adoo isticmaalaya Graph Generation).
  3. Jiilka Jawaabta – Llama 3.1 8B waxa ay socodsiisaa isla markiiba oo waxa ay dhalisaa jawaab kooban, iyada oo ka faa’iidaysanaysa aqoonta la isku daray ee laga helay kaydka xogta iyo garaafyada oo leh silsilad isku dhafan.


 ### Composite Vector + Graph Generations cypher_prompt = PromptTemplate( template="""You are an expert at generating Cypher queries for Neo4j. Use the following schema to generate a Cypher query that answers the given question. Make the query flexible by using case-insensitive matching and partial string matching where appropriate. Focus on searching paper titles as they contain the most relevant information. Schema: {schema} Question: {question} Cypher Query:""", input_variables=["schema", "question"], )



 # QA prompt qa_prompt = PromptTemplate( template="""You are an assistant for question-answering tasks. Use the following Cypher query results to answer the question. If you don't know the answer, just say that you don't know. Use three sentences maximum and keep the answer concise. If topic information is not available, focus on the paper titles. Question: {question} Cypher Query: {query} Query Results: {context} Answer:""", input_variables=["question", "query", "context"], ) llm = ChatOpenAI(model="gpt-4o", temperature=0)


 # Chain graph_rag_chain = GraphCypherQAChain.from_llm( cypher_llm=llm, qa_llm=llm, validate_cypher=True, graph=graph, verbose=True, return_intermediate_steps=True, return_direct=True, cypher_prompt=cypher_prompt, qa_prompt=qa_prompt, )


Aan eegno natiijooyinka raadintayada, isku darka awoodaha garaafka iyo xogta xogta vector si aan u wanaajino helitaanka warqad cilmi baaris ah.


Waxaan ku bilaabaynaa raadinta garaafka annaga oo adeegsanayna Neo4j:


 # Example input data question = "What paper talks about Multi-Agent?" generation = graph_rag_chain.invoke({"query": question}) print(generation)


 > Entering new GraphCypherQAChain chain... Generated Cypher: cypher MATCH (p:Paper) WHERE toLower(p.title) CONTAINS toLower("Multi-Agent") RETURN p.title AS PaperTitle, p.summary AS Summary, p.url AS URL


 > Finished chain. {'query': 'What paper talks about Multi-Agent?', 'result': [{'PaperTitle': 'Collaborative Multi-Agent, Multi-Reasoning-Path (CoMM) Prompting Framework', 'Summary': 'In this work, we aim to push the upper bound of the reasoning capability of LLMs by proposing a collaborative multi-agent, multi-reasoning-path (CoMM) prompting framework. Specifically, we prompt LLMs to play different roles in a problem-solving team, and encourage different role-play agents to collaboratively solve the target task. In particular, we discover that applying different reasoning paths for different roles is an effective strategy to implement few-shot prompting approaches in the multi-agent scenarios. Empirical results demonstrate the effectiveness of the proposed methods on two college-level science problems over competitive baselines. Our further analysis shows the necessity of prompting LLMs to play different roles or experts independently.', 'URL': 'https://github.com/amazon-science/comm-prompt'}]


Raadinta garaafku aad ayuu ugu fiican yahay helida xidhiidhada iyo xogta badan. Waxay si dhakhso ah u aqoonsan kartaa waraaqaha ku salaysan cinwaannada, qorayaasha, ama qaybaha horay loo sii qeexay, iyada oo bixisa aragtida habaysan ee xogta.


Marka xigta, waxaynu u leexanaynaa raadinta ra'yigayaga aragti kale:


 # Example input data question = "What paper talks about Multi-Agent?" # Get vector + graph answers docs = retriever.invoke(question) vector_context = rag_chain.invoke({"context": docs, "question": question})


 > The paper discusses "Adaptive In-conversation Team Building for Language Model Agents" and talks about Multi-Agent. It presents a new adaptive team-building paradigm that offers a flexible solution for building teams of LLM agents to solve complex tasks effectively. The approach, called Captain Agent, dynamically forms and manages teams for each step of the task-solving process, utilizing nested group conversations and reflection to ensure diverse expertise and prevent stereotypical outputs.


Raadinta vector runtii aad bay ugu fiican tahay fahamka macnaha guud iyo isu ekaanshaha semantiga. Waxay daaha ka qaadi kartaa waraaqaha fikrad ahaan la xiriira weydiinta, xitaa haddii aysan si cad ugu jirin ereyada raadinta.


Ugu dambeyntii, waxaan isku darnaa labada hab ee raadinta:


Tani waa qayb muhiim ah oo ka mid ah wakiilkayaga RAG, taas oo suurtogal ka dhigaysa in la isticmaalo kaydinta xogta iyo garaafyada labadaba.


 composite_chain = prompt | llm | StrOutputParser() answer = composite_chain.invoke({"question": question, "context": vector_context, "graph_context": graph_context}) print(answer)


 > The paper "Collaborative Multi-Agent, Multi-Reasoning-Path (CoMM) Prompting Framework" talks about Multi-Agent. It proposes a framework that prompts LLMs to play different roles in a problem-solving team and encourages different role-play agents to collaboratively solve the target task. The paper presents empirical results demonstrating the effectiveness of the proposed methods on two college-level science problems.


Marka la isku daro garaafyada iyo raadinta vector, waxaan ka faa'ideysaneynaa xoogga labada qaab. Raadinta garaafku waxa uu bixiyaa saxsanaan iyo dhex maro xidhiidhada habaysan, halka baadhista vector ay ku kordhinayso qoto dheer iyada oo loo marayo fahamka semantic.


Habkan la isku daray wuxuu bixiyaa faa'iidooyin dhowr ah:


  1. Dib u xasuusinta la hagaajiyay : Waxa ay heshaa waraaqo khuseeya oo laga yaabo in ay seegaan labada hab oo keliya.
  2. Macnaha la wanaajiyey : Waxay bixisaa faham aad u qoto dheer oo ku saabsan sida warqaduhu isula xiriiraan.
  3. Dabacsanaanta : Waxay la qabsan kartaa noocyada kala duwan ee weydiimaha, laga bilaabo raadinta ereyada muhiimka ah ee gaarka ah ilaa sahaminta fikradeed ballaaran.

Soo koobid

Boostada baloogga, waxaan ku tusnay sida loo dhiso wakiilka GraphRAG iyadoo la adeegsanayo Neo4j iyo Milvus. Marka la isku daro xoogga xogta garaafyada iyo raadinta vector , wakiilkani wuxuu bixiyaa jawaabo sax ah oo ku habboon weydiimaha isticmaalaha.


Qaab dhismeedka wakiilkayaga RAG, oo leh marin u heellan, habab dib-u-dhac, iyo awoodaha is-sixitaanka, ayaa ka dhigaya mid adag oo la isku halayn karo. Tusaalooyinka Jiilka Garaafka iyo Qaybaha Wakiilka Isku-dhafka ah waxay muujinayaan sida wakiilkani u taabsan karo labadaba xogta xogta garaafyada si uu u bixiyo jawaabo dhamaystiran oo kooban.


Waxaan rajeyneynaa in hagahan uu ahaa mid waxtar leh oo kugu dhiirigeliya inaad hubiso suurtagalnimada isku darka xogta garaafyada iyo raadinta vector ee mashaariicdaada.


Koodhka hadda jira ayaa laga heli karaa GitHub .


Si aad wax badan uga barato mawduucan, nagu soo biir NODES 2024 ee Noofembar 7, shirkayada horumarinta farsamada ee bilaashka ah ee ku saabsan abka caqliga leh, garaafyada aqoonta, iyo AI. Hadda isdiiwaangeli!