3.5.14 nodeSimilarity create a single relationship between two nodes

Hi,

According to documentation, it seems that nodeSimilarity will create 2 relationships with different direction between the compared two nodes.

Somehow I got 1 relationship between 2 compared nodes:

MATCH (n:Sub_Field)-[s:SIMILAR]-(m:Sub_Field)
WHERE n.id = 2 and m.id = 14
RETURN n,m

image

My query as followed:

CALL algo.nodeSimilarity('Sub_Field | Project', 'PROJECT_SUB_FIELD_BELONG', {
  direction: 'INCOMING',
  write: true
})
YIELD nodesCompared, relationships, write, writeProperty, writeRelationshipType;

Is this normal? What cause that if it is normal?

By the way, how do I use cypher projection to express a complex path like
'MATCH (male:Male) RETURN id(male) as id',
(s:School)--(n:Male)-[:LIKE]-(:Books)-[:LIKE]-(m:Male), (s)--(m)
RETURN id(n) as source, id(m) as target'

I want to create the similarity of male students who are in the same school according to books they like. Assume there are many schools and Game node (like Books mentioned) type between males.

Thanks for helping!

I think you'd also need to return the relationship as well to get multiple relationships back. I'm not sure it does that by default so :slight_smile:

MATCH (n:Sub_Field)-[s:SIMILAR]-(m:Sub_Field)
WHERE n.id = 2 and m.id = 14
RETURN n,s,m

Give that a shot

Hi Porter,

Thanks for helping.
I tried what you suggested

MATCH (n:Sub_Field)-[s:SIMILAR]-(m:Sub_Field)
WHERE n.id = 2 and m.id = 14
RETURN n,m,s

It returns the same:
image

Not all of them happened like this, most of them will return 2 relationships:
image

Thanks

Ah sorry didn't quite grok what you were asking. It may be possible that you got a typo in there somewhere. Did you try to clear the graph and start again?

Hi Porter,
Sorry about the confusion and forgive my poor English.
I am asking if I use nodeSimilarity to compute similarity, is it possible to happen that only one similar relationship was created between the compared 2 nodes?

Because the official example shows that there are two relationships would be created after calling nodeSimilarity.

After calling nodeSimilarity:
Alice -> Dave
Dave-> Alice
2 relationships(opposite directions) are created between Alice and Dave

Alice -> Bob
Bob-> Alice
2 relationships(opposite directions) are created between Alice and Bob

And also the same for Carol and Alice, Dave and Carol, Bob and Dave.

But in my case, some compared nodes only have created 1 relationship between them after calling nodeSimilarity.
image
And some of them have created 2 relationships after calling nodeSimilarity
image

Hope you get my point this time :smiley:
Thanks

If you're trying to recreate the example given in the Docs it looks like you have a different relationship direction. Incoming vs. outgoing in the example. That may affect the results you're getting.

Yes indeed, the docs' example is using outgoing, in my case, I use incoming otherwise the nodeSimilarity will not work.

Are you doing anything differently besides that? Have a cut off? Does that node match others in your graph that have multiple similarity relationships or scores? Seems like something of that nature is happening.

I did not have a cut off or anything else.
Just the following query I used:

CALL algo.nodeSimilarity('Sub_Field | Project', 'PROJECT_SUB_FIELD_BELONG', {
  direction: 'INCOMING',
  write: true
})
YIELD nodesCompared, relationships, write, writeProperty, writeRelationshipType;

The node with id 2 and the node with id 14 both have other matchs with multiple similarity relationships
image
image

Thanks