Skip to content

Removing vertices and edges

Ingestion only adds and updates. To take a vertex or an edge out of a graph, remove it by its identity:

from graflo import GraphEngine, GraphManifest
from graflo.connections import Neo4jConfig

schema = GraphManifest.from_yaml("manifest.yaml").require_schema()
conn_conf = Neo4jConfig.from_env()

engine = GraphEngine()
engine.delete_vertices(conn_conf, schema, "machine", [{"serial": "M-17"}])
engine.delete_edges(
    conn_conf,
    schema,
    ("technician", "machine", "maintains"),
    [({"badge": "T-4"}, {"serial": "M-17"})],
)

Pass the schema the graph was written with. Names are logical, as in the manifest: each document carries the vertex type's identity fields, and GraFlo translates them to the names the database stores.

  • delete_vertices(conn_conf, schema, vertex, key_docs) removes the vertices and every edge that touches them, in any edge type. A document missing an identity field removes nothing.
  • delete_edges(conn_conf, schema, edge_id, endpoints) removes the edges of one declared edge between each (source, target) pair, whatever their properties. edge_id is the edge's (source, target, relation), with relation set to None for an edge declared without one.
Target Removes
ArangoDB, Neo4j, Memgraph, FalkorDB, TigerGraph, PostgreSQL, NebulaGraph Vertices with their edges, and edges
File backend Nothing: its chunks are append-only

Both calls raise ValueError before a connection is opened on a target that cannot remove, and delete_edges also raises it for an edge the schema does not declare.

Removing a scope

To replace everything one source wrote, remove the elements whose scope field holds its value, then write the new snapshot:

engine.delete_scoped(
    conn_conf,
    schema,
    "installation",
    "T1",
    vertices=["account"],
    edges=[("account", "zone", "holds")],
)

Every type named must declare the field. Edges go first; a removed vertex takes every edge that touches it, scoped or not. A None value is refused.

Target Removes a scope
Neo4j, FalkorDB Yes
Every other target No: ValueError before a connection is opened