What are query modules in Memgraph?

Question:

I keep coming across the term "query module" in blog posts related to Memgraph. What are query modules and when should I use one?

Asked By: KWriter

||

Answers:

Memgraph supports extending the query language with user-written procedures in C, C++, Python, and Rust. These procedures are grouped into modules – query modules files (either *.so or *.py files).

Some query modules are built-in, and others, like those that can help you solve complex graph issues, are available as part of the MAGE library you can add to your Memgraph installation. The library is already included if you are using Memgraph Platform or Memgraph MAGE Docker images to run Memgraph.

You can also implement custom query modules. Every single Memgraph installation comes with the example.so and py_example.py query modules located in the /usr/lib/memgraph/query_modules directory. They were provided as examples of query modules for you to examine and learn from.

Each query module file corresponds to one query module, and file names are mapped as query module names. For example, example.so will be mapped as an example module, and py_example.py will be mapped as a py_example module. If each module file has a procedure called procedure defined, those procedures would be mapped in the Cypher query language as example.procedure() and py_example.procedure() respectively.

Regardless of where they come from and who wrote them, all modules need to be loaded into Memgraph so that they can be called while querying the database. They are either loaded automatically when Memgraph starts or manually if they were added while Memgraph was already running.

Answered By: KWriter