Connecting Neo4j Desktop -GDS with Python driver

Hi, I have the Neo4j Desktop 5.11.0
I have installed the Graph Data Science Library plugin - I'm a bit confused with the Python connection I tried a couple of ways but I could not connect.

import neo4j
from graphdatascience import GraphDataScience
# Create a connection to the Neo4j database
gds = GraphDataScience("bolt://localhost:7687", auth=("neo4j", "12345678"))
d=gds.run_cypher("MATCH(n)-[r]-(m) RETURN n,r,m")

print(d)

And the Error-

---------------------------------------------------------------------------
CypherSyntaxError                         Traceback (most recent call last)
File ~/anaconda3/lib/python3.11/site-packages/graphdatascience/graph_data_science.py:93, in GraphDataScience.__init__(self, endpoint, auth, aura_ds, database, arrow, arrow_disable_server_verification, arrow_tls_root_certs, aura_db_connection_info)
     92 try:
---> 93     server_version_string = self._query_runner.run_query("RETURN gds.version()", custom_error=False).squeeze()
     94 except Exception as e:

File ~/anaconda3/lib/python3.11/site-packages/graphdatascience/query_runner/neo4j_query_runner.py:71, in Neo4jQueryRunner.run_query(self, query, params, database, custom_error)
     70     else:
---> 71         raise e
     73 # Though pandas support may be experimental in the `neo4j` package, it should always
     74 # be supported in the `graphdatascience` package.

File ~/anaconda3/lib/python3.11/site-packages/graphdatascience/query_runner/neo4j_query_runner.py:66, in Neo4jQueryRunner.run_query(self, query, params, database, custom_error)
     65 try:
---> 66     result = session.run(query, params)
     67 except Exception as e:

File ~/anaconda3/lib/python3.11/site-packages/neo4j/_sync/work/session.py:311, in Session.run(self, query, parameters, **kwargs)
    310 parameters = dict(parameters or {}, **kwargs)
--> 311 self._auto_result._run(
    312     query, parameters, self._config.database,
    313     self._config.impersonated_user, self._config.default_access_mode,
    314     bookmarks, self._config.notifications_min_severity,
    315     self._config.notifications_disabled_categories,
    316 )
    318 return self._auto_result

File ~/anaconda3/lib/python3.11/site-packages/neo4j/_sync/work/result.py:166, in Result._run(self, query, parameters, db, imp_user, access_mode, bookmarks, notifications_min_severity, notifications_disabled_categories)
    165 self._connection.send_all()
--> 166 self._attach()

File ~/anaconda3/lib/python3.11/site-packages/neo4j/_sync/work/result.py:274, in Result._attach(self)
    273 while self._attached is False:
--> 274     self._connection.fetch_message()

File ~/anaconda3/lib/python3.11/site-packages/neo4j/_sync/io/_common.py:180, in ConnectionErrorHandler.__getattr__.<locals>.outer.<locals>.inner(*args, **kwargs)
    179 try:
--> 180     func(*args, **kwargs)
    181 except (Neo4jError, ServiceUnavailable, SessionExpired) as exc:

File ~/anaconda3/lib/python3.11/site-packages/neo4j/_sync/io/_bolt.py:808, in Bolt.fetch_message(self)
    805 tag, fields = self.inbox.pop(
    806     hydration_hooks=self.responses[0].hydration_hooks
    807 )
--> 808 res = self._process_message(tag, fields)
    809 self.idle_since = perf_counter()

File ~/anaconda3/lib/python3.11/site-packages/neo4j/_sync/io/_bolt5.py:352, in Bolt5x0._process_message(self, tag, fields)
    351 try:
--> 352     response.on_failure(summary_metadata or {})
    353 except (ServiceUnavailable, DatabaseUnavailable):

File ~/anaconda3/lib/python3.11/site-packages/neo4j/_sync/io/_common.py:247, in Response.on_failure(self, metadata)
    246 Util.callback(handler)
--> 247 raise Neo4jError.hydrate(**metadata)

CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Unknown function 'gds.version' (line 1, column 8 (offset: 7))
"RETURN gds.version()"
        ^}

During handling of the above exception, another exception occurred:

UnableToConnectError                      Traceback (most recent call last)
Cell In[60], line 5
      2 from graphdatascience import GraphDataScience
      4 # Create a connection to the Neo4j database
----> 5 gds = GraphDataScience("bolt://localhost:7687", auth=("neo4j", "12345678"))
      6 d=gds.run_cypher("MATCH(n)-[r]-(m) RETURN n,r,m")
      8 print(d)

File ~/anaconda3/lib/python3.11/site-packages/graphdatascience/graph_data_science.py:95, in GraphDataScience.__init__(self, endpoint, auth, aura_ds, database, arrow, arrow_disable_server_verification, arrow_tls_root_certs, aura_db_connection_info)
     93     server_version_string = self._query_runner.run_query("RETURN gds.version()", custom_error=False).squeeze()
     94 except Exception as e:
---> 95     raise UnableToConnectError(e)
     96 finally:
     97     # Some Python versions appear to not call __del__ of self._query_runner when an exception
     98     # is raised, so we have to close the driver manually.
     99     if isinstance(endpoint, str):

UnableToConnectError: {code: Neo.ClientError.Statement.SyntaxError} {message: Unknown function 'gds.version' (line 1, column 8 (offset: 7))
"RETURN gds.version()"
        ^}

Hello @roopesh.keetavarampa ,
this error indicates, that you did not install GDS correctly on the Neo4j server.

Could you check the server logs?
And which GDS version do you have installed?
Also how did you install GDS?

Thanks @florentin_dorre for letting me know about the GDS incorrectly installed
I followed the instruction of this - https://neo4j.com/docs/graph-data-science/current/installation/neo4j-desktop/

and I added these 2 lines in the Settings

dbms.security.procedures.unrestricted=gds.*
dbms.security.procedures.allowlist=gds.*

GDS Version is 2.4.4
Neo4j Desktop Version 5.11.0

Logs Info:

2023-08-17 12:52:06.196+0000 INFO  Starting...
2023-08-17 12:52:08.271+0000 INFO  ======== Neo4j 5.11.0 ========
2023-08-17 12:52:08.283+0000 INFO  This instance is ServerId{7ced6a16} (7ced6a16-9464-41f1-998b-afeacb4ef464)
2023-08-17 12:52:08.421+0000 INFO  GDS compatibility: for Neo4j Settings 4.4 -- not available, for Neo4j Settings 5.1 -- not available, for Neo4j Settings 5.2.0 -- not available, for Neo4j Settings 5.3 -- not available, for Neo4j Settings 5.4 -- not available, for Neo4j Settings 5.5 -- not available, for Neo4j Settings 5.6 -- not available, for Neo4j Settings 5.7 -- not available, for Neo4j Settings 5.8 -- not available, for Neo4j Settings 5.9 -- not available, for Neo4j Settings 5.10 -- not available, for Neo4j Settings 5.11 -- available, selected: Neo4j Settings 5.11
2023-08-17 12:52:08.421+0000 INFO  GDS compatibility: for Neo4j 4.4 -- not available, for Neo4j 5.1 -- not available, for Neo4j 5.2.0 -- not available, for Neo4j 5.3 -- not available, for Neo4j 5.4 -- not available, for Neo4j 5.5 -- not available, for Neo4j 5.6 -- not available, for Neo4j 5.7 -- not available, for Neo4j 5.8 -- not available, for Neo4j 5.9 -- not available, for Neo4j 5.10 -- not available, for Neo4j 5.11 -- available, selected: Neo4j 5.11
2023-08-17 12:52:16.534+0000 INFO  Sending metrics to CSV file at /Users/roopeshbharatwajkr/Library/Application Support/Neo4j Desktop/Application/relate-data/dbmss/dbms-5d76305e-8809-4bce-b812-c2c745044322/metrics
2023-08-17 12:52:16.548+0000 INFO  Bolt enabled on localhost:7687.
2023-08-17 12:52:16.549+0000 INFO  Bolt (Routing) enabled on localhost:7688.

So , Looks like for 5.11.0- GDS is available

1 Like

Cool -It's working Now, I'm planning to use Machine Learning for Node Prediction / Classification. Is there any examples or any git repo that will be helpful?

I would recommend to look at Machine learning pipelines: Node classification - Neo4j Graph Data Science Client for a good jupyter notebook.

If you dont want to use the python client, I would recommend to follow the examples from Node classification pipelines - Neo4j Graph Data Science

Thank you very much - But how can we load our own custom graph which we have developed from the DB? any idea for that? Are there any examples or any git repo specific?

Because in the example I can see all were using the Cora data set and I could not find the gcd calling of the database -> which has the already constructed graph (nodes and relationships).

Please let me know. how to call the specific db after connecting with the Python Client.

This tutorial projects from a Neo4j db.
Product recommendations with kNN based on FastRP embeddings - Neo4j Graph Data Science Client.
Futher, the related native projection site: (Projecting graphs using native projections - Neo4j Graph Data Science). Please create a new post if you have further issues.

For the specific db, you can set the database to query against (see Projecting graphs using native projections - Neo4j Graph Data Science).

Sure, Thank you very much.