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 become Valor nodes, and duplicate keys are refused.

  • Update: update=True MERGEs the node and merges its attributes. replace=True deletes 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=True recursively deletes WeakNode children, detach=True (CASCADE) removes the edges and keeps the neighbours, and on_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: Neo4jGraph

Memgraph-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 edition is passed — Neo4j editions don’t apply.

__init__(url, user, password, database=None, auto_pk_indexes=False, **driver_config)[source]
Parameters:
  • url (str)

  • user (str)

  • password (str)

  • database (str | None)

  • auto_pk_indexes (bool)

  • driver_config (Any)

Return type:

None

server_edition()[source]

"enterprise" if the Memgraph server has a valid Enterprise license (SHOW LICENSE INFO), "community" otherwise.

Return type:

str

drop_constraint(name)[source]

Not supported: Memgraph constraints have no name.

Parameters:

name (str)

Return type:

None