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

Update deprecated Neo4jGraph import to support langchain-neo4j #2084

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TheCommandCat
Copy link

@TheCommandCat TheCommandCat commented Dec 11, 2024

Description

This PR addresses the following deprecation warning encountered during execution of the Graph Memory module in mem0:

LangChainDeprecationWarning: The class Neo4jGraph was deprecated in LangChain 0.3.8 and will be removed in 1.0. An updated version of the class exists in the langchain-neo4j package and should be used instead. To use it run pip install -U langchain-neo4j and import as from langchain_neo4j import Neo4jGraph.

Previously, using graph_memory.py triggered this warning during initialization:

\Lib\site-packages\mem0\memory\graph_memory.py:42: LangChainDeprecationWarning: The class `Neo4jGraph` was deprecated in LangChain 0.3.8 and will be removed in 1.0.
  self.graph = Neo4jGraph(

Fix Overview

The changes in \mem0\memory\graph_memory.py update the import to the new langchain-neo4j package while maintaining backward compatibility with langchain-community.

Old Import:

try:
    from langchain_community.graphs import Neo4jGraph
except ImportError:
    raise ImportError("langchain_community is not installed. Please install it using pip install langchain-community")

New Import:

try:
    from langchain_neo4j import Neo4jGraph
except ImportError:
    try:
        from langchain_community.graphs.neo4j_graph import Neo4jGraph
    except ImportError:
        raise ImportError(
            "Neither 'langchain-neo4j' nor 'langchain-community' is installed. "
            "Please install one using 'pip install langchain-neo4j' or 'pip install langchain-community'."
        )

This ensures compatibility with both the new langchain-neo4j package and the older langchain-community package, eliminating the deprecation warning.

BTW - building poetry also upgraded poetry.lock any available packages by itself, I'm not very familiar yet with poetry so will free to remove that if not necessary :)

Type of change

Please delete options that are not relevant.

  • Refactor (does not change functionality, e.g. code style improvements, linting)

How Has This Been Tested?

I wrote a simple script that just init mem0 calss with a local ollama llm, chromadb and neo4j, before the fix the warning popup was displayed and now it dosent

Please delete options that are not relevant.

  • Test Script (please provide)
from mem0 import Memory

config = {
        "embedder": {
            "provider": "ollama",
            "config": {
                "model": "mxbai-embed-large"
            }
        },
        "llm": {
        "provider": "ollama",
        "config": {
            "model": "llama3.2",
            }
        },
        "vector_store": {
            "provider": "chroma",
            "config": {
                "collection_name": "VectorStore",
                "path": "db",
            }
        },
        "graph_store": {
            "provider": "neo4j",
            "config": {
                "url": "bolt://localhost:7687",
                "username": "neo4j",
                "password": "yourpassword"
            }
        },
        "version": "v1.1"
}

m = Memory.from_config(config)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas (self explanatory)
  • I have made corresponding changes to the documentation (not needed as much as I know)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (not needed)
  • New and existing unit tests pass locally with my changes (locally i got errors on testing but no new ones with this changes)
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Made sure Checks passed

@CLAassistant
Copy link

CLAassistant commented Dec 11, 2024

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants