Find answers from the community

Updated 6 months ago

KG_nebula_property_graph

hey - any help would be appreciated.
I was trying out https://docs.llamaindex.ai/en/stable/examples/property_graph/property_graph_nebula/, and I was running into an issue as I wanted to visualize the traversed graph as in the image. The retriever only gets the nodes. Here is a gist https://gist.github.com/flight505/6a3c0311706aebea301d02bc74a763a8 where I attempted to run it in streamlit, hoping to use LlamaIndex traversal method, but it does not work for paths. Is there a simple direct method that I could use from Llmmaindex? - I haven't found it in the docs

the basic code should be something like this, here i can get the nodes used in the query but not the paths:
if st.button("Query Engine"):
if query:
query_engine = index.as_query_engine(include_text=True)
try:
response = query_engine.query(query)
st.write("Query Response:")
st.write(str(response)) # Print the response to inspect its structure

# Extract nodes and edges from the response
nodes = [{"id": node.node_id, "name": node.text} for node in response.nodes]
edges = [{"source": edge.start_node_id, "target": edge.end_node_id, "relationship": edge.relationship} for edge in response.edges]

# Visualize the graph
net = visualize_graph(nodes, edges)
display_graph(net)
except Exception as e:
st.error(f"Error during query: {str(e)}")
Attachment
image.png
L
f
4 comments
Are you trying to visualize just the retrieved nodes? or the entire graph?
Hi, I think the graph has too many nodes and edges to get helpful information from the entire graph. It is a streamlit app, and the query is very slow at this point. I wanted to visualize the information related to the response of the query, to show the traversed path or how the query is connected like a subgraph. The query is natural language like the minimal example, "Tell me about Peter Quill.". the llamaidex docs about nebula property graph and "retriever = index.as_retriever(include_text=False) " & "nodes = retriever.retrieve(query)" only returns the nodes related to the query.
When you query, the retriever kind of loses the original kg node and relation objects, because everything goes into a text node to make consumption by the llm easier

Probably you'd want to use the lower level graph store apis instead to pull in data? Would probably need a custom retriever at that point
Thanks, will give it a try
Add a reply
Sign up and join the conversation on Discord