Overview of Memgraph Custom Query Modules in Python
mgp module, which acts as a wrapper around the Memgraph C API.website·Indexed 35 days ago
https://memgraph.com/docsMemgraph is a high-performance, in-memory graph database designed to power real-time AI context. The documentation covers installation across Docker, Kubernetes, and various Linux distributions (Debian, Ubuntu, CentOS, Fedora, Red Hat), as well as Memgraph Cloud management. It provides comprehensive guides for client libraries in Python, JavaScript, Node.js, Java, Go, Rust, C#, and PHP, and details the AI ecosystem including GraphRAG and knowledge graph creation.
mgp module, which acts as a wrapper around the Memgraph C API.Memgraph allows extending the Cypher query language with user-written procedures grouped into query modules. These modules can be written in C, C++, Python, and Rust.
.so shared library files..py files.Naming and Mapping:
example.so or example.py is mapped to the example module.procedure within that file is called in Cypher as example.procedure().Memgraph uses the Cypher language to perform database operations. The available clauses include:
ALTER: Modify existing enum definitions.CALL: Execute a subquery within a query.CASE: Create conditional expressions.CREATE: Create new nodes and relationships.DELETE: Delete nodes and relationships.DROP: Remove constraints, indexes, or the entire database.EXPLAIN: Inspect a query's execution plan.FOREACH: Iterate over a list of elements.LOAD CSV: Import data from a CSV file.MATCH: Search for patterns.MERGE: Ensure a pattern exists (creates it if it does not).OPTIONAL MATCH: Search for patterns, filling missing parts with nulls if not found.PROFILE: Generate a detailed report on query plan behavior.REMOVE: Remove labels and properties.RETURN: Define the result set to be presented to the user.SET: Add or update labels and properties.UNION / UNION ALL: Combine results from multiple queries.UNWIND: Expand a list of values into individual rows.WHERE: Filter matched data.WITH: Chain multiple read and write operations.USING PERIODIC COMMIT num_rows: Batch a query for periodic execution.CALL {subquery} IN TRANSACTIONS OF num_rows ROWS: Batch a subquery for periodic execution.Memgraph Enterprise unlocks advanced capabilities across several categories:
The graph_analyzer module extracts structural properties from an undirected, unweighted graph. The available analytics include:
Time-to-Live (TTL) allows vertices and edges to be tagged with an expiration time. When a vertex expires, it and all its associated edges are deleted. TTL is implemented as a background job that periodically executes deletions; therefore, objects are deleted eventually after expiration, not necessarily immediately.
Important Constraints:
TTL and property ttl are reserved for this feature.node2vec is a semi-supervised framework that maps nodes to a low-dimensional feature space while preserving network neighborhoods. It uses biased random walks to capture two types of similarities:
q < 1).p < 1).It supports directed/undirected graphs and weighted/unweighted edges.
The embeddings module computes sentence embeddings for text, supporting two backends:
SentenceTransformer models from Hugging Face running on CPU or CUDA within the Memgraph process.Routing is determined by the model_name configuration: a LiteLLM-style provider prefix (e.g., openai/text-embedding-3-small) triggers a remote call; a bare name or Hugging Face path (e.g., all-MiniLM-L6-v2 or BAAI/bge-small-en-v1.5) loads the model locally.
DUMP DATABASE exports. They are primarily used to document the data model for human developers and AI-driven tools (like LLM clients, GraphChat, and MCP) that consume SHOW SCHEMA INFO.community_detection_online module implements the LabelRankT dynamic community detection algorithm. It is a label propagation algorithm where nodes determine their communities by learning from neighbors. It is designed for large-scale graphs and is ideal for streaming platforms because it only processes sections of the graph affected by updates. The algorithm is deterministic and supports both directed/undirected and weighted/unweighted graphs. Note: This is a Memgraph Enterprise feature and requires an Enterprise license.Memgraph can connect to Kafka, Redpanda, and Pulsar sources to ingest data for querying with MAGE algorithms or custom procedures. To implement a stream, a user must follow these steps:
CREATE <streaming platform> STREAM query.START STREAM query.