Find answers from the community

Updated last year

Hi

At a glance
Hi,
I am trying to build a KnowledgeGraph from structured Data in Python.
My data is similar to GoogleMaps restaurants.

Example Data:
[ { "name": "Italian Restaurant 1", "price": "10EUR", "location": "New York", "opening": "10am", "closing": "10pm", }, {...}, ]
I am adding Nodes to the KnowledgeGraph based on this example: https://gpt-index.readthedocs.io/en/v0.6.32/examples/index_structs/knowledge_graph/NebulaGraphKGIndexDemo.html#optional-try-building-the-graph-and-manually-add-triplets
At the section: Building the Graph and Manually adding Triplets

Using this Example I would have Triplets looking similar to this:
[ ("Italian Restaurant 1", "costs", "10EUR"), ("Italian Restaurant 1", "city", "New York"), ("Italian Restaurant 1", "opens", "10am"), ("Italian Restaurant 1", "closes", "10pm") ]
I would have many of those for my entire Dataset.
Now my general question is how I would create the custom Nodes.

I have been using TextNodes so far, creating a new Node for each Data entry (restaurant).
node = TextNode() triplets = [...] for t in triplets: index.upsert_triplet_and_node(t, node)

This to me seems wrong, as I don't really have a text for this Node. Using the NodeParsers or from_document options as stated in many other examples is not really applicable to this structured data.

Can someone guide me into the right direction? How should I use Initialize Nodes? What relationships should I use? Should I use a node per Restaurant or per Triplet?

The goal is to query the index for something like "What restaurant is open in Now York at 2pm?"
L
H
6 comments
theres two options in the knowledge graph index.as_query_engine(include_text=False) or index.as_query_engine(include_text=True)

When this is true, the triplets AND the nodes they are associated with are sent to the LLM to answer a query

When it's false, the LLM only reads the triplets when answering a query
Thanks for that, i will play around using different params there.
How should I structure my KG when building it?
Should I have a Node for each triplet, or for each restaurant or a combination of the two?

Should I add Triplets with links in both direction? i.e: ("restaurant 1", "offers", "delivery") AND ("delivery", "offert by", "restaurant 1") or is one sufficient?
I think both direction is probably better when possible
should I start a new TextNode for each Triplet (or in this case 1 for both directions) or for each Restaurant?
Add a reply
Sign up and join the conversation on Discord