Open liamdonnellymv opened 1 month ago
Hey there, @liamdonnellymv! I'm Dosu, here to assist you with any bugs, questions, or contributions. Let's work together to tackle this issue!
To resolve the Cypher syntax error when creating a Neo4jGraphStore
using the latest Neo4j Docker container, you need to update the constraint creation query to comply with the latest Neo4j syntax. The error message indicates that the ON
and ASSERT
keywords should be replaced with FOR
and REQUIRE
.
Here's how you can modify the Neo4jGraphStore
initialization to use the correct syntax:
Update the Constraint Creation Query:
Modify the query in the Neo4jGraphStore
class to use the latest syntax:
"""
CREATE CONSTRAINT IF NOT EXISTS FOR (n:%s) REQUIRE n.id IS UNIQUE;
"""
% (self.node_label)
Ensure Proper Initialization:
Make sure the Neo4jGraphStore
is properly initialized and connected to the Neo4j database. Here is an example:
from llama_index.graph_stores.neo4j import Neo4jGraphStore
# Initialize the Neo4jGraphStore
graph_store = Neo4jGraphStore(
username="neo4j",
password="your_password",
url="bolt://localhost:7687",
database="neo4j"
)
# Verify connection and refresh schema
graph_store.refresh_schema()
Launch Neo4j Docker Container with Required Configurations: Ensure that the Neo4j Docker container is launched with the necessary configurations, including the APOC plugin:
services:
neofourj:
image: neo4j
ports:
- 8102:7474
- 8103:7687
volumes:
- ./neo4j_data:/data
environment:
- NEO4J_PLUGINS=["apoc"]
- NEO4J_dbms_security_procedures_unrestricted=apoc.*
Then, spin up the container with:
docker compose up
By following these steps, you should be able to resolve the Cypher syntax error and successfully create a Neo4jGraphStore
using the latest Neo4j Docker container [1][2].
To continue talking to Dosu, mention @dosu.
Will try changing the llamaindex code but this is a work around and still requires a PR
Turns out the Cipher syntax wasn't the root cause. It was symptom of the try except assuming syntax was the issue and then running Copher for neo4j < 5.
Suggestion: Line 83 in .../python3.10/site-packages/llama_index/graph_stores/neo4j/base.py
should have some logic to check the exception from neo4j. In my case it was some pre existing constraints in the database I was pointing at.
Bug Description
When I try to create a graph store with:
from llama_index.graph_stores.neo4j import Neo4jGraphStore
graph_store = Neo4jGraphStore( username=username, password=password, url=url, database=database, )
I see an error around "Invalid constraint syntax, ON and ASSERT should not be used. Replace ON with FOR and ASSERT with REQUIRE."
Version
0.10.55
Steps to Reproduce
Pull neo4j from docker:
docker pull neo4j
Create neo4j docker container compose yaml file with the following:
services: neofourj: image: neo4j ports:
- NEO4J_AUTH=neo4j/password
Spin up the container with
docker compose up
.Run the following in python script:
from llama_index.graph_stores.neo4j import Neo4jGraphStore
graph_store = Neo4jGraphStore( username=username, password=password, url=url, database=database, )
Relevant Logs/Tracbacks