-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgraph_rag.py
39 lines (32 loc) · 1.17 KB
/
graph_rag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import logging
import dotenv
dotenv.load_dotenv()
logging.basicConfig(level=logging.INFO)
logging.info('Starting up the Knowledge Graph RAG...')
# Instantiate the Neo4J connector
logging.info(f'Instantiating the Neo4J connector for: { os.getenv("NEO4J_URI") }')
from langchain_community.graphs import Neo4jGraph
graph = Neo4jGraph()
# Instantiate LLM to use with the Graph RAG
logging.info('Instantiating LLM to use with the LLMGraphTransformer')
from langchain_community.llms import Ollama
llm=Ollama(model='llama3', temperature=0.0)
# Instantiate the langchain Graph RAG with the Neo4J connector and the LLM
from langchain.chains import GraphCypherQAChain
chain = GraphCypherQAChain.from_llm(graph=graph, llm=llm, verbose=True)
logging.info('Knowledge Graph RAG is ready to go!')
logging.info('='*50)
def main():
logging.info('Type "exit" to quit the program.')
while True:
question = input('\nAsk me a question: ')
if question == 'exit':
break
result = chain.invoke({"query": question})
if result['result']:
print(result['result'])
else:
print(result)
if __name__ == '__main__':
main()