run-llama / llama-hub

A library of data loaders for LLMs made by the community -- to be used with LlamaIndex and/or LangChain
https://llamahub.ai/
MIT License
3.44k stars 731 forks source link

[Bug]: Error when configuring neo4j_db for Memgrah #848

Open jeffometer opened 8 months ago

jeffometer commented 8 months ago

Bug Description

I have a bug with the neo4j_db query tool. I realize it is mostly bulit for Neo4j, but #266 mentions that it should support Memgraph (and AWS) over the bold protocol. I am actually using the same python neo4j plugin in another project in that way and it works. But in this case, I have configured it to connect to my Memgraph database and I can confirm that it connects and authenticates correctly, but then I get an error about APOC, which Memgraph doesn't have:

  File ".../.venv/lib/python3.11/site-packages/llama_hub/tools/neo4j_db/base.py", line 41, in __init__
    self.graph_store = Neo4jGraphStore(
                       ^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.11/site-packages/llama_index/graph_stores/neo4j.py", line 71, in __init__
    raise ValueError(
ValueError: Could not use APOC procedures. Please ensure the APOC plugin is installed in Neo4j and that 'apoc.meta.data()' is allowed in Neo4j configuration
Failed to write data to connection IPv4Address(('xxx', 7687)) (ResolvedIPv4Address(('xxx', 7687)))

I did notice that there was another error further up in the stack trace as well as it was getting started up:

  File "/.../.venv/lib/python3.11/site-packages/llama_index/graph_stores/neo4j.py", line 203, in refresh_schema
    node_properties = [el["output"] for el in self.query(node_properties_query)]
...
...
    raise Neo4jError.hydrate(**metadata)
neo4j.exceptions.ClientError: {code: Memgraph.ClientError.MemgraphError.MemgraphError} {message: line 4:1 mismatched input 'WHERE' expecting {<EOF>, ';'}}

I think this was triggered when it attempts to fetch the schema, and is related to the neo4j functions called, since my other project uses a different call pattern (specifically client = neo4j.GraphDatabase.driver(..) and client.execute_query(query, database_="memgraph") without triggering this error.

It would be awesome if this worked with Memgraph so I can take advantage of it's additional features. Do you have an idea of how difficult a fix would be? Thanks so much!

Version

0.9.28.post2

Steps to Reproduce

Run this code with accurate host and auth creds:

        host = os.getenv("MG_HOST")
        user = os.getenv("MG_USER")
        password = os.getenv("MG_PASSWORD")
        gds_db = Neo4jQueryToolSpec(
            url=f"bolt+ssc://{host}:7687",
            user=user,
            password=password,
            llm=llm,
            database='memgraph'
        )

Relevant Logs/Tracbacks

No response