Implementation:Run llama Llama index SimplePropertyGraphStore
| Knowledge Sources | |
|---|---|
| Domains | Knowledge Graphs, Graph Storage, RAG |
| Last Updated | 2026-02-11 19:00 GMT |
Overview
An in-memory labelled property graph store that supports typed nodes (entities and chunks), labelled relations with properties, and triplet-based querying for knowledge graph-enhanced RAG systems.
Description
SimplePropertyGraphStore extends PropertyGraphStore and wraps a LabelledPropertyGraph model to provide a complete in-memory graph store. It supports two node types -- EntityNode (identified by a name field) and ChunkNode (identified by a text field) -- along with typed Relation objects that form triplets (subject-predicate-object).
Key capabilities:
- Node operations:
get()retrieves nodes filtered by properties or IDs;upsert_nodes()adds or updates nodes - Triplet operations:
get_triplets()retrieves triplets filtered by entity names, relation names, properties, or IDs;upsert_relations()adds relations - Depth-aware traversal:
get_rel_map()performs multi-hop graph traversal starting from given nodes, with configurable depth (default: 2) and result limit (default: 30), plus the ability to ignore specific relation types - Deletion:
delete()removes matching triplets and nodes based on entity names, relation names, properties, or IDs - Persistence: JSON serialization via
fsspecwithpersist(),from_persist_path(), andfrom_persist_dir() - Visualization:
save_networkx_graph()exports to an interactive HTML file via pyvis;show_jupyter_graph()displays in Jupyter via yfiles_jupyter_graphs
The store explicitly does not support structured queries, vector queries, schema retrieval, or external client connections. These methods raise NotImplementedError with descriptive messages.
Usage
Use this store for development, testing, and small-scale knowledge graph applications where an external graph database (such as Neo4j) is not needed. It is suitable for prototyping knowledge graph-enhanced RAG pipelines and for scenarios where the graph fits in memory. For production workloads with large graphs, use a dedicated graph database backend.
Code Reference
Source Location
- Repository: Run_llama_Llama_index
- File:
llama-index-core/llama_index/core/graph_stores/simple_labelled.py - Lines: 1-310
Signature
class SimplePropertyGraphStore(PropertyGraphStore):
supports_structured_queries: bool = False
supports_vector_queries: bool = False
def __init__(
self,
graph: Optional[LabelledPropertyGraph] = None,
) -> None
Import
from llama_index.core.graph_stores.simple_labelled import SimplePropertyGraphStore
# or
from llama_index.core.graph_stores import SimplePropertyGraphStore
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| graph | Optional[LabelledPropertyGraph] | No | Initial graph model; defaults to a new empty LabelledPropertyGraph()
|
Outputs
| Name | Type | Description |
|---|---|---|
| self.graph | LabelledPropertyGraph | The underlying graph model containing nodes, relations, and triplets |
Key Methods
get
def get(
self,
properties: Optional[dict] = None,
ids: Optional[List[str]] = None,
) -> List[LabelledNode]
Retrieves nodes from the graph, optionally filtered by property values and/or node IDs. Returns all nodes if no filters are provided.
get_triplets
def get_triplets(
self,
entity_names: Optional[List[str]] = None,
relation_names: Optional[List[str]] = None,
properties: Optional[dict] = None,
ids: Optional[List[str]] = None,
) -> List[Triplet]
Retrieves triplets (subject, relation, object) from the graph with multi-criteria filtering. Returns an empty list if no filter parameters are provided, preventing accidental full-graph dumps.
get_rel_map
def get_rel_map(
self,
graph_nodes: List[LabelledNode],
depth: int = 2,
limit: int = 30,
ignore_rels: Optional[List[str]] = None,
) -> List[Triplet]
Performs depth-aware relation traversal starting from the given nodes. Iteratively follows outgoing relations up to the specified depth, deduplicating visited triplets. Filters out relations in the ignore_rels list and returns at most limit triplets.
upsert_nodes
def upsert_nodes(self, nodes: Sequence[LabelledNode]) -> None
Adds or updates nodes in the graph by delegating to self.graph.add_node().
upsert_relations
def upsert_relations(self, relations: List[Relation]) -> None
Adds relations to the graph by delegating to self.graph.add_relation().
delete
def delete(
self,
entity_names: Optional[List[str]] = None,
relation_names: Optional[List[str]] = None,
properties: Optional[dict] = None,
ids: Optional[List[str]] = None,
) -> None
Deletes matching triplets and then matching nodes from the graph.
persist
def persist(
self,
persist_path: str,
fs: Optional[fsspec.AbstractFileSystem] = None,
) -> None
Serializes the graph to JSON and writes it to the given path using fsspec.
from_persist_path (classmethod)
@classmethod
def from_persist_path(
cls,
persist_path: str,
fs: Optional[fsspec.AbstractFileSystem] = None,
) -> "SimplePropertyGraphStore"
Loads a graph store from a JSON file at the given path.
from_dict (classmethod)
@classmethod
def from_dict(cls, data: dict) -> "SimplePropertyGraphStore"
Reconstructs a graph store from a dictionary. Infers node types: if a node dict contains "name", it is loaded as EntityNode; if it contains "text", it is loaded as ChunkNode.
Visualization Methods
save_networkx_graph
def save_networkx_graph(self, name: str = "kg.html") -> None
Exports the graph to an interactive HTML file using NetworkX and pyvis. Nodes are labeled with their IDs, and edges are labeled with their relation IDs.
Requires: networkx, pyvis
show_jupyter_graph
def show_jupyter_graph(self) -> None
Displays the graph inline in a Jupyter notebook using yfiles_jupyter_graphs.
Requires: yfiles_jupyter_graphs
Unsupported Operations
| Method | Reason |
|---|---|
get_schema() |
Schema not implemented for in-memory store |
structured_query() |
No query language support (e.g., Cypher) |
vector_query() |
No vector index support |
client (property) |
No external database client |
Usage Examples
Basic Usage
from llama_index.core.graph_stores import SimplePropertyGraphStore
from llama_index.core.graph_stores.types import EntityNode, Relation
# Create the store
graph_store = SimplePropertyGraphStore()
# Add entity nodes
node1 = EntityNode(name="Python", properties={"type": "language"})
node2 = EntityNode(name="LlamaIndex", properties={"type": "framework"})
graph_store.upsert_nodes([node1, node2])
# Add a relation
relation = Relation(
source_id="Python",
target_id="LlamaIndex",
label="USED_BY",
)
graph_store.upsert_relations([relation])
# Query triplets
triplets = graph_store.get_triplets(entity_names=["Python"])
# Depth-aware traversal
rel_map = graph_store.get_rel_map(
graph_nodes=[node1],
depth=2,
limit=30,
)
Persistence
# Save to disk
graph_store.persist("./storage/property_graph.json")
# Load from disk
loaded_store = SimplePropertyGraphStore.from_persist_path(
"./storage/property_graph.json"
)
Visualization
# Export to HTML
graph_store.save_networkx_graph("my_knowledge_graph.html")
# Display in Jupyter
graph_store.show_jupyter_graph()