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
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:
Waxaan markaa leenahay qaybo kale, sida:
Qaab dhismeedka wakiilkayaga GraphRAG waxa loo sawiri karaa socod shaqo oo leh dhawr noodood oo isku xidhan:
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.
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:
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.
Soo celinta macnaha guud - Weydiimaha la ansaxiyay waxaa lagu fuliyay garaafka Neo4j si loo soo ceshado macnaha guud.
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.
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:
### 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:
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!