GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • GitHubGitHub
  • DiscordDiscord
  • Setup and sample prompts
  • Question? Give us feedback →
  • Edit this page

This view

  • Original page
  • New address

GeezerVison is showing memgraph.com — node2vec

For AI agents: an index of this documentation is at https://memgraph.com/docs/llms.txt. Every page is also available as Markdown by adding .md to its URL. To search the docs, use the Memgraph docs MCP server at https://mcp-docs.memgraph.com (no API key).

  • Home
  • Getting started
    • AI coding assistants
      • Memgraph plugins
      • Docs MCP server
      • llms.txt
    • Installation
      • Docker
      • Docker Compose
      • Memgraph Cloud
      • Kubernetes
      • Linux
      • WSL
      • Direct download links
      • Source build
      • Packaging
    • CLI
  • AI applications
    • Knowledge graph creation
      • Structured2Graph
      • Unstructured2Graph
    • GraphRAG
      • Atomic GraphRAG
        • Text2Cypher
        • Local graph search
        • Query-focused summarization
      • Agentic GraphRAG
    • AI memory
      • Get started
      • Recall and memory
      • The graph
      • Privacy
      • Supported agents
      • Custom agents
      • Shared spaces
      • Configuration
    • Agentic AI
    • Graph machine learning
    • AI Toolkit and integrations
      • Memgraph MCP server
      • LangChain
      • LlamaIndex
      • LightRAG
      • Cognee
      • Mem0
  • Client libraries
    • C#
    • Go
    • GraphQL
    • Java
    • JavaScript
    • Node.js
    • PHP
    • Python
    • Rust
  • Fundamentals
    • Constraints
    • Data types
    • Data durability
    • Indexes
    • Storage access
    • Storage memory usage
    • Telemetry
    • Transactions
    • Triggers
  • Data modeling
    • Graph data model
      • LPG vs. RDF
    • Modeling guides
      • Model a knowledge graph
      • Model a graph from CSV file
    • Best practices
  • Data migration
    • Best practices
    • CSV
    • PARQUET
    • JSON
    • CYPHERL
    • Data streams
      • Transformation modules
        • Transformation modules C API
        • Transformations Python API
      • Manage streams with queries
      • Graph stream processing with Kafka
      • Kafka Connect
    • Migrate from Neo4j
      • Using CSV files
      • Using a single Cypher query
    • Migrate from RDBMS using CSV files
    • Migrate from RDBMS using MAGE modules
    • Migrate Apache Iceberg tables from data lake using Dremio
    • Migrate to Memgraph using Apache Spark
    • Migrate from Memgraph Platform to Memgraph MAGE
    • Export data
  • Querying
    • Best practices
    • Differences in Cypher implementations
    • Create graph objects
    • Read and modify data
    • Clauses
      • ALTER
      • CALL
      • CASE
      • CREATE
      • DELETE
      • DROP
      • EXPLAIN
      • FOREACH
      • LOAD CSV
      • LOAD PARQUET
      • MATCH
      • MERGE
      • OPTIONAL MATCH
      • PROFILE
      • REMOVE
      • RETURN
      • SET
      • UNION
      • UNWIND
      • USING PARALLEL EXECUTION
      • WHERE
      • WITH
    • Functions
    • Expressions
    • Subquery expressions
    • Schema
    • Text search
    • Vector search
    • Time to live
    • Query plan
    • Parallel execution
    • Exploring datasets
      • Analyzing TED talks
      • Backpacking through Europe
      • Exploring the European road network
      • Football transfers
      • GoT deaths
      • Graphing the premier league
      • Marvel universe
      • Movie recommendation
    • Sample datasets
  • Advanced algorithms
    • Available algorithms
      • algo
      • betweenness_centrality_online
      • betweenness_centrality
      • biconnected_components
      • bipartite_matching
      • bridges
      • collections
      • csv_utils
      • community_detection_online
      • community_detection
      • convert
      • convert_c
      • do
      • create
      • cross_database
      • cugraph
      • cycles
      • date
      • degree_centrality
      • distance_calculator
      • elasticsearch_synchronization
      • embeddings
      • export_util
      • gnn
      • gnn_link_prediction
      • gnn_node_classification
      • graph_analyzer
      • graph_coloring
      • graph_util
      • igraphalg
      • import_util
      • json_util
      • knn
      • katz_centrality_online
      • katz_centrality
      • kmeans_clustering
      • label
      • leiden_community_detection
      • llm
      • llm_util
      • map
      • math
      • max_flow
      • merge
      • meta_util
      • meta
      • migrate
      • mgps
      • neighbors
      • node_similarity
      • node
      • node2vec_online
      • node2vec
      • nodes
      • nxalg
      • pagerank_online
      • pagerank
      • path
      • periodic
      • refactor
      • search
      • set_cover
      • set_property
      • temporal
      • text
      • temporal_graph_networks
      • tsp
      • union_find
      • util_module
      • uuid_generator
      • vrp
      • weakly_connected_components
      • xml_module
    • Deep path traversal algorithms
    • Install MAGE
    • Run algorithms
    • Utilize NetworkX
  • Custom query modules
    • C
      • C API
      • C example
    • C++
      • C++ API
      • C++ example
    • Python
      • Python API
      • Mock Python API
      • Python example
      • Implement custom query module in Python
      • Understanding music with modules
    • Rust
      • Rust API
      • Rust example
    • Manage query modules
    • Contributing
  • Database management
    • Authentication and authorization
      • Users
      • Role-based access control
      • Migrating to v3.7 LBAC
      • Multiple roles per user and multi-tenant roles
      • Auth system integrations
      • Impersonate user
      • User profiles
      • Query privileges reference
    • Backup and restore
    • Clustering
      • Replication
        • Under the hood
        • Set up replication cluster with Docker
        • Set up replication cluster with K8s
        • Best practices
        • Reference commands
        • System replication
      • High availability
        • Under the hood
        • Querying the cluster in HA
        • Coordinator authentication
        • Set up HA cluster with Docker
        • Set up HA cluster with Docker Compose
        • Set up HA cluster with K8s
        • Best practices
        • Bulk import in analytical mode
        • Reference commands
        • Reference architectures
        • Migrating to v3.9 HA
      • FAQ
    • Configuration
    • Debugging
    • Enabling Memgraph Enterprise
    • Logs
    • Monitoring
    • Multi-tenancy
    • Tenant profiles
    • Query metadata
    • Server-side descriptions
    • Server-side parameters
    • Server stats
    • SSL encryption
    • System configuration
    • Upgrades
      • Specific versions
      • Deprecated features
  • Deployment
    • Best practices
    • Workloads
      • Memgraph in cybersecurity
      • Memgraph in GraphRAG use cases
      • Memgraph in high-throughput workloads
      • Memgraph in mission critical workloads
      • Memgraph in fraud detection
      • Memgraph in supply chain
    • Environments
      • Docker
      • Linux
      • AWS
      • GCP
      • Azure
    • Benchmarking
  • Memgraph Lab
    • Getting started
      • Installation and deployment
      • Connection types
      • Data migration
    • Querying
    • Features
      • Collections
      • CSV file import
      • Custom configuration
      • Data modeling
      • GraphChat
      • Graph schema
      • Graph Style Script (GSS)
        • Main building blocks
        • Built-in elements
        • Directive properties
        • Tutorial
      • Layout
      • Logs
      • Multi-tenancy
      • Monitoring
      • Run history
      • Sharing features
      • Single sign-on
      • Query modules
      • Streams
    • Configuration
  • Help center
    • FAQ
    • Errors
      • Auth
      • Connection
      • Durability
      • High availability
      • Memory
      • Modules
      • Ports
      • Python modules
      • Replication
      • Snapshots
      • Socket
      • SSL
      • Transactions
      • Unknown
  • Release notes

  • Memgraph Zero
    • MemGQL
      • Quick Start
      • Use Cases
        • Federated GQL
        • Public-Private Data
        • Distributed Compute
        • Enterprise Context
        • Agentic Access
      • Features
      • Connect
        • to Clickhouse
        • to DuckDB
        • to Microsoft Fabric
        • to SAP HANA
        • to Iceberg
        • to Memgraph
        • to MongoDB
        • to Neo4j
        • to Oracle
        • to PostgreSQL
        • to MySQL
        • to SQL Server
        • to Pinot
        • to Amazon Redshift
        • to Snowflake
      • Schema File
      • Multiple Graphs
      • Docker Compose
      • Reference
      • Licensing
      • Changelog
      • Telemetry

  • What's coming soon to Memgraph?
Advanced algorithmsAvailable algorithmsnode2vec

node2vec

The node2vec is a semi-supervised algorithmic framework for learning continuous feature representations for nodes in networks. The algorithm generates a mapping of nodes to a low-dimensional space of features that maximizes the likelihood of preserving network neighborhoods of nodes. By using a biased random walk procedure, it enables exploring diverse neighborhoods. In tasks such as multi-label classification and link prediction, node2vec shows great results. Check out Scalable Feature Learning for Networks by A. Grover and J. Leskovec.

The node2vec algorithm was inspired by a similar NLP technique. The same way as a document is an ordered sequence of words, by sampling sequences of nodes from the underlying network and turning a network into an ordered sequence of nodes. Although the idea of sampling is easy, choosing the actual strategy can be challenging and dependent on the techniques that will be applied afterward.

Capturing information in networks often shuttles between two kinds of similarities: homophily and structural equivalence. Under the homophily hypothesis, nodes that are highly interconnected and belong to similar network clusters or communities should be embedded closely together. In contrast, under the structural equivalence hypothesis, nodes that have similar structural roles in networks should be embedded closely together (e.g., nodes that act as hubs of their corresponding communities).

The current implementation easily captures homophily or structural equivalence by changing hyperparameters.

BFS and DFS strategies play a key role in producing representations that reflect either of the above equivalences. The neighborhoods sampled by BFS lead to embeddings that correspond closely to structural equivalence. The opposite is true for DFS. It can explore larger parts of the network as it can move further away from the source node. Therefore, DFS sampled walks accurately reflect a macro-view of the neighborhood, which is essential in inferring communities based on homophily.

By having different parameters:

  • return parameter p
  • and in-out parameterq

one decides whether to prioritize the BFS or DFS strategy when sampling. If p is smaller than 1, then we create more BFS like walks and we capture more structural equivalence. The opposite is true if q is smaller than 1. Then we capture DFS like walks and homophily.

node2vec can be used for link prediction. We recommend you use the link prediction with GNN as it’s more precise (node2vec gives a correct results in approximately 35% cases, while GNNs are correct in approximately 75% cases).

Source code
TraitValue
Module typemodule
ImplementationC++
Graph directiondirected/undirected
Edge weightsweighted/unweighted
Parallelismsequential

Procedures

You can execute this algorithm on graph projections, subgraphs or portions of the graph.

get_embeddings()

The procedure returns calculated embeddings and the corresponding list of embeddings.

Input:

  • subgraph: Graph (OPTIONAL) ➡ A specific subgraph, which is an object of type Graph 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.

  • is_directed : boolean ➡ If True, graph is treated as directed, otherwise it’s treated as undirected

  • p : float ➡ Return hyperparameter for calculating transition probabilities.

  • q : float ➡ In-out hyperparameter for calculating transition probabilities.

  • num_walks : integer ➡ The number of walks per node in the walk sampling.

  • walk_length : integer ➡ Length of one walk in the walk sampling.

  • vector_size : integer ➡ Dimensionality of the word vectors.

  • alpha : float (default=0.025) ➡ The initial learning rate.

  • window : integer ➡ The maximum distance between the current and predicted word within a sentence.

  • min_count : integer ➡ Ignores all words with total frequency lower than this.

  • seed : integer ➡ Seed for the random number generator. Initial vectors for each word are seeded with a hash of the concatenation of word + str(seed).

  • workers : integer ➡ Use these many worker threads to train the model (=faster training with multicore machines).

  • min_alpha : float ➡ Learning rate will linearly drop to min_alpha as training progresses.

  • sg : {0, 1} ➡ Training algorithm: 1 for skip-gram; otherwise CBOW.

  • hs : {0, 1} ➡ If 1, hierarchical softmax will be used for model training. If 0, and negative is > 0, negative sampling will be used.

  • negative : integer ➡ If > 0, negative sampling will be used, the integer for negative specifies how many “noise words” should be drawn (usually between 5-20). If set to 0, no negative sampling is used. Either negative must be > 0 or hs must be set to 1.

  • epochs : integer (default=5)

  • edge_weight_property : string (default="weight")

Output:

  • nodes: mgp.List[mgp.Vertex] ➡ List of nodes for which embeddings were calculated
  • embeddings: mgp.List[mgp.List[mgp.Number]] ➡ Corresponding list of embeddings

Usage:

To get the calculated embeddings and the corresponding list of embeddings, use the following query:

CALL node2vec.get_embeddings(False, 2.0, 0.5, 4, 5, 100, 0.025, 5, 1, 1, 1, 0.0001, 1, 0, 5, 5, "weight")
YIELD nodes, embeddings
RETURN nodes, embeddings;

set_embeddings()

The procedure calculates embeddings, creates a property of type List on a node with the embedding values and returns the corresponding list of embeddings.

Input:

  • subgraph: Graph (OPTIONAL) ➡ A specific subgraph, which is an object of type Graph 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.

  • is_directed : boolean ➡ If True, graph is treated as directed, else not directed

  • p : float ➡ Return hyperparameter for calculating transition probabilities.

  • q : float ➡ In-out hyperparameter for calculating transition probabilities.

  • num_walks : integer ➡ The number of walks per node in walk sampling.

  • walk_length : integer ➡ Length of one walk in walk sampling.

  • vector_size : integer ➡ Dimensionality of the word vectors.

  • alpha : float ➡ The initial learning rate.

  • window : integer ➡ The maximum distance between the current and predicted word within a sentence.

  • min_count : integer ➡ Ignores all words with total frequency lower than this.

  • seed : integer ➡ Seed for the random number generator. Initial vectors for each word are seeded with a hash of the concatenation of word + str(seed).

  • workers : integer ➡ Use these many worker threads to train the model (=faster training with multicore machines).

  • min_alpha : float ➡ Learning rate will linearly drop to min_alpha as training progresses.

  • sg : {0, 1} ➡ Training algorithm: 1 for skip-gram; otherwise CBOW.

  • hs : {0, 1} ➡ If 1, hierarchical softmax will be used for model training. If 0, and negative is non-zero, negative sampling will be used.

  • negative : integer ➡ If > 0, negative sampling will be used, the int for negative specifies how many “noise words” should be drawn (usually between 5-20). If set to 0, no negative sampling is used.

  • epochs : integer (default=5)

  • edge_weight_property : string (default="weight")

Output:

  • nodes: mgp.List[mgp.Vertex] ➡ List of nodes for which embeddings were calculated
  • embeddings: mgp.List[mgp.List[mgp.Number]] ➡ Corresponding list of embeddings

Usage:

To calculate embeddings, use the following query:

CALL node2vec.set_embeddings(False, 2.0, 0.5, 4, 5, 100, 0.025, 5, 1, 1, 1, 0.0001, 1, 0, 5, 5, "weight")
YIELD nodes, embeddings
RETURN nodes, embeddings;

help()

The procedure returns the list of available procedures and input parameters.

Output:

  • name: string ➡ Names of the available functions.
  • value: string ➡ Documentation for every function.

Usage:

To get help about the queries from this module, use the following query:

CALL node2vec.help()
YIELD name, value
RETURN name, value;

Example

Database state

The database contains the following data:

Input graph

Created with the following Cypher queries:

MERGE (n:Node {id: 1}) MERGE (m:Node {id: 6}) CREATE (n)-[:RELATION]->(m);
MERGE (n:Node {id: 2}) MERGE (m:Node {id: 6}) CREATE (n)-[:RELATION]->(m);
MERGE (n:Node {id: 10}) MERGE (m:Node {id: 5}) CREATE (n)-[:RELATION]->(m);
MERGE (n:Node {id: 5}) MERGE (m:Node {id: 2}) CREATE (n)-[:RELATION]->(m);
MERGE (n:Node {id: 9}) MERGE (m:Node {id: 7}) CREATE (n)-[:RELATION]->(m);
MERGE (n:Node {id: 7}) MERGE (m:Node {id: 3}) CREATE (n)-[:RELATION]->(m);
MERGE (n:Node {id: 3}) MERGE (m:Node {id: 6}) CREATE (n)-[:RELATION]->(m);
MERGE (n:Node {id: 9}) MERGE (m:Node {id: 8}) CREATE (n)-[:RELATION]->(m);
MERGE (n:Node {id: 8}) MERGE (m:Node {id: 4}) CREATE (n)-[:RELATION]->(m);
MERGE (n:Node {id: 4}) MERGE (m:Node {id: 6}) CREATE (n)-[:RELATION]->(m);

Set embeddings

Use the following query to set a new node property with the calculated embeddings:

CALL node2vec.set_embeddings(False, 2.0, 0.5, 4, 5, 2) 
YIELD nodes, embeddings
RETURN nodes, embeddings;

Check embeddings

Run the following query to check the embeddings:

MATCH (n)
RETURN n.id as node, n.embedding as embedding
ORDER BY n.id;

Result:

+-------------------------+---------------------------+
| node                    | embedding                 |
+-------------------------+---------------------------+
| 1                       | [-0.0127249, -0.00772426] |
| 2                       | [0.08956, -0.245196]      |
| 3                       | [-0.0144552, -0.0900884]  |
| 4                       | [-0.0301506, -0.0306455]  |
| 5                       | [0.203085, 0.237084]      |
| 6                       | [-0.163547, 0.22033]      |
| 7                       | [0.0376115, -0.204049]    |
| 8                       | [0.0681532, -0.246293]    |
| 9                       | [-0.122394, 0.0467055]    |
| 10                      | [-0.097512, -0.0980783]   |
+-------------------------+---------------------------+
node2vec_onlinenodes
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.