Find answers from the community

Updated 3 months ago

Hello I am trying to use my existing

Hello! I am trying to use my existing nodes and edges in neo4j as the index for my KnowledgeGraphIndex, but loading the nodes from neo4j and using the existing relationships to build the index is not straightforward with the documentation. Can someone help me? My current approach looks something like this.. but I'm a bit stuck

Plain Text
nodes = graph_store.query('MATCH (n)-[r]->(m) RETURN n,r,m;')

for node in nodes:
  subject = node['n']['id']
  relationship = node['r']['id']
  object = node['m']['id']
  index.upsert_triplet_and_node(
    [subject, relationship, object], 
    TextNode(
      text=..., 
      id_=node['n']['id'],
    )
  )


Any help is appreciated thank you
L
n
4 comments
does that give an error? seems alright to me at first glance
It doesn't give an error, it's just my naive idea that I came up with and I'd be surprised if it's the correct way to load graph data into a graph index, i would assume there would be some better way
Well, be surprised i giess haha

You could just use your existing neo4j db with a query engine
https://gpt-index.readthedocs.io/en/stable/examples/query_engine/knowledge_graph_rag_query_engine.html
Thank you! So helpful!
Add a reply
Sign up and join the conversation on Discord