Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memgraph 2.21 documentation changes #1009

Merged
merged 38 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ae1822e
Adding bugfix #2361 to release notes
hal-eisen-MG Oct 7, 2024
3b38e40
Merge branch 'main' into memgraph-2-21
hal-eisen-MG Oct 7, 2024
0edda5a
Added changelog for #2352, #2366 and #2371
hal-eisen-MG Oct 7, 2024
50858b2
Typo
hal-eisen-MG Oct 7, 2024
16b6392
Remove trailing slash in URL
hal-eisen-MG Oct 8, 2024
2f4e8a1
Escaping curly braces
hal-eisen-MG Oct 8, 2024
2839e3d
HA bugfixes from Andi (2421 and 2422)
hal-eisen-MG Oct 18, 2024
ffc1c4c
Merge branch 'main' into memgraph-2-21
hal-eisen-MG Oct 18, 2024
87b2747
changelog for mgp::memory deprecation
hal-eisen-MG Oct 18, 2024
d109432
Re-ordering 2.21 and 2.20.1
hal-eisen-MG Oct 18, 2024
559a30e
Remove toolchain-v4 and obsolete versions of Linux
hal-eisen-MG Oct 23, 2024
34e2533
Changelog for 2430 (coordinators using only 1 log type
hal-eisen-MG Oct 25, 2024
11b1223
Add callout for breaking change (coordinator log store)
hal-eisen-MG Oct 25, 2024
74e4e5b
C++ API remove mgp::memory usage note (#1016)
Ignition Nov 3, 2024
42d1d8d
Add changelog item for the query module memory guard
gitbuda Nov 3, 2024
81c334d
Iteration under the release notes
gitbuda Nov 3, 2024
c16deab
Add Leiden static community detection algorithm (#1014)
DavIvek Nov 3, 2024
4c418e5
Add the show schema info changelog item
gitbuda Nov 3, 2024
ce2a29d
Add all changelog items, Grammarly check TBD
gitbuda Nov 4, 2024
39c37ac
Improve breaking change
as51340 Nov 4, 2024
0c6849d
Add explanation for exception handling in Leiden community detection …
DavIvek Nov 4, 2024
9820a55
Spatial index and data type docs (#1018)
imilinovic Nov 5, 2024
d8b6001
Update the changelog
gitbuda Nov 5, 2024
4beeac2
Improve getting building from soruce
gitbuda Nov 5, 2024
e5b7d7b
Improve changelog
gitbuda Nov 5, 2024
0ca7b7c
Add Debian 12 toolchain link
gitbuda Nov 5, 2024
5e6272c
Merge main
gitbuda Nov 5, 2024
a441da1
Merge branch 'main' into memgraph-2-21
katarinasupe Nov 5, 2024
3198a17
update changelog titles
katarinasupe Nov 5, 2024
86097b7
Merge branch 'main' into memgraph-2-21
katarinasupe Nov 5, 2024
7bb479d
update algorithm pages (#1020)
DavIvek Nov 5, 2024
102d8f1
Add custom SSL for Lab configuration page (#1030)
AlexIchenskiy Nov 5, 2024
c8ec32f
Merge branch 'main' into memgraph-2-21
katarinasupe Nov 5, 2024
b1f2d2e
update cypher differences
katarinasupe Nov 5, 2024
98f071b
Add more details related to the schema info v2 (#1029)
andrejtonev Nov 5, 2024
68cba02
Merge branch 'main' into memgraph-2-21
gitbuda Nov 6, 2024
20d0335
Remove redundant empty lines
gitbuda Nov 6, 2024
e1298b9
More lines
gitbuda Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pages/advanced-algorithms/available-algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ library](/advanced-algorithms/install-mage).

| Algorithms | Lang | Description |
|------------------------------------------------------------------------------------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [algo](/advanced-algorithms/available-algorithms/algo) | C++ | The algo module provides users with a powerful set of graph algorithms, enabling users to perform complex graph-based operations and computations, such as graph traversal, edge detection, and more. |
| [algo](/advanced-algorithms/available-algorithms/algo) | C++ | The algo module provides users with a powerful set of graph algorithms, enabling users to perform complex graph-based operations and computations, such as graph traversal, edge detection, and more. |
| [betweenness_centrality](/advanced-algorithms/available-algorithms/betweenness_centrality) | C++ | The betweenness centrality of a node is defined as the sum of the of all-pairs shortest paths that run through the node, divided by the number of all-pairs shortest paths in the graph. The algorithm has O(nm) time complexity. |
| [biconnected_components](/advanced-algorithms/available-algorithms/biconnected_components) | C++ | Algorithm for calculating maximal biconnected subgraph. A biconnected subgraph is a subgraph with a property that if any vertex were to be removed, the graph will remain connected. |
| [bipartite_matching](/advanced-algorithms/available-algorithms/bipartite_matching) | C++ | Algorithm for calculating maximum bipartite matching, where matching is a set of nodes chosen in such a way that no two edges share an endpoint. |
Expand All @@ -36,6 +36,7 @@ library](/advanced-algorithms/install-mage).
| [graph_coloring](/advanced-algorithms/available-algorithms/graph_coloring) | Python | Algorithm for assigning labels to the graph elements subject to certain constraints. In this form, it is a way of coloring the graph vertices such that no two adjacent vertices are of the same color. |
| [katz_centrality](/advanced-algorithms/available-algorithms/katz_centrality) | C++ | Katz centrality is a centrality measurement that outputs a node's influence based on the number of shortest paths and their weighted length. |
| [kmeans_clustering](/advanced-algorithms/available-algorithms/kmeans_clustering) | Python | An algorithm for clustering given data. |
| [leiden_community_detection](/advanced-algorithms/available-algorithms/leiden_community_detection) | C++ | The Leiden method for community detection is an improvement over the Louvain method, designed to find communities with maximum modularity in a graph while addressing issues of disconnected communities. Runs in _O_(L\*E) time and _O_(V\*E) space, where *L* is the number of iterations of the algorithm, E is the number of edges, V is the number of nodes. |
| [max_flow](/advanced-algorithms/available-algorithms/max_flow) | Python | An algorithm for finding a flow through a graph such that it is the maximum possible flow. |
| [node_similarity](/advanced-algorithms/available-algorithms/node_similarity) | C++ | A module that contains similarity measures for calculating the similarity between two nodes. |
| [pagerank](/advanced-algorithms/available-algorithms/pagerank) | C++ | Algorithm that yields the influence measurement based on the recursive information about the connected nodes influence. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
---
title: leiden_community_detection
description: Explore Memgraph's Leiden community detection capabilities and learn how to analyze the structure of complex networks. Access tutorials and comprehensive documentation to enhance your understanding of Leiden community detection algorithm.
---

import { Steps } from 'nextra/components'
import { Callout } from 'nextra/components'
import { Card, Cards } from 'nextra/components'
import GitHub from '/components/icons/GitHub'

# leiden_community_detection

Community in graphs mirrors real-world communities, like social circles. In a
graph, communities are sets of nodes. M. Girvan and M. E. J. Newman note that
nodes in a community connect more intensely with each other than with outside
nodes.

This module employs the [Leiden
algorithm](https://en.wikipedia.org/wiki/Leiden_algorithm) for community
detection based on paper [*From Louvain to Leiden: guaranteeing well-connected
communities*](https://arxiv.org/abs/1810.08473). The Leiden algorithm is a
hierarchical clustering algorithm, that recursively merges communities into
single nodes by greedily optimizing the modularity and the process repeats in
the condensed graph. It enhances the Louvain algorithm by addressing its
limitations, particularly in situations where some identified communities are
not well-connected. This improvement is made by periodically subdividing
communities into smaller, well-connected groups. With an $\mathcal{O}(Lm)$
runtime for $m$ edges and $L$ number of iterations, it suits large graphs. The
space complexity if $\mathcal{O}(VE)$ for $V$ nodes and $E$ edges.

<Cards>
<Card
icon={<GitHub />}
title="Source code"
href="https://github.com/memgraph/mage/blob/main/cpp/leiden_community_detection_module/leiden_community_detection_module.cpp"
/>
</Cards>

| Trait | Value |
| ------------------------ | --------------------- |
| **Module type** | algorithm |
| **Implementation** | C++ |
| **Graph direction** | undirected |
| **Relationship weights** | weighted / unweighted |
| **Parallelism** | parallel |

## Procedures

<Callout type="info">
You can execute this algorithm on [graph projections, subgraphs or portions of
the graph](/advanced-algorithms/run-algorithms#run-procedures-on-subgraph).
</Callout>

### `get()`

Computes graph communities using the Leiden algorithm. For more information on
specific algorithm parameters and their use, refer to the paper [*From Louvain
to Leiden: guaranteeing well-connected
communities*](https://arxiv.org/abs/1810.08473).

{<h4> Input: </h4>}

- `subgraph: Graph` (**OPTIONAL**) ➡ A specific subgraph, which is an [object
of type
Graph](/advanced-algorithms/run-algorithms#run-procedures-on-subgraph)
returned by the `project()` function, on which the algorithm is run. If
subgraph is not specified, the algorithm is computed on the entire graph by
default.
- `weight: string (default=null)` ➡ Specifies the name of the property
containing the edge weight. Users can set their own weight property; if this
property is not specified, the algorithm uses the `weight` edge attribute by
default. If neither is set, each edge's weight defaults to `1`. To utilize a
custom weight property, the user must set the
`--storage-properties-on-edges=true` flag.
- `gamma: double (default=1.0)` ➡ Resolution parameter used when computing the
modularity. Higher resolutions lead to more smaller communities, while lower
resolutions lead to fewer larger communities.
- `theta: double (default=0.01)` ➡ Controls the randomness while breaking a
community into smaller ones.
- `resolution_parameter: double (default=0.01)` ➡ Minimum change in modularity
that must be achieved when merging nodes within the same community.
- `max_iterations: int (default=inf)` ➡ Maximum number of iterations the
algorithm will perform. If set to infinity, the algorithm will run until
convergence is reached.

{<h4> Output: </h4>}

- `node: Vertex` ➡ A graph node for which the algorithm was performed and
returned as part of the results.
- `community_id: integer` ➡ Community ID. Defaults to $-1$ if the node does not
belong to any community.
- `communities: list` ➡ List representing the hierarchy of communities that a
node has belonged to across iterations.

{<h4> Usage: </h4>}

Use the following query to detect communities:

```cypher
CALL leiden_community_detection.get()
YIELD node, community_id, communities;
```

<Callout type="info">
The algorithm throws an exception if no communities are detected. This can happen if in the first iteration
all nodes merge into a single community or if each node forms its own. If this occurs, try adjusting the algorithm's `gamma` parameter.
</Callout>

### `get_subgraph()`

Computes graph communities over a subgraph using the Leiden method.

{<h4> Input: </h4>}

- `subgraph: Graph` (**OPTIONAL**) ➡ A specific subgraph, which is an [object
of type
Graph](/advanced-algorithms/run-algorithms#run-procedures-on-subgraph)
returned by the `project()` function, on which the algorithm is run. If
subgraph is not specified, the algorithm is computed on the entire graph by
default.
- `subgraph_nodes: List[Node]` ➡ List of nodes in the subgraph.
- `subgraph_relationships: List[Relationship]` ➡ List of relationships in the
subgraph.
- `weight: string (default=null)` ➡ Specifies the name of the property
containing the edge weight. Users can set their own weight property; if this
property is not specified, the algorithm uses the `weight` edge attribute by
default. If neither is set, each edge's weight defaults to `1`. To utilize a
custom weight property, the user must set the
`--storage-properties-on-edges=true` flag.
- `gamma: double (default=1.0)` ➡ Resolution parameter used when computing the
modularity. Higher resolutions lead to more smaller communities, while lower
resolutions lead to fewer larger communities.
- `theta: double (default=0.01)` ➡ Controls the randomness while breaking a
community into smaller ones.
- `resolution_parameter: double (default=0.01)` ➡ Minimum change in modularity
that must be achieved when merging nodes within the same community.
- `max_iterations: int (default=inf)` ➡ Maximum number of iterations the
algorithm will perform. If set to infinity, the algorithm will run until
convergence is reached.

{<h4> Output: </h4>}

- `node: Vertex` ➡ A graph node for which the algorithm was performed and
returned as part of the results.
- `community_id: int` ➡ Community ID. Defaults to $-1$ if the node does not
belong to any community.
- `communities: list` ➡ List representing the hierarchy of communities that a
node has belonged to across iterations.

{<h4> Usage: </h4>}

Use the following query to compute communities in a subgraph:

```cypher
MATCH (a)-[e]-(b)
WITH COLLECT(a) AS nodes, COLLECT (e) AS relationships
CALL leiden_community_detection.get_subgraph(nodes, relationships)
YIELD node, community_id, communities;
```

## Single Iteration Example

<Steps>

{<h3> Database state </h3>}

The database contains the following data:

![](/pages/advanced-algorithms/available-algorithms/community_detection/community-detection-1.png)

Created with the following Cypher queries:

```cypher
MERGE (a: Node {id: 0}) MERGE (b: Node {id: 1}) CREATE (a)-[r: Relation]->(b);
MERGE (a: Node {id: 0}) MERGE (b: Node {id: 2}) CREATE (a)-[r: Relation]->(b);
MERGE (a: Node {id: 1}) MERGE (b: Node {id: 2}) CREATE (a)-[r: Relation]->(b);
MERGE (a: Node {id: 2}) MERGE (b: Node {id: 3}) CREATE (a)-[r: Relation]->(b);
MERGE (a: Node {id: 3}) MERGE (b: Node {id: 4}) CREATE (a)-[r: Relation]->(b);
MERGE (a: Node {id: 3}) MERGE (b: Node {id: 5}) CREATE (a)-[r: Relation]->(b);
MERGE (a: Node {id: 4}) MERGE (b: Node {id: 5}) CREATE (a)-[r: Relation]->(b);
```

{<h3> Detect communities </h3>}

Get communities using the following query:

```cypher
CALL leiden_community_detection.get()
YIELD node, community_id, communities
RETURN node.id AS node_id, community_id, communities
ORDER BY node_id;
```

Results show which nodes belong to community 0, and which to community 1.

```plaintext
+--------------+--------------+--------------+
| node_id | community_id | communities |
+--------------+--------------+--------------+
| 0 | 0 | [0] |
| 1 | 0 | [0] |
| 2 | 0 | [0] |
| 3 | 1 | [1] |
| 4 | 1 | [1] |
| 5 | 1 | [1] |
+--------------+--------------+--------------+
```

</Steps>

## Multiple Iterations Example

<Steps>

{<h3> Database state </h3>}

The database contains the following data:

![](/pages/advanced-algorithms/available-algorithms/katz_centrality/memgraph-katz.png)

Created with the following Cypher queries:

```cypher
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 0}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 10}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 1}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 8}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 10}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 10}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 4}) MERGE (b:Node {id: 10}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 4}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 5}) MERGE (b:Node {id: 10}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 5}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 6}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 7}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 8}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 8}) MERGE (b:Node {id: 10}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 9}) MERGE (b:Node {id: 10}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 10}) MERGE (b:Node {id: 9}) CREATE (a)-[:RELATION]->(b);
```

{<h3> Detect communities </h3>}

Get communities using the following query:

```cypher
CALL leiden_community_detection.get()
YIELD node, community_id, communities
RETURN node.id AS node_id, community_id, communities
ORDER BY node_id;
```

The results show which nodes belong to community 0 and which to community 1, as well as how nodes changed communities across iterations.

```plaintext
+--------------+--------------+--------------+
| node_id | community_id | communities |
+--------------+--------------+--------------+
| 0 | 1 | [0, 1] |
| 1 | 1 | [0, 1] |
| 2 | 0 | [1, 0] |
| 3 | 1 | [2, 1] |
| 4 | 1 | [3, 1] |
| 5 | 0 | [4, 0] |
| 6 | 0 | [1, 0] |
| 7 | 0 | [1, 0] |
| 8 | 0 | [1, 0] |
| 9 | 1 | [2, 1] |
| 10 | 1 | [2, 1] |
+--------------+--------------+--------------+
```

</Steps>
36 changes: 21 additions & 15 deletions pages/custom-query-modules/cpp/cpp-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,36 @@ description: Get your hands on the API documentation for mgp.hpp, covering decla
# Query modules C++ API

This is the API documentation for `mgp.hpp`, which contains declarations of all
functions in the C++ API for implementing query module procedures and functions.
The source file can be found in the Memgraph installation directory, under
`/usr/include/memgraph`.
functions in the C++ API for implementing query module procedures and
functions. The source file can be found in the Memgraph installation directory,
under `/usr/include/memgraph`.

To see how to implement query modules in C++, take a look at
[the example we provided](/custom-query-modules/python/python-example).
To see how to implement query modules in C++, take a look at [the example we
provided](/custom-query-modules/python/python-example).

If you install any C++ modules after running Memgraph, you’ll need to [load
them into Memgraph](/custom-query-modules/manage-query-modules#loading-query-modules) or restart
Memgraph in order to use them.
them into
Memgraph](/custom-query-modules/manage-query-modules#loading-query-modules) or
restart Memgraph in order to use them.

## Functions and procedures

With this API it’s possible to extend your Cypher queries with **functions** and **procedures** with
`AddProcedure` and `AddFunction`.
With this API it’s possible to extend your Cypher queries with **functions**
and **procedures** with `AddProcedure` and `AddFunction`.

The API needs memory access to add procedures and functions, this can be done with either `mgp::MemoryDispatcherGuard guard(memory);` or `mgp::memory = memory;`, where the use of the former is advised since `mgp::memory = memory;` is not thread-safe and will be deprecated in the future.
The API needs memory access to add procedures and functions, this can be done
with `mgp::MemoryDispatcherGuard guard(memory);`. Old code used `mgp::memory =
memory;`, but this is not thread-safe and has been deprecated. v2.18.1 onwards
you should modify your C++ modules and recompile. v2.21 onwards setting
`mgp::memory` will cause a compilation error, so the guard has to be used.

Functions are simple operations that return a single value and can be used in any expression or predicate.

Procedures are more complex computations that may modify the graph, and their output is available to
later processing steps in your query. A procedure may only be run from `CALL` clauses.
The output is a stream of **records** that is made accessible with a `YIELD` clause.
Functions are simple operations that return a single value and can be used in
any expression or predicate.

Procedures are more complex computations that may modify the graph, and their
output is available to later processing steps in your query. A procedure may
only be run from `CALL` clauses. The output is a stream of **records** that is
made accessible with a `YIELD` clause.

### AddProcedure

Expand Down
Loading