How to stream nod labels from the graph projection?

Hello,
I am once more lost with something very trivial: How can I stream node labels from the graph projection?
I see GDS procedures to mutate node label, but nothing to read what is written in the graph projection. I can write in the graph projection but node read. It feels I am missing something very obvious...
The only dirty work around I can think of so far is to both mutate the graph and write these temporary node labels back into the main database and use the gds.util.asNodes procedure to read the nodes back from the main database which I really don't want to do. I shouldn't have to alter my main database to read temporary information.
What I am missing? Any help will be appreciated.

Neo4j Desktop: 1.5.7
Neo4j DBMS: 5.4.0
APOC version: 5.4.1
GDS version: 2.3.1
Python Neo4j client: 5.4.0
Python GDS client: 1.6

Hi Minrt,

Another great question! You are correct that mutate writes the results of the algorithm to the projected graph and returns a single record of summary statistics.

What you are looking for is the stream functionality in gds. Stream will return the results of the algorithm as a stream of records without altering the database. If you have a large output and only want some values returned, you can alwaysORDERBY and LIMIT to see a portion of the results.

@alison.cossette thank you for replying and trying to help. This is very much appreciated. But please note that the question is about node labels, not node properties. I know I can use the stream functionality in gds to read node values (like values computed by algorithms). But how do I read a label I wrote in the graph memory?
When I read this documentation: Node operations - Neo4j Graph Data Science I see how to stream a node property, write or mutate a node lablel but nothing to stream a node label.

Hello again @mlnrt,
catching up on your post.

For streaming node labels, I would suggest to stream the nodes for each nodeLabel explicitly.
This way, you save streaming the label strings for each node.
gds.graph.nodeProperties.stream has a nodeLabels parameter which can set to a single label in your case.
You can get the labels of the projected graph through CALL gds.graph.list('my_graph') YIELD schemaWithOrientation WITH labels AS keys(schemaWithOrientation['nodes'])

From the general usage pov, why do you want to stream the node labels? Are you using gds.alpha.graph.nodeLabel.mutate? Otherwise the nodeLabels should be the same as in your input data.

Hello @florentin_dorre
Thank you for replying. Yes I do use the gds.alpha.graph.nodeLabel.mutate procedure and I just find it natural to be able read what was written in the graph.
What I am trying to achieve is that in the database I have, amongst other things, people nodes. When I project these nodes into a graph projection to perform some analysis, I want to put them into different categories and I am using labels for that. And I don't want these temporary labels to be written in the database so I would like to just mutate the graph. Then later on, in my analysis the objective is to stratify per category (node labels) and for that I want to pull all the labels of each nodes. So using the nodeLabels parameter of the gds.graph.nodeProperties.stream procedure doesn't help me achieve that.

Okay, that totally makes sense.

My work around would look like the following:

CALL gds.graph.project('g2', ['A', 'B'], '*', {nodeProperties: ['score']})
CALL gds.alpha.graph.nodeLabel.mutate('g2', 'C', { nodeFilter: 'n.score > 1' })
YIELD graphName, nodeLabel, nodeLabelsWritten, nodeCount
WITH ['A', 'B', 'C'] AS labels
UNWIND labels as label
CALL gds.graph.nodeProperty.stream('g2', 'score', label)
YIELD nodeId, propertyValue
WITH nodeId, propertyValue, label
RETURN *

This result you should be able to use?

I see. I did not thought about that. That would work I think. Thank you for taking the time to help and provide a solution. This is really much appreciated.

1 Like