----------------------
You can convert an existing Neo4j knowledge graph into a LlamaIndex "Property Graph" by following these steps:
- First, you need to connect to your existing Neo4j graph. You can do this by creating an instance of
Neo4jPropertyGraphStore
with your Neo4j credentials and URL. Here is an example:
from llama_index.graph_stores.neo4j import Neo4jPropertyGraphStore
graph_store = Neo4jPropertyGraphStore(
username="neo4j",
password="your_password",
url="bolt://localhost:7687",
)
Replace
"your_password"
with your actual Neo4j password.
- Then, you can create a
PropertyGraphIndex
from the existing graph using the from_existing
method. You need to specify the property_graph_store
(which is the graph_store
we just created), the language model (llm
), and the embedding model (embed_model
). Here is an example:
from llama_index.core import PropertyGraphIndex
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
index = PropertyGraphIndex.from_existing(
property_graph_store=graph_store,
llm=OpenAI(model="gpt-3.5-turbo", temperature=0.3),
embed_model=OpenAIEmbedding(model_name="text-embedding-3-small"),
)
In this example, we are using the OpenAI's GPT-3.5-turbo as the language model and a small text embedding model for the embedding model. You can replace these with the models of your choice.
- Now, you can use the
index
to insert more documents, retrieve nodes, and perform other operations.
Please note that if your graph was created outside of LlamaIndex, the most useful retrievers will be text to cypher or cypher templates. Other retrievers rely on properties that LlamaIndex inserts.