Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not Connect to the Neo4j database using langchain.graphs import Neo4jGraph #26897

Open
5 tasks done
giuseppefutia opened this issue Sep 26, 2024 · 6 comments
Open
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate

Comments

@giuseppefutia
Copy link

giuseppefutia commented Sep 26, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

I am running the following Python code:

from langchain.graphs import Neo4jGraph
graph_store = Neo4jGraph(
  url=neo4j_url,
  username=neo4j_username,
  password=neo4j_password,
  database=neo4j_database
)

However, it generates the following error:

ClientError: {code: Neo.ClientError.Database.DatabaseNotFound} {message: Database neo4j not found}

I specified a different database name in the neo4j_database variable, but it seems to still attempt to connect to a database named "neo4j".

To test the access to the database specified in the neo4j_database variable, I used the following script, and no issues or errors were raised:

from neo4j import GraphDatabase

def test_neo4j_connection(uri, user, password, database):
    driver = GraphDatabase.driver(uri, auth=(user, password))

    try:
        with driver.session(database=database) as session:
            result = session.run("RETURN 'Connection successful!' AS message")
            for record in result:
                print(record["message"])
    except Exception as e:
        print(f"Failed to connect to Neo4j: {e}")
    finally:
        driver.close()

test_neo4j_connection(neo4j_url, neo4j_username, neo4j_password, neo4j_database)

I am running the code in a colab notebook, and everything worked well until today when I re-installed everything from scratch.

Error Message and Stack Trace (if applicable)

No response

Description

It seems that langchain still attempts to connect to a database named "neo4j", also in the cases in which I specified a different database name

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 27 21:05:47 UTC 2024
Python Version: 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]

Package Information

langchain_core: 0.3.6
langchain: 0.3.1
langchain_community: 0.3.1
langsmith: 0.1.128
langchain_ollama: 0.2.0
langchain_text_splitters: 0.3.0

Optional packages not installed

langgraph
langserve

Other Dependencies

aiohttp: 3.10.5
async-timeout: 4.0.3
dataclasses-json: 0.6.7
httpx: 0.27.2
jsonpatch: 1.33
numpy: 1.26.4
ollama: 0.3.3
orjson: 3.10.7
packaging: 24.1
pydantic: 2.9.2
pydantic-settings: 2.5.2
PyYAML: 6.0.2
requests: 2.32.3
SQLAlchemy: 2.0.35
tenacity: 8.5.0
typing-extensions: 4.12.2

@langcarl langcarl bot added the investigate label Sep 26, 2024
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Sep 26, 2024
@tomasonjo
Copy link
Contributor

Can you show the code you're using?

@giuseppefutia
Copy link
Author

To replicate the error, you can follow these steps:

pip install langchain
pip install langchain_community
pip install neo4j
url = "bolt://localhost:7687"
username ="neo4j"
password = "password"
database = "other_db"

graph = Neo4jGraph(
  url=url,
  username=username,
  password=password,
  database=database
)

graph.query("MATCH (n) RETURN n LIMIT 10")

You will notice that the query is always run against the neo4 database and not the other_db specified in the variable. Let me know if you need further details.

@giuseppefutia
Copy link
Author

This should be the same issue: #27185

@tomasonjo
Copy link
Contributor

Added a fix: #27190

@SimaIm
Copy link

SimaIm commented Oct 15, 2024

I'm experiencing the same problem in my code where queries are always run against the neo4j database, even when I specify a different database name. This issue started recently, it was working correctly about two weeks ago.
@giuseppefutia Could you please share how you resolved it? Thanks

@tomasonjo
Copy link
Contributor

tomasonjo commented Oct 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate
Projects
None yet
Development

No branches or pull requests

3 participants