Memgraph backend
cvcdocdb.memgraph_graph stores graphs in Memgraph. It reuses the
Neo4j backend’s logic (same API, same change-propagation policy on insert,
update and delete) and overrides only the Cypher that Memgraph doesn’t
support.
MemgraphGraph — Memgraph backend for the DRM graph model.
Memgraph speaks the Bolt protocol and openCypher,
so it is driven with the same neo4j Python driver, and
MemgraphGraph reuses Neo4jGraph’s
logic unchanged. The change-propagation policy is therefore identical to
the Neo4j backend:
Insert: a WeakNode inserts its parent first (
insert_parent) and the parent→child relation carries_propagate=TRUE. A WeakNode without its parent is refused (nothing is written), child keys must reference the parent’s keys, dependencies becomeValornodes, and duplicate keys are refused.Update:
update=TrueMERGEs the node and merges its attributes.replace=Truedeletes the existing node with propagation (its WeakNode descendants go too) and creates a fresh one.Delete: RESTRICT (default) refuses nodes with WeakNode children or edges.
propagation=Truerecursively deletes WeakNode children,detach=True(CASCADE) removes the edges and keeps the neighbours, andon_delete="set_null"is also supported.Relations: FK validation of both endpoints, plus
update/replace.
test/test_memgraph_graph.py runs the same propagation scenarios on both
backends and checks they leave the same graph and raise the same errors.
Only the operations whose Cypher differs are overridden here: listing and
creating pk indexes (SHOW INDEX INFO / CREATE INDEX ON :L(p)) and
listing labels and relationship types (Memgraph has no db.labels()).
The Neo4j Enterprise operations of cvcdocdb.neo4j_enterprise are not
available.
Example
>>> graph = MemgraphGraph("bolt://localhost:7687", "", "")
>>> graph.insertNode(Node(pk={"doc": "DOC-001"}, main_label="Document"))
>>> graph.close()
- class cvcdocdb.memgraph_graph.MemgraphGraph(url, user, password, database=None, auto_pk_indexes=False, **driver_config)[source]
Bases:
Neo4jGraphMemgraph-backed graph store, with the same API and semantics as
Neo4jGraph.- Parameters:
url (str) – Bolt URL of the Memgraph server (e.g.
bolt://localhost:7687).user (str) – Username (
""if authentication is disabled, Memgraph’s default).password (str) – Password (
""if authentication is disabled).database (Optional[str]) – Target database. Memgraph Community has a single database (
memgraph); multi-tenancy needs a Memgraph Enterprise license.auto_pk_indexes (bool) – See
Neo4jGraph.**driver_config (Any) – Forwarded to
neo4j.GraphDatabase.driver().
- Raises:
TypeError – If
editionis passed — Neo4j editions don’t apply.