Property Graph Index Visualization¶
Similar to the property_graph_basic notebook, in this notebook, we demonstrate an alternative visualization approach for the default SimplePropertyGraphStore
While the focus of the other notebook is querying the graph, this notebook focuses on the visualization aspect of what was created.
In [ ]:
Copied!
%pip install llama-index
%pip install llama-index
Setup¶
In [ ]:
Copied!
import os
import urllib.request
os.environ["OPENAI_API_KEY"] = "sk-proj-..."
import os
import urllib.request
os.environ["OPENAI_API_KEY"] = "sk-proj-..."
In [ ]:
Copied!
url = "https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt"
filename = "data/paul_graham/paul_graham_essay.txt"
os.makedirs(os.path.dirname(filename), exist_ok=True)
urllib.request.urlretrieve(url, filename)
url = "https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt"
filename = "data/paul_graham/paul_graham_essay.txt"
os.makedirs(os.path.dirname(filename), exist_ok=True)
urllib.request.urlretrieve(url, filename)
In [ ]:
Copied!
import nest_asyncio
nest_asyncio.apply()
import nest_asyncio
nest_asyncio.apply()
In [ ]:
Copied!
from llama_index.core import SimpleDirectoryReader
from llama_index.core import SimpleDirectoryReader
In [ ]:
Copied!
documents = SimpleDirectoryReader("./data/paul_graham/").load_data()
documents = SimpleDirectoryReader("./data/paul_graham/").load_data()
Construction¶
In [ ]:
Copied!
from llama_index.core import PropertyGraphIndex
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
index = PropertyGraphIndex.from_documents(
documents,
llm=OpenAI(model="gpt-3.5-turbo", temperature=0.3),
embed_model=OpenAIEmbedding(model_name="text-embedding-3-small"),
show_progress=True,
)
from llama_index.core import PropertyGraphIndex
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
index = PropertyGraphIndex.from_documents(
documents,
llm=OpenAI(model="gpt-3.5-turbo", temperature=0.3),
embed_model=OpenAIEmbedding(model_name="text-embedding-3-small"),
show_progress=True,
)
Visualization¶
Let's explore what we created. Using the show_jupyter_graph()
method to create our graph directly in the Jupyter cell!
Note that this only works in Jupyter environments.
In [ ]:
Copied!
index.property_graph_store.show_jupyter_graph()
index.property_graph_store.show_jupyter_graph()