Save, Load and Add New Data into GraphRAG #14896
Replies: 1 comment
-
Hey @brianadit24! 👋 I'm here to assist you with any issues or questions you have regarding GraphRAG. Let's tackle this challenge together! To save, load, and add new data into
Here is a complete example: from llama_index.core.graph_stores.simple_labelled import SimplePropertyGraphStore
from llama_index.core.graph_stores.types import LabelledNode, Relation
# Initialize a new graph store
graph_store = SimplePropertyGraphStore()
# Add some data
node1 = LabelledNode(id="subject1", properties={"name": "Subject 1"})
node2 = LabelledNode(id="object1", properties={"name": "Object 1"})
relation1 = Relation(id="relation1", start="subject1", end="object1", properties={"type": "Relation 1"})
graph_store.upsert_nodes([node1, node2])
graph_store.upsert_relations([relation1])
# Save the current state
graph_store.persist(persist_path="path/to/save/graph_store.json")
# Load the previously saved state
loaded_graph_store = SimplePropertyGraphStore.from_persist_path(persist_path="path/to/save/graph_store.json")
# Add new data to the loaded graph store
new_node = LabelledNode(id="subject2", properties={"name": "Subject 2"})
new_relation = Relation(id="relation2", start="subject2", end="object1", properties={"type": "Relation 2"})
loaded_graph_store.upsert_nodes([new_node])
loaded_graph_store.upsert_relations([new_relation]) This approach allows you to manage the state of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Related to this notebook:
https://github.com/run-llama/llama_index/blob/main/docs/docs/examples/cookbooks/GraphRAG_v1.ipynb
Someone in here already try to save and load GraphRAG and also how about we add new data into GraphRAG?
Beta Was this translation helpful? Give feedback.
All reactions