6.4.1. Node Similarity

This section describes the Node Similarity algorithm in the Neo4j Graph Data Science library. The algorithm is based on the Jaccard Similarity score.

This topic includes:

6.4.1.1. Introduction

The Node Similarity algorithm compares a set of nodes based on the nodes they are connected to. Two nodes are considered similar if they share many of the same neighbors. Node Similarity computes pair-wise similarities based on the Jaccard metric, also known as the Jaccard Similarity Score.

Jaccard Similarity is computed using the following formula:

jaccard

The input of this algorithm is a bipartite, connected graph containing two disjoint node sets. Each relationship starts from a node in the first node set and ends at a node in the second node set.

The Node Similarity algorithm compares each node that has outgoing relationships with each other such node. For every node n, we collect the outgoing neighborhood N(n) of that node, that is, all nodes m such that there is a relationship from n to m. For each pair n, m, the algorithm computes a similarity for that pair which is the Jaccard similarity of N(n) and N(m).

The complexity of this comparison grows quadratically with the number of nodes to compare. The algorithm reduces the complexity by ignoring disconnected nodes.

In addition to computational complexity, the memory requirement for producing results also scales roughly quadratically. In order to bound memory usage, the algorithm requires an explicit limit on the number of results to compute per node. This is the 'topK' parameter. It can be set to any value, except 0.

The output of the algorithm are new relationships between pairs of the first node set. Similarity scores are expressed via relationship properties.

A related function for computing Jaccard similarity is described in Section 6.4.3, “Jaccard Similarity”.

For more information on this algorithm, see:

Running this algorithm requires sufficient available memory. Before running this algorithm, we recommend that you read Section 3.1, “Memory Estimation”.

6.4.1.2. Syntax

This section covers the syntax used to execute the Node Similarity algorithm in each of its execution modes. We are describing the named graph variant of the syntax. To learn more about general syntax variants, see Section 6.1, “Syntax overview”.

Example 6.10. Node Similarity syntax per mode

Run Node Similarity in stream mode on a named graph. 

CALL gds.nodeSimilarity.stream(
  graphName: String,
  configuration: Map
) YIELD
  node1: Integer,
  node2: Integer,
  similarity: Float

Table 6.248. Parameters
Name Type Default Optional Description

graphName

String

n/a

no

The name of a graph stored in the catalog.

configuration

Map

{}

yes

Configuration for algorithm-specifics and/or graph filtering.

Table 6.249. General configuration for algorithm execution on a named graph.
Name Type Default Optional Description

nodeLabels

String[]

['*']

yes

Filter the named graph using the given node labels.

relationshipTypes

String[]

['*']

yes

Filter the named graph using the given relationship types.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm.

Table 6.250. Algorithm specific configuration
Name Type Default Optional Description

similarityCutoff

Float

1E-42

yes

Lower limit for the similarity score to be present in the result. . Values must be between 0 and 1.

degreeCutoff

Integer

1

yes

Lower limit on the node degree for a node to be considered in the comparisons. This value can not be lower than 1.

topK

Integer

10

yes

Limit on the number of scores per node. The K largest results are returned. This value cannot be lower than 1.

bottomK

Integer

10

yes

Limit on the number of scores per node. The K smallest results are returned. This value cannot be lower than 1.

topN

Integer

0

yes

Global limit on the number of scores computed. The N largest total results are returned. This value cannot be negative, a value of 0 means no global limit.

bottomN

Integer

0

yes

Global limit on the number of scores computed. The N smallest total results are returned. This value cannot be negative, a value of 0 means no global limit.

Table 6.251. Results
Name Type Description

node1

Integer

Node ID of the first node.

node2

Integer

Node ID of the second node.

similarity

Float

Similarity score for the two nodes.

Run Node Similarity in stats mode on a named graph. 

CALL gds.nodeSimilarity.stats(
  graphName: String,
  configuration: Map
)
YIELD
  createMillis: Integer,
  computeMillis: Integer,
  postProcessingMillis: Integer,
  nodesCompared: Integer,
  similarityPairs: Integer,
  similarityDistribution: Map,
  configuration: Map

Table 6.252. Parameters
Name Type Default Optional Description

graphName

String

n/a

no

The name of a graph stored in the catalog.

configuration

Map

{}

yes

Configuration for algorithm-specifics and/or graph filtering.

Table 6.253. General configuration for algorithm execution on a named graph.
Name Type Default Optional Description

nodeLabels

String[]

['*']

yes

Filter the named graph using the given node labels.

relationshipTypes

String[]

['*']

yes

Filter the named graph using the given relationship types.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm.

Table 6.254. Algorithm specific configuration
Name Type Default Optional Description

similarityCutoff

Float

1E-42

yes

Lower limit for the similarity score to be present in the result. . Values must be between 0 and 1.

degreeCutoff

Integer

1

yes

Lower limit on the node degree for a node to be considered in the comparisons. This value can not be lower than 1.

topK

Integer

10

yes

Limit on the number of scores per node. The K largest results are returned. This value cannot be lower than 1.

bottomK

Integer

10

yes

Limit on the number of scores per node. The K smallest results are returned. This value cannot be lower than 1.

topN

Integer

0

yes

Global limit on the number of scores computed. The N largest total results are returned. This value cannot be negative, a value of 0 means no global limit.

bottomN

Integer

0

yes

Global limit on the number of scores computed. The N smallest total results are returned. This value cannot be negative, a value of 0 means no global limit.

Table 6.255. Results
Name Type Description

createMillis

Integer

Milliseconds for loading data.

computeMillis

Integer

Milliseconds for running the algorithm.

postProcessingMillis

Integer

Milliseconds for computing component count and distribution statistics.

similarityPairs

Integer

The number of pairs of similar nodes computed.

similarityDistribution

Map

Map containing min, max, mean as well as p50, p75, p90, p95, p99 and p999 percentile values of the computed similarity results.

configuration

Map

The configuration used for running the algorithm.

Run Node Similarity in mutate mode on a graph stored in the catalog. 

CALL gds.nodeSimilarity.mutate(
  graphName: String,
  configuration: Map
)
YIELD
  createMillis: Integer,
  computeMillis: Integer,
  mutateMillis: Integer,
  postProcessingMillis: Integer,
  relationshipsWritten: Integer,
  nodesCompared: Integer,
  similarityDistribution: Map,
  configuration: Map

Table 6.256. Parameters
Name Type Default Optional Description

graphName

String

n/a

no

The name of a graph stored in the catalog.

configuration

Map

{}

yes

Configuration for algorithm-specifics and/or graph filtering.

Table 6.257. General configuration for algorithm execution on a named graph.
Name Type Default Optional Description

mutateRelationshipType

String

n/a

no

The relationship type used for the new relationships written to Neo4j.

mutateProperty

String

n/a

no

The relationship property in the GDS graph to which the similarity score is written.

nodeLabels

String[]

['*']

yes

Filter the named graph using the given node labels.

relationshipTypes

String[]

['*']

yes

Filter the named graph using the given relationship types.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm.

Table 6.258. Algorithm specific configuration
Name Type Default Optional Description

similarityCutoff

Float

1E-42

yes

Lower limit for the similarity score to be present in the result. . Values must be between 0 and 1.

degreeCutoff

Integer

1

yes

Lower limit on the node degree for a node to be considered in the comparisons. This value can not be lower than 1.

topK

Integer

10

yes

Limit on the number of scores per node. The K largest results are returned. This value cannot be lower than 1.

bottomK

Integer

10

yes

Limit on the number of scores per node. The K smallest results are returned. This value cannot be lower than 1.

topN

Integer

0

yes

Global limit on the number of scores computed. The N largest total results are returned. This value cannot be negative, a value of 0 means no global limit.

bottomN

Integer

0

yes

Global limit on the number of scores computed. The N smallest total results are returned. This value cannot be negative, a value of 0 means no global limit.

Table 6.259. Results
Name Type Description

nodesCompared

Integer

The number of nodes compared.

relationshipsWritten

Integer

The number of relationships created.

createMillis

Integer

Milliseconds for loading data.

computeMillis

Integer

Milliseconds for running the algorithm.

mutateMillis

Integer

Milliseconds for adding properties to the in-memory graph.

postProcessingMillis

Integer

Milliseconds for computing percentiles.

similarityDistribution

Map

Map containing min, max, mean, stdDev and p1, p5, p10, p25, p75, p90, p95, p99, p100 percentile values of the computed similarity results.

configuration

Map

The configuration used for running the algorithm.

Run Node Similarity in write mode on a graph stored in the catalog. 

CALL gds.nodeSimilarity.write(
  graphName: String,
  configuration: Map
)
YIELD
  createMillis: Integer,
  computeMillis: Integer,
  writeMillis: Integer,
  postProcessingMillis: Integer,
  nodesCompared: Integer,
  relationshipsWritten: Integer,
  similarityDistribution: Map,
  configuration: Map

Table 6.260. Parameters
Name Type Default Optional Description

graphName

String

n/a

no

The name of a graph stored in the catalog.

configuration

Map

{}

yes

Configuration for algorithm-specifics and/or graph filtering.

Table 6.261. General configuration for algorithm execution on a named graph.
Name Type Default Optional Description

writeRelationshipType

String

n/a

no

The relationship type used to persist the computed relationships in the Neo4j database.

writeProperty

String

n/a

no

The relationship property in the Neo4j database to which the similarity score is written.

nodeLabels

String[]

['*']

yes

Filter the named graph using the given node labels.

relationshipTypes

String[]

['*']

yes

Filter the named graph using the given relationship types.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm. Also provides the default value for 'writeConcurrency'.

writeConcurrency

Integer

value of 'concurrency'

yes

The number of concurrent threads used for writing the result to Neo4j.

Table 6.262. Algorithm specific configuration
Name Type Default Optional Description

similarityCutoff

Float

1E-42

yes

Lower limit for the similarity score to be present in the result. . Values must be between 0 and 1.

degreeCutoff

Integer

1

yes

Lower limit on the node degree for a node to be considered in the comparisons. This value can not be lower than 1.

topK

Integer

10

yes

Limit on the number of scores per node. The K largest results are returned. This value cannot be lower than 1.

bottomK

Integer

10

yes

Limit on the number of scores per node. The K smallest results are returned. This value cannot be lower than 1.

topN

Integer

0

yes

Global limit on the number of scores computed. The N largest total results are returned. This value cannot be negative, a value of 0 means no global limit.

bottomN

Integer

0

yes

Global limit on the number of scores computed. The N smallest total results are returned. This value cannot be negative, a value of 0 means no global limit.

Table 6.263. Results
Name Type Description

nodesCompared

Integer

The number of nodes compared.

relationshipsWritten

Integer

The number of relationships created.

createMillis

Integer

Milliseconds for loading data.

computeMillis

Integer

Milliseconds for running the algorithm.

writeMillis

Integer

Milliseconds for writing result data back to Neo4j.

postProcessingMillis

Integer

Milliseconds for computing percentiles.

similarityDistribution

Map

Map containing min, max, mean, stdDev and p1, p5, p10, p25, p75, p90, p95, p99, p100 percentile values of the computed similarity results.

configuration

Map

The configuration used for running the algorithm.

Anonymous graphs

It is also possible to execute the algorithm on a graph that is projected in conjunction with the algorithm execution. In this case, the graph does not have a name, and we call it anonymous. When executing over an anonymous graph the configuration map contains a graph projection configuration as well as an algorithm configuration. All execution modes support execution on anonymous graphs, although we only show syntax and mode-specific configuration for the write mode for brevity.

For more information on syntax variants, see Section 6.1, “Syntax overview”.

Run Node Similarity in write mode on an anonymous graph. 

CALL gds.nodeSimilarity.write(
  configuration: Map
)
YIELD
  createMillis: Integer,
  computeMillis: Integer,
  writeMillis: Integer,
  postProcessingMillis: Integer,
  nodesCompared: Integer,
  relationshipsWritten: Integer,
  similarityDistribution: Map,
  configuration: Map

Table 6.264. General configuration for algorithm execution on an anonymous graph.
Name Type Default Optional Description

nodeProjection

String, String[] or Map

null

yes

The node projection used for anonymous graph creation via a Native projection.

relationshipProjection

String, String[] or Map

null

yes

The relationship projection used for anonymous graph creation a Native projection.

nodeQuery

String

null

yes

The Cypher query used to select the nodes for anonymous graph creation via a Cypher projection.

relationshipQuery

String

null

yes

The Cypher query used to select the relationships for anonymous graph creation via a Cypher projection.

nodeProperties

String, String[] or Map

null

yes

The node properties to project during anonymous graph creation.

relationshipProperties

String, String[] or Map

null

yes

The relationship properties to project during anonymous graph creation.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm. Also provides the default value for 'readConcurrency' and 'writeConcurrency'.

readConcurrency

Integer

value of 'concurrency'

yes

The number of concurrent threads used for creating the graph.

writeConcurrency

Integer

value of 'concurrency'

yes

The number of concurrent threads used for writing the result to Neo4j.

writeRelationshipType

String

n/a

no

The relationship type used to persist the computed relationships in the Neo4j database.

writeProperty

String

n/a

no

The relationship property in the Neo4j database to which the similarity score is written.

Table 6.265. Algorithm specific configuration
Name Type Default Optional Description

similarityCutoff

Float

1E-42

yes

Lower limit for the similarity score to be present in the result. . Values must be between 0 and 1.

degreeCutoff

Integer

1

yes

Lower limit on the node degree for a node to be considered in the comparisons. This value can not be lower than 1.

topK

Integer

10

yes

Limit on the number of scores per node. The K largest results are returned. This value cannot be lower than 1.

bottomK

Integer

10

yes

Limit on the number of scores per node. The K smallest results are returned. This value cannot be lower than 1.

topN

Integer

0

yes

Global limit on the number of scores computed. The N largest total results are returned. This value cannot be negative, a value of 0 means no global limit.

bottomN

Integer

0

yes

Global limit on the number of scores computed. The N smallest total results are returned. This value cannot be negative, a value of 0 means no global limit.

The results are the same as for running write mode with a named graph, see the write mode syntax above.

6.4.1.3. Examples

In this section we will show examples of running the Node Similarity algorithm on a concrete graph. The intention is to illustrate what the results look like and to provide a guide in how to make use of the algorithm in a real setting. We will do this on a small knowledge graph of a handful nodes connected in a particular pattern. The example graph looks like this:

node similarity

The following Cypher statement will create the example graph in the Neo4j database: 

CREATE
  (alice:Person {name: 'Alice'}),
  (bob:Person {name: 'Bob'}),
  (carol:Person {name: 'Carol'}),
  (dave:Person {name: 'Dave'}),
  (eve:Person {name: 'Eve'}),
  (guitar:Instrument {name: 'Guitar'}),
  (synth:Instrument {name: 'Synthesizer'}),
  (bongos:Instrument {name: 'Bongos'}),
  (trumpet:Instrument {name: 'Trumpet'}),

  (alice)-[:LIKES]->(guitar),
  (alice)-[:LIKES]->(synth),
  (alice)-[:LIKES {strength: 0.5}]->(bongos),
  (bob)-[:LIKES]->(guitar),
  (bob)-[:LIKES]->(synth),
  (carol)-[:LIKES]->(bongos),
  (dave)-[:LIKES]->(guitar),
  (dave)-[:LIKES]->(synth),
  (dave)-[:LIKES]->(bongos);

This bipartite graph has two node sets, Person nodes and Instrument nodes. The two node sets are connected via LIKES relationships. Each relationship starts at a Person node and ends at an Instrument node.

In the example, we want to use the Node Similarity algorithm to compare people based on the instruments they like.

The Node Similarity algorithm will only compute similarity for nodes that have a degree of at least 1. In the example graph, the Eve node will not be compared to other Person nodes.

In the examples below we will use named graphs and standard projections as the norm. However, Cypher projection and anonymous graphs could also be used.

The following statement will create the graph and store it in the graph catalog. 

CALL gds.graph.create(
    'myGraph',
    ['Person', 'Instrument'],
    {
        LIKES: {
            type: 'LIKES',
            properties: {
                strength: {
                    property: 'strength',
                    defaultValue: 1.0
                }
            }
        }
    }
);

In the following examples we will demonstrate using the Node Similarity algorithm on this graph.

Memory Estimation

First off, we will estimate the cost of running the algorithm using the estimate procedure. This can be done with any execution mode. We will use the write mode in this example. Estimating the algorithm is useful to understand the memory impact that running the algorithm on your graph will have. When you later actually run the algorithm in one of the execution modes the system will perform an estimation. If the estimation shows that there is a very high probability of the execution going over its memory limitations, the execution is prohibited. To read more about this, see Section 3.1.3, “Automatic estimation and execution blocking”.

For more details on estimate in general, see Section 3.1, “Memory Estimation”.

The following will estimate the memory requirements for running the algorithm: 

CALL gds.nodeSimilarity.write.estimate('myGraph', {
  writeRelationshipType: 'SIMILAR',
  writeProperty: 'score'
})
YIELD nodeCount, relationshipCount, bytesMin, bytesMax, requiredMemory

Table 6.266. Results
nodeCount relationshipCount bytesMin bytesMax requiredMemory

9

9

2592

2808

"[2592 Bytes ... 2808 Bytes]"

Stream

In the stream execution mode, the algorithm returns the similarity score for each relationship. This allows us to inspect the results directly or post-process them in Cypher without any side effects. For example, we can order the results to find the nodes with the highest local clustering coefficient.

For more details on the stream mode in general, see Section 3.3.1, “Stream”.

The following will run the algorithm, and stream results: 

CALL gds.nodeSimilarity.stream('myGraph')
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY similarity DESCENDING, Person1, Person2

Table 6.267. Results
Person1 Person2 similarity

"Alice"

"Dave"

1.0

"Dave"

"Alice"

1.0

"Alice"

"Bob"

0.6666666666666666

"Bob"

"Alice"

0.6666666666666666

"Bob"

"Dave"

0.6666666666666666

"Dave"

"Bob"

0.6666666666666666

"Alice"

"Carol"

0.3333333333333333

"Carol"

"Alice"

0.3333333333333333

"Carol"

"Dave"

0.3333333333333333

"Dave"

"Carol"

0.3333333333333333

10 rows

We use default values for the procedure configuration parameter. TopK is set to 10, topN is set to 0. Because of that the result set contains the top 10 similarity scores for each node.

If we would like to instead compare the Instruments to each other, we would then project the LIKES relationship type using REVERSE orientation. This would return similarities for pairs of Instruments and not compute any similarities between Persons.

Stats

In the stats execution mode, the algorithm returns a single row containing a summary of the algorithm result. The summary result contains the avearage clustering coefficient of the graph, which is the normalised sum over all local clustering coefficients. This execution mode does not have any side effects. It can be useful for evaluating algorithm performance by inspecting the computeMillis return item. In the examples below we will omit returning the timings. The full signature of the procedure can be found in the syntax section.

For more details on the stats mode in general, see Section 3.3.2, “Stats”.

The following will run the algorithm and returns the result in form of statistical and measurement values. 

CALL gds.nodeSimilarity.stats('myGraph')
YIELD nodesCompared, similarityPairs

Table 6.268. Results
nodesCompared similarityPairs

4

10

Mutate

The mutate execution mode extends the stats mode with an important side effect: updating the named graph with a new relationship property containing the similarity score for that relationship. The name of the new property is specified using the mandatory configuration parameter mutateProperty. The result is a single summary row, similar to stats, but with some additional metrics. The mutate mode is especially useful when multiple algorithms are used in conjunction. For example, using the triangle count to compute the local clustering coefficient.

For more details on the mutate mode in general, see Section 3.3.3, “Mutate”.

The following will run the algorithm, and write back results: 

CALL gds.nodeSimilarity.mutate('myGraph', {
    mutateRelationshipType: 'SIMILAR',
    mutateProperty: 'score'
})
YIELD nodesCompared, relationshipsWritten

Table 6.269. Results
nodesCompared relationshipsWritten

4

10

As we can see from the results, the number of created relationships is equal to the number of rows in the streaming example.

Write

The write execution mode extends the stats mode with an important side effect: for each pair of nodes we create a relationship with the Jaccard similarity score as a property to the Neo4j database. The type of the new relationship is specified using the mandatory configuration parameter writeRelationshipType. The name of the new property is specified using the mandatory configuration parameter writeProperty. The result is a single summary row, similar to stats, but with some additional metrics.

For more details on the write mode in general, see Section 3.3.4, “Write”.

The following will run the algorithm, and write back results: 

CALL gds.nodeSimilarity.write('myGraph', {
    writeRelationshipType: 'SIMILAR',
    writeProperty: 'score'
})
YIELD nodesCompared, relationshipsWritten

Table 6.270. Results
nodesCompared relationshipsWritten

4

10

As we can see from the results, the number of created relationships is equal to the number of rows in the streaming example.

Limit results

There are four limits that can be applied to the similarity results. Top limits the result to the highest similarity scores. Bottom limits the result to the lowest similarity scores. Both top and bottom limits can apply to the result as a whole ("N"), or to the result per node ("K").

There must always be a "K" limit, either bottomK or topK, which is a positive number. The default value for topK and bottomK is 10.

Table 6.271. Result limits
  total results results per node

highest score

topN

topK

lowest score

bottomN

bottomK

topK and bottomK

TopK and bottomK are limits on the number of scores computed per node. For topK, the K largest similarity scores per node are returned. For bottomK, the K smallest similarity scores per node are returned. TopK and bottomK cannot be 0, used in conjunction, and the default value is 10. If neither is specified, topK is used.

The following will run the algorithm, and stream the top 1 result per node: 

CALL gds.nodeSimilarity.stream('myGraph', { topK: 1 })
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY Person1

Table 6.272. Results
Person1 Person2 similarity

"Alice"

"Dave"

1.0

"Bob"

"Alice"

0.6666666666666666

"Carol"

"Alice"

0.3333333333333333

"Dave"

"Alice"

1.0

4 rows

The following will run the algorithm, and stream the bottom 1 result per node: 

CALL gds.nodeSimilarity.stream('myGraph', { bottomK: 1 })
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY Person1

Table 6.273. Results
Person1 Person2 similarity

"Alice"

"Carol"

0.3333333333333333

"Bob"

"Alice"

0.6666666666666666

"Carol"

"Alice"

0.3333333333333333

"Dave"

"Carol"

0.3333333333333333

4 rows

topN and bottomN

TopN and bottomN limit the number of similarity scores across all nodes. This is a limit on the total result set, in addition to the topK or bottomK limit on the results per node. For topN, the N largest similarity scores are returned. For bottomN, the N smallest similarity scores are returned. A value of 0 means no global limit is imposed and all results from topK or bottomK are returned.

The following will run the algorithm, and stream the 3 highest out of the top 1 results per node: 

CALL gds.nodeSimilarity.stream('myGraph', { topK: 1, topN: 3 })
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY similarity DESC, Person1, Person2

Table 6.274. Results
Person1 Person2 similarity

"Alice"

"Dave"

1.0

"Dave"

"Alice"

1.0

"Bob"

"Alice"

0.6666666666666666

3 rows

Degree cutoff and similarity cutoff

Degree cutoff is a lower limit on the node degree for a node to be considered in the comparisons. This value can not be lower than 1.

The following will ignore nodes with less than 3 LIKES relationships: 

CALL gds.nodeSimilarity.stream('myGraph', { degreeCutoff: 3 })
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY Person1

Table 6.275. Results
Person1 Person2 similarity

"Alice"

"Dave"

1.0

"Dave"

"Alice"

1.0

2 rows

Similarity cutoff is a lower limit for the similarity score to be present in the result. The default value is very small (1E-42) to exclude results with a similarity score of 0.

Setting similarity cutoff to 0 may yield a very large result set, increased runtime and memory consumption.

The following will ignore node pairs with a similarity score less than 0.5: 

CALL gds.nodeSimilarity.stream('myGraph', { similarityCutoff: 0.5 })
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY Person1

Table 6.276. Results
Person1 Person2 similarity

"Alice"

"Dave"

1.0

"Alice"

"Bob"

0.6666666666666666

"Bob"

"Dave"

0.6666666666666666

"Bob"

"Alice"

0.6666666666666666

"Dave"

"Alice"

1.0

"Dave"

"Bob"

0.6666666666666666

6 rows

Weighted Jaccard Similarity

Relationship properties can be used to modify the similarity induced by certain relationships. For example a relationship value of 2 is equal to counting that relationship twice while computing the jaccard similarity.

Weighted jaccard similarity is only defined for values greater or equal to 0.

The following query will respect relationship properties in the similarity computation: 

CALL gds.nodeSimilarity.stream('myGraph', { relationshipWeightProperty: 'strength', similarityCutoff: 0.5 })
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY Person1

Table 6.277. Results
Person1 Person2 similarity

"Alice"

"Dave"

0.8333333333333334

"Alice"

"Bob"

0.8

"Bob"

"Alice"

0.8

"Bob"

"Dave"

0.6666666666666666

"Dave"

"Alice"

0.8333333333333334

"Dave"

"Bob"

0.6666666666666666

6 rows

It can be seen that the similarity between Alice and Dave decreased compared to the non-weighted version of this algorithm. This is the case as the strength of the relationship between Alice and Bongos is reduced and both persons now only share 2.5 out of 3 possible instruments. Analogous the similarity between Alice and Bob increased as the missing liked instrument has a lower impact on the similarity score.